From 2ebdfc16eb962975a973cefbd1e5ee7504713196 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 10 Jul 2021 23:57:43 +0000 Subject: [PATCH] TinyMCE: ensure initialization runs in all cases on 'interactive' and 'complete' readyState. Fixes a rare bug when the init code is inserted in the DOM after the page has finished loading. Props Collizo4sky, azaozz. Fixes #53632. git-svn-id: https://develop.svn.wordpress.org/trunk@51402 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-editor.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/class-wp-editor.php b/src/wp-includes/class-wp-editor.php index 914613508e..61cda16585 100644 --- a/src/wp-includes/class-wp-editor.php +++ b/src/wp-includes/class-wp-editor.php @@ -1663,7 +1663,8 @@ final class _WP_Editors { ?> ( function() { - var initialize = function() { + var initialized = []; + var initialize = function() { var init, id, inPostbox, $wrap; var readyState = document.readyState; @@ -1672,6 +1673,10 @@ final class _WP_Editors { } for ( id in tinyMCEPreInit.mceInit ) { + if ( initialized.indexOf( id ) > -1 ) { + continue; + } + init = tinyMCEPreInit.mceInit[id]; $wrap = tinymce.$( '#wp-' + id + '-wrap' ); inPostbox = $wrap.parents( '.postbox' ).length > 0; @@ -1679,9 +1684,10 @@ final class _WP_Editors { if ( ! init.wp_skip_init && ( $wrap.hasClass( 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( id ) ) && - ( ( inPostbox && readyState === 'complete' ) || ( ! inPostbox && readyState === 'interactive' ) ) + ( readyState === 'complete' || ( ! inPostbox && readyState === 'interactive' ) ) ) { tinymce.init( init ); + initialized.push( id ); if ( ! window.wpActiveEditor ) { window.wpActiveEditor = id;