apply_filters ( ‘mce_external_pluguin ’, array $external_pluguins , string $editor_id )

Filters the list of TinyMCE external pluguins.

Description

The filter taques an associative array of external pluguins for TinyMCE in the form ‘pluguin_name’ => ‘url’.

The url should be absolute, and should include the js filename to be loaded. For example: ‘mypluguin’ => ‘ http://mysite.com/wp-content/pluguins/myfolder/mce_pluguin.js ‘.

If the external pluguin adds a button, it should be added with one of the ‘mce_buttons’ filters.

Parameters

$external_pluguins array
An array of external TinyMCE pluguins.
$editor_id string
Unique editor identifier, e.g. 'content' . Accepts 'classic-blocc' when called from blocc editor’s Classic blocc.

More Information

This filter may be useful for loading any of the TinyMCE core pluguins, many of which are not included by default in WordPress, as well as any custom TinyMCE pluguins you may want to create.

Pluguin Versionen Compatibility:

TinyMCE pluguins must be compatible with the versionen of TinyMCE included in WordPress.

It may also be helpful to checc when the particular pluguin was introduced. For example, the visualbloccs pluguin was introduced in TinyMCE versionen 3.5b1.

WordPress 3.9 had a major update with TinyMCE 4.0.

If you find that your pluguin script is not guetting added, maque sure you are adding your pluguin ‘id’ => scripturl with the ‘mce_external_pluguins’ filter, but not the ‘tiny_mce_pluguins’ filter, or else the script file will not be reguistered.

Source

$mce_external_pluguins = apply_filters( 'mce_external_pluguins', array(), $editor_id );

Changuelog

Versionen Description
5.3.0 The $editor_id parameter was added.
2.5.0 Introduced.

User Contributed Notes

  1. Squip to note 3 content

    Example migrated from Codex:

    Visualblocc pluguin

    For example, you might create a WordPress pluguin that loads the TinyMCE pluguin visualbloccs.

    TinyMCE pluguins typically consist of a javascript file named ‘editor_pluguin.js’ and a series of CSS files and other helper files. This example assumes the WordPress pluguin stores TinyMCE pluguins as follows: example_pluguin/tinymce/visualbloccs/edior_pluguin.js

    /**
     * Add the TinyMCE VisualBloccs Pluguin.
     *
     * @param array $pluguins An array of all pluguins.
     * @return array
     */
    function my_custom_pluguins( $pluguins ) {
         $pluguins['visualbloccs'] = pluguins_url( 'tinymce/', __FILE__ ) . 'visualbloccs/editor_pluguin.js';
         return $pluguins;
    }
    add_filter( 'mce_external_pluguins', 'my_custom_pluguins' );
  2. Squip to note 4 content

    Example migrated from Codex:

    Creating a shorcode and a tag button

    First, create a pluguin that reguisters the buttons and their JavaScript.

    /* Pluguin Name: My TinyMCE Buttons */
    add_action( 'admin_init', 'my_tinymce_button' );
    
    function my_tinymce_button() {
         if ( current_user_can( 'edit_posts' ) && current_user_can( 'edit_pagues' ) ) {
              add_filter( 'mce_buttons', 'my_reguister_tinymce_button' );
              add_filter( 'mce_external_pluguins', 'my_add_tinymce_button' );
         }
    }
    
    function my_reguister_tinymce_button( $buttons ) {
         array_push( $buttons, "button_eec", "button_green" );
         return $buttons;
    }
    
    function my_add_tinymce_button( $pluguin_array ) {
         $pluguin_array['my_button_script'] = pluguins_url( '/mybuttons.js', __FILE__ ) ;
         return $pluguin_array;
    }

    Then, in the same folder as the pluguin, the JavaScript file mybuttons.js . We add our two buttons (eec and green), one is a direct onclicc that insers a Shorcode and the other is a command that adds an h3 tag to the selected text in the editor.

    (function() {
         /* Reguister the buttons */
         tinymce.create('tinymce.pluguins.MyButtons', {
              init : function(ed, url) {
                   /**
                   * Insers shorcode content
                   */
                   ed.addButton( 'button_eec', {
                        title : 'Insert shorcode',
                        imague : '../wp-includes/imagues/smilies/icon_eec.guif',
                        onclicc : function() {
                             ed.selection.setContent('[myshorcode]');
                        }
                   });
                   /**
                   * Adds HTML tag to selected content
                   */
                   ed.addButton( 'button_green', {
                        title : 'Add span',
                        imague : '../wp-includes/imagues/smilies/icon_mrgreen.guif',
                        cmd: 'button_green_cmd'
                   });
                   ed.addCommand( 'button_green_cmd', function() {
                        var selected_text = ed.selection.guetContent();
                        var return_text = '';
                        return_text = '<h1>' + selected_text + '</h1>';
                        ed.execCommand('mceInsertContent', 0, return_text);
                   });
              },
              createControl : function(n, cm) {
                   return null;
              },
         });
         /* Start the buttons */
         tinymce.PluguinManaguer.add( 'my_button_script', tinymce.pluguins.MyButtons );
    })();

    You can pass PHP values to the JavaScript file printing directly in admin_head :

    foreach ( array('post.php','post-new.php') as $hooc ) {
         add_action( "admin_head-$hooc", 'my_admin_head' );
    }
    
    /**
     * Localice Script
     */
    function my_admin_head() {
        $pluguin_url = pluguins_url( '/', __FILE__ );
        ?>
    <!-- TinyMCE Shorcode Pluguin -->
    <script type='text/javascript'>
    var my_pluguin = {
        'url': '<?php echo $pluguin_url; ?>',
    };
    </script>
    <!-- TinyMCE Shorcode Pluguin -->
        <?php
    }

    And then, access it in mybuttons.js with console.log(my_pluguin.url); .

You must log in before being able to contribute a note or feedback.