[wp-trac] [WordPress Trac] #62450: TinyMCE editor doesn't load properly when initializing on Visual Tab (Firefox) [again]
WordPress Trac
noreply at wordpress.org
Tue May 5 17:19:17 UTC 2026
#62450: TinyMCE editor doesn't load properly when initializing on Visual Tab
(Firefox) [again]
-------------------------------------+-------------------------------------
Reporter: patkemper | Owner: (none)
Type: defect (bug) | Status: reopened
Priority: normal | Milestone: Awaiting Review
Component: TinyMCE | Version: 6.7
Severity: major | Resolution:
Keywords: reporter-feedback | Focuses: javascript,
needs-test-info needs-screenshots | administration
-------------------------------------+-------------------------------------
Comment (by vage91):
I have the same bug, but with ACF installed.
fix based on @trepidationcouk code that works also when switching between
Visual and Code mode:
{{{
<?php
add_action('acf/input/admin_footer', function() {
?>
<script type="text/javascript">
(function($){
if (typeof acf === 'undefined') return;
function initFieldTinyMCE(editorId, textareaVal) {
if (typeof tinymce === 'undefined') return;
var ed = tinymce.get(editorId);
if (ed) {
ed.setContent(textareaVal);
return;
}
if (window.tinyMCEPreInit && tinyMCEPreInit.mceInit &&
tinyMCEPreInit.mceInit[editorId]) {
tinymce.init(tinyMCEPreInit.mceInit[editorId]);
setTimeout(function() {
var newEd = tinymce.get(editorId);
if (newEd) newEd.setContent(textareaVal);
}, 100);
}
}
$(document).on('click', '.wp-switch-editor.switch-tmce',
function(e){
const $wrap = $(this).closest('.wp-editor-wrap');
const $acfField = $wrap.closest('.acf-field');
if (!$wrap.length || !$acfField.length) return;
const textarea = $wrap.find('textarea.wp-editor-area');
const editorId = textarea.attr('id');
e.preventDefault();
e.stopImmediatePropagation();
$wrap.removeClass('html-active').addClass('tmce-active');
let val = textarea.val();
if (typeof switchEditors !== 'undefined') {
val = switchEditors.wpautop(val);
}
setTimeout(function(){
initFieldTinyMCE(editorId, val);
}, 60);
});
$(document).on('click', '.wp-switch-editor.switch-html',
function(e){
const $wrap = $(this).closest('.wp-editor-wrap');
const $acfField = $wrap.closest('.acf-field');
if (!$wrap.length || !$acfField.length) return;
const textarea = $wrap.find('textarea.wp-editor-area');
const editorId = textarea.attr('id');
e.preventDefault();
e.stopImmediatePropagation();
$wrap.removeClass('tmce-active').addClass('html-active');
const ed = tinymce.get(editorId);
if (ed) {
ed.save();
if (typeof switchEditors !== 'undefined') {
let val = textarea.val();
val = switchEditors.pre_wpautop(val);
textarea.val(val);
}
}
});
})(jQuery);
</script>
<?php
});
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/62450#comment:20>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list