From fb79e5e64c30599184e356a4c963c752ca659921 Mon Sep 17 00:00:00 2001 From: azaozz Date: Tue, 22 Nov 2011 21:47:01 +0000 Subject: [PATCH] Restore back-compat with wp_tiny_mce(), see #19320 git-svn-id: http://svn.automattic.com/wordpress/trunk@19408 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/deprecated.php | 28 +++++++++++-- wp-includes/class-wp-editor.php | 71 +++++++++++++++++--------------- 2 files changed, 61 insertions(+), 38 deletions(-) diff --git a/wp-admin/includes/deprecated.php b/wp-admin/includes/deprecated.php index cd3744b327..9d44204132 100644 --- a/wp-admin/includes/deprecated.php +++ b/wp-admin/includes/deprecated.php @@ -21,7 +21,7 @@ function tinymce_include() { _deprecated_function( __FUNCTION__, '2.1', 'wp_editor()' ); - wp_editor('', 'content'); + wp_tiny_mce(); } /** @@ -708,10 +708,30 @@ function wp_dashboard_quick_press_output() { * @deprecated Use wp_editor() * @see wp_editor() */ -function wp_tiny_mce() { +function wp_tiny_mce( $teeny = false, $settings = false ) { _deprecated_function( __FUNCTION__, '3.3', 'wp_editor()' ); - wp_editor('', 'content'); + global $wp_editor; + static $num = 1; + + if ( !is_a($wp_editor, 'WP_Editor') ) { + if ( !class_exists('WP_Editor') ) + require_once( ABSPATH . WPINC . '/class-wp-editor.php' ); + + $wp_editor = new WP_Editor; + } + + $editor_id = 'content' . $num; + ++$num; + + $set = array( + 'teeny' => $teeny, + 'tinymce' => $settings ? $settings : true, + 'quicktags' => false + ); + + $set = $wp_editor->parse_settings($editor_id, $set); + $wp_editor->editor_settings($editor_id, $set); } /** @@ -853,4 +873,4 @@ function type_url_form_video() { function type_url_form_file() { __deprecated_function( __FUNCTION__, '3.3', "wp_media_insert_url_form('file')" ); return wp_media_insert_url_form( 'file' ); -} \ No newline at end of file +} diff --git a/wp-includes/class-wp-editor.php b/wp-includes/class-wp-editor.php index 65279cfc9b..cbde53daf1 100644 --- a/wp-includes/class-wp-editor.php +++ b/wp-includes/class-wp-editor.php @@ -1,18 +1,11 @@ can_richedit = user_can_richedit(); $this->default_editor = $this->wp_default_editor(); } - /** - * Outputs the HTML and enqueues the JavaScript for a single instance of the editor. - * - * @param string $content The initial content of the editor. - * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers). - * @param array $settings See below for description. - */ - function editor( $content, $editor_id, $settings = array() ) { - + function parse_settings($editor_id, $settings) { $set = wp_parse_args( $settings, array( 'wpautop' => true, // use wpautop? 'media_buttons' => true, // show insert/upload button(s) @@ -63,6 +49,26 @@ class WP_Editor { $this->this_tinymce = !empty($set['tinymce']) && $this->can_richedit; $this->this_quicktags = !empty($set['quicktags']); + + if ( $this->this_tinymce ) + $this->has_tinymce = true; + + if ( $this->this_quicktags ) + $this->has_quicktags = true; + + return $set; + } + + /** + * Outputs the HTML for a single instance of the editor. + * + * @param string $content The initial content of the editor. + * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers). + * @param array $settings See WP_Editor::_parse_settings for description. + */ + function editor( $content, $editor_id, $settings = array() ) { + + $set = $this->parse_settings($editor_id, $settings); $editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"'; $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : ''; $rows = ' rows="' . (int) $set['textarea_rows'] . '"'; @@ -74,7 +80,6 @@ class WP_Editor { if ( $this->this_quicktags && $this->this_tinymce ) { $switch_class = 'html-active'; - $this->has_tinymce = $this->has_quicktags = true; if ( 'html' == $this->default_editor ) { add_filter('the_editor_content', 'wp_htmledit_pre'); @@ -85,18 +90,14 @@ class WP_Editor { $buttons .= '' . __('HTML') . "\n"; $buttons .= '' . __('Visual') . "\n"; - } else { - if ( $this->this_tinymce ) - $this->has_tinymce = true; - - if ( $this->this_quicktags ) - $this->has_quicktags = true; } echo '
'; - if ( empty($this->first_init) ) + if ( $this->editor_buttons_css ) { wp_print_styles('editor-buttons'); + $this->editor_buttons_css = false; + } if ( !empty($set['editor_css']) ) echo $set['editor_css'] . "\n"; @@ -124,13 +125,6 @@ class WP_Editor { printf($the_editor, $content); echo "\n
\n\n"; - if ( empty($this->first_init) ) { - add_action( 'admin_print_footer_scripts', array($this, 'editor_js'), 50 ); - add_action( 'wp_print_footer_scripts', array($this, 'editor_js'), 50 ); - add_action( 'admin_footer', array($this, 'enqueue_scripts'), 1 ); - add_action( 'wp_footer', array($this, 'enqueue_scripts'), 1 ); - } - $this->editor_settings($editor_id, $set); } @@ -138,6 +132,16 @@ class WP_Editor { global $editor_styles; $first_run = false; + if ( empty($this->first_init) ) { + if ( is_admin() ) { + add_action( 'admin_print_footer_scripts', array($this, 'editor_js'), 50 ); + add_action( 'admin_footer', array($this, 'enqueue_scripts'), 1 ); + } else { + add_action( 'wp_print_footer_scripts', array($this, 'editor_js'), 50 ); + add_action( 'wp_footer', array($this, 'enqueue_scripts'), 1 ); + } + } + if ( $this->this_quicktags ) { $qtInit = array( @@ -406,7 +410,6 @@ class WP_Editor { } $this->mce_settings[$editor_id] = $mceInit; - $first_run = false; } // end if $this->this_tinymce }