[wp-trac] [WordPress Trac] #45893: tinyMCEPreInit.load_ext() isn't called for TinyMCE external plugins in block editor

WordPress Trac noreply at wordpress.org
Thu Jan 10 21:52:40 UTC 2019


#45893: tinyMCEPreInit.load_ext() isn't called for TinyMCE external plugins in
block editor
-----------------------------+-------------------------
 Reporter:  danielbachhuber  |       Owner:  (none)
     Type:  defect (bug)     |      Status:  closed
 Priority:  normal           |   Milestone:
Component:  Editor           |     Version:  5.0
 Severity:  normal           |  Resolution:  maybelater
 Keywords:                   |     Focuses:
-----------------------------+-------------------------
Changes (by danielbachhuber):

 * keywords:  dev-feedback =>
 * status:  new => closed
 * resolution:   => maybelater
 * milestone:  Future Release =>


Comment:

 After much struggle, I managed to track down the problem:

 1. Our specific plugin calls `wp_editor( '', 'tasty-recipes-editor',
 array( 'teeny' => true ) );`. This instance isn't ever rendered. Rather,
 we then steal `tinyMCEPreInit.mceInit['tasty-recipes-editor']` when we
 call `tinyMCE.init()` for our dynamic text fields.
 2. In the Classic Editor, TinyMCE is initialized via
 `WP_Editor->editor_js()`. However, TinyMCE is initialized in Gutenberg
 with `print_default_editor_scripts()`. The former makes the
 `tinyMCEPreInit.load_ext()` call while the latter does not.
 3. Gutenberg doesn't initialize external plugins globally on preinit, only
 when the Classic Block TinyMCE is initialized.

 I was able to work around this by filtering TeenyMCE init and always
 including our external plugin:

 {{{
 add_filter( 'teeny_mce_before_init', function( $settings, $editor_id ) {
         if ( 'tasty-recipes-editor' !== $editor_id ) {
                 return $settings;
         }
         $external_plugins = array();
         if ( isset( $settings['external_plugins'] ) ) {
                 if ( is_string( $settings['external_plugins'] ) ) {
                         $external_plugins = json_decode(
 $settings['external_plugins'], true ) ? : array();
                 } elseif ( is_array( $settings['external_plugins'] ) ) {
                         $external_plugins = $settings['external_plugins'];
                 }
         }
         $assets_path                    = dirname( dirname( __FILE__ ) ) .
 '/assets';
         $assets_url                     = plugins_url( 'assets', __DIR__
 );
         $filepath                       = '/js/tinymce-plugin.js';
         $mtime                          = filemtime( $assets_path .
 $filepath );
         $external_plugins['tastylinks'] = $assets_url . $filepath . '?v='
 . (int) $mtime;
         $settings['external_plugins']   = $external_plugins;
         return $settings;
 }, 10, 2 );
 }}}

 Closing this as `maybelater` as I don't think it's worth spending time
 fixing.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45893#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list