Skip to content

Commit

Permalink
Fix wysiwyg instantiation when user_can_richedit() is false. Fixes #1031
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsternberg committed Oct 6, 2017
1 parent 8f18824 commit bc5043c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
13 changes: 7 additions & 6 deletions includes/CMB2_JS.php
Expand Up @@ -124,12 +124,13 @@ protected static function localize( $debug ) {

$localized = true;
$l10n = array(
'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ),
'ajaxurl' => admin_url( '/admin-ajax.php' ),
'script_debug' => $debug,
'up_arrow_class' => 'dashicons dashicons-arrow-up-alt2',
'down_arrow_class' => 'dashicons dashicons-arrow-down-alt2',
'defaults' => array(
'ajax_nonce' => wp_create_nonce( 'ajax_nonce' ),
'ajaxurl' => admin_url( '/admin-ajax.php' ),
'script_debug' => $debug,
'up_arrow_class' => 'dashicons dashicons-arrow-up-alt2',
'down_arrow_class' => 'dashicons dashicons-arrow-down-alt2',
'user_can_richedit' => user_can_richedit(),
'defaults' => array(
'color_picker' => false,
'date_picker' => array(
'changeMonth' => true,
Expand Down
17 changes: 14 additions & 3 deletions js/cmb2-wysiwyg.js
Expand Up @@ -275,18 +275,25 @@ window.CMB2.wysiwyg = window.CMB2.wysiwyg || {};
return false;
}

var mceActive = window.cmb2_l10.user_can_richedit && window.tinyMCE;
var qtActive = 'function' === typeof window.quicktags;
$.extend( data, getGroupData( data ) );

initOptions( data );

$toReplace.replaceWith( data.template( data ) );

window.tinyMCE.init( tinyMCEPreInit.mceInit[ data.id ] );
if ( 'function' === typeof window.quicktags ) {
if ( mceActive ) {
window.tinyMCE.init( tinyMCEPreInit.mceInit[ data.id ] );
}

if ( qtActive ) {
window.quicktags( tinyMCEPreInit.qtInit[ data.id ] );
}

$( document.getElementById( data.id ) ).parents( '.wp-editor-wrap' ).removeClass( 'html-active' ).addClass( 'tmce-active' );
if ( mceActive ) {
$( document.getElementById( data.id ) ).parents( '.wp-editor-wrap' ).removeClass( 'html-active' ).addClass( 'tmce-active' );
}

if ( false !== buttonsInit && 'undefined' !== typeof window.QTags ) {
window.QTags._buttonsInit();
Expand All @@ -304,6 +311,10 @@ window.CMB2.wysiwyg = window.CMB2.wysiwyg || {};
* @return {void}
*/
wysiwyg.destroy = function( id ) {
if ( ! window.cmb2_l10.user_can_richedit || ! window.tinyMCE ) {
// Nothing to see here.
return;
}

// The editor might not be initialized yet. But we need to destroy it once it is.
var editor = tinyMCE.get( id );
Expand Down

0 comments on commit bc5043c

Please sign in to comment.