diff --git a/includes/admin/assets/js/um-admin-modal.js b/includes/admin/assets/js/um-admin-modal.js index cec5ee6c..e0b9b414 100644 --- a/includes/admin/assets/js/um-admin-modal.js +++ b/includes/admin/assets/js/um-admin-modal.js @@ -37,7 +37,7 @@ function um_admin_new_modal( id, ajax, size ) { function um_tinymce_init( id, content ) { var object = jQuery('#' + id); - if ( tinyMCE.get( id ) !== null ) { + if ( typeof(tinyMCE) === 'object' && tinyMCE.get( id ) !== null ) { tinyMCE.triggerSave(); tinyMCE.EditorManager.execCommand( 'mceRemoveEditor', true, id ); "4" === tinyMCE.majorVersion ? window.tinyMCE.execCommand( "mceRemoveEditor", !0, id ) : window.tinyMCE.execCommand( "mceRemoveControl", !0, id ); @@ -55,7 +55,9 @@ function um_tinymce_init( id, content ) { QTags( tinyMCEPreInit.qtInit[ id ] ); QTags._buttonsInit(); } - window.switchEditors.go( id ); + if ( typeof(window.switchEditors) === 'object' ) { + window.switchEditors.go( id ); + } tinyMCE.init( init ); tinyMCE.get( id ).setContent( content ); object.html( content ); @@ -77,7 +79,7 @@ function um_tinymce_init( id, content ) { jQuery( 'body' ).on( 'click', '.wp-switch-editor', function() { var target = jQuery(this); - if ( target.hasClass( 'wp-switch-editor' ) ) { + if ( target.hasClass( 'wp-switch-editor' ) && typeof(window.switchEditors) === 'object' ) { var mode = target.hasClass( 'switch-tmce' ) ? 'tmce' : 'html'; window.switchEditors.go( id, mode ); } diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index 25a0f753..09601894 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -98,6 +98,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { function enqueue_cpt_scripts() { if ( ( isset( $_GET['post_type'] ) && 'um_form' == $_GET['post_type'] ) || ( isset( $_GET['post'] ) && 'um_form' == get_post_type( $_GET['post'] ) ) ) { $this->um_cpt_form_screen = true; + add_action( 'admin_footer', array( $this, 'admin_footer_scripts' ), 20 ); } $this->post_page = true; @@ -265,7 +266,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { wp_register_style( 'um_admin_modal', $this->css_url . 'um-admin-modal.css', array( 'wp-color-picker' ), ultimatemember_version ); wp_enqueue_style( 'um_admin_modal' ); - wp_register_script( 'um_admin_modal', $this->js_url . 'um-admin-modal.js', array( 'jquery', 'wp-util', 'wp-color-picker' ), ultimatemember_version, true ); + wp_register_script( 'um_admin_modal', $this->js_url . 'um-admin-modal.js', array( 'jquery', 'editor', 'wp-util', 'wp-color-picker', 'wp-tinymce' ), ultimatemember_version, true ); wp_enqueue_script( 'um_admin_modal' ); } @@ -648,5 +649,32 @@ if ( ! class_exists( 'um\admin\core\Admin_Enqueue' ) ) { } + + /** + * Print editor scripts if they are not printed by default + * @return type + */ + function admin_footer_scripts() { + $CLASS = '\_WP_Editors'; + + if ( did_action( 'print_default_editor_scripts' ) ) { + return; + } + if ( did_action( 'wp_tiny_mce_init' ) ) { + return; + } + if ( has_action( 'admin_print_footer_scripts', array( $CLASS, 'editor_js' ) ) ) { + return; + } + + if ( !class_exists( $CLASS, false ) ) { + require_once( ABSPATH . WPINC . '/class-wp-editor.php' ); + } + + $CLASS::force_uncompressed_tinymce(); + $CLASS::enqueue_scripts(); + $CLASS::editor_js(); + } + } } diff --git a/includes/admin/core/class-admin-metabox.php b/includes/admin/core/class-admin-metabox.php index eac5b9a6..a066b7f9 100644 --- a/includes/admin/core/class-admin-metabox.php +++ b/includes/admin/core/class-admin-metabox.php @@ -1091,9 +1091,9 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) { if ( ! empty( $mode ) ) { $posts = $wpdb->get_col( - "SELECT post_id - FROM {$wpdb->postmeta} - WHERE meta_key = '_um_mode' AND + "SELECT post_id + FROM {$wpdb->postmeta} + WHERE meta_key = '_um_mode' AND meta_value = 'directory'" ); @@ -1149,9 +1149,9 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) { $mode = UM()->query()->get_attr( 'mode', $post_id ); if ( ! empty( $mode ) ) { $posts = $wpdb->get_col( $wpdb->prepare( - "SELECT post_id - FROM {$wpdb->postmeta} - WHERE meta_key = '_um_mode' AND + "SELECT post_id + FROM {$wpdb->postmeta} + WHERE meta_key = '_um_mode' AND meta_value = %s", $mode ) );