Skip to content

Instantly share code, notes, and snippets.

@DavidCramer
Created September 7, 2015 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DavidCramer/4a30399cb012e0040c09 to your computer and use it in GitHub Desktop.
Save DavidCramer/4a30399cb012e0040c09 to your computer and use it in GitHub Desktop.
reinit WP editors dynamically
function re_init_wp_editors(){
if( typeof tinyMCEPreInit === 'undefined'){
return;
}
var ed, init, edId, qtId, firstInit, wrapper;
if ( typeof tinymce !== 'undefined' ) {
for ( edId in tinyMCEPreInit.mceInit ) {
if ( firstInit ) {
init = tinyMCEPreInit.mceInit[edId] = tinymce.extend( {}, firstInit, tinyMCEPreInit.mceInit[edId] );
} else {
init = firstInit = tinyMCEPreInit.mceInit[edId];
}
wrapper = tinymce.DOM.select( '#wp-' + edId + '-wrap' )[0];
if ( ( tinymce.DOM.hasClass( wrapper, 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( edId ) ) &&
! init.wp_skip_init ) {
try {
tinymce.init( init );
if ( ! window.wpActiveEditor ) {
window.wpActiveEditor = edId;
}
} catch(e){}
}
}
}
for ( qtId in tinyMCEPreInit.qtInit ) {
try {
quicktags( tinyMCEPreInit.qtInit[qtId] );
if ( ! window.wpActiveEditor ) {
window.wpActiveEditor = qtId;
}
} catch(e){};
}
jQuery('.wp-editor-wrap').on( 'click.wp-editor', function() {
if ( this.id ) {
window.wpActiveEditor = this.id.slice( 3, -5 );
}
});
}
@DavidCramer
Copy link
Author

Work in progress...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment