[wp-trac] [WordPress Trac] #53644: WPeditor not fully initialized in a classic metabox

WordPress Trac noreply at wordpress.org
Mon Oct 17 12:55:41 UTC 2022


#53644: WPeditor not fully initialized in a classic metabox
---------------------------+-------------------------
 Reporter:  dway           |       Owner:  (none)
     Type:  defect (bug)   |      Status:  closed
 Priority:  normal         |   Milestone:
Component:  TinyMCE        |     Version:  5.6
 Severity:  normal         |  Resolution:  worksforme
 Keywords:  needs-testing  |     Focuses:  javascript
---------------------------+-------------------------

Comment (by zaantar):

 I believe this is not fixed at all. It definitely isn't for me.

 After a very long time, I have a working solution. This function needs to
 be called after the Gutenberg editor has been fully loaded (which is a
 task in itself).

 Sharing here in the hopes it will help someone. Or that someone finds an
 actual fix to this.

 Original idea: https://stackoverflow.com/a/34764607

 {{{
 // An alternative (but awful) workaround is forcing TinyMCE to the HTML
 mode on every load:
 // add_filter( 'wp_default_editor', function() { return 'html'; } );
 const reinitializeAllWysiwygFields = () => {
         tinymce.EditorManager.editors.forEach( function( editor ) {
                 // Apparently, TinyMCE does some parts of the
 reinitialization asynchronously.
                 //
                 // When there is more than one instance, this creates a
 race condition on its own. Incorrect
                 // settings are loaded for the second and following
 editors, and the reinitialization breaks.
                 //
                 // That forces us to make an arbitrary pause between
 reinitialization so that TinyMCE can
                 // execute all its hooks and asynchronous calls in the
 meantime.
                 setTimeout( () => {
                         const oldGlobalSettings = tinymce.settings;
                         tinymce.settings = editor.settings;
                         tinymce.EditorManager.execCommand(
 'mceRemoveEditor', false, editor.id );
                         tinymce.EditorManager.execCommand( 'mceAddEditor',
 false, editor.id );
                         tinymce.settings = oldGlobalSettings;
                 }, 1000 );
         } );
 };
 }}}

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


More information about the wp-trac mailing list