WordPress.org

Make WordPress Core

Changeset 19408


Ignore:
Timestamp:
11/22/2011 09:47:01 PM (6 years ago)
Author:
azaozz
Message:

Restore back-compat with wp_tiny_mce(), see #19320

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/deprecated.php

    r19054 r19408  
    2222    _deprecated_function( __FUNCTION__, '2.1', 'wp_editor()' );
    2323
    24     wp_editor('', 'content');
     24    wp_tiny_mce();
    2525}
    2626
     
    709709 * @see wp_editor()
    710710 */
    711 function wp_tiny_mce() {
     711function wp_tiny_mce( $teeny = false, $settings = false ) {
    712712    _deprecated_function( __FUNCTION__, '3.3', 'wp_editor()' );
    713713
    714     wp_editor('', 'content');
     714    global $wp_editor;
     715    static $num = 1;
     716
     717    if ( !is_a($wp_editor, 'WP_Editor') ) {
     718        if ( !class_exists('WP_Editor') )
     719            require_once( ABSPATH . WPINC . '/class-wp-editor.php' );
     720
     721        $wp_editor = new WP_Editor;
     722    }
     723
     724    $editor_id = 'content' . $num;
     725    ++$num;
     726
     727    $set = array(
     728        'teeny' => $teeny,
     729        'tinymce' => $settings ? $settings : true,
     730        'quicktags' => false
     731    );
     732
     733    $set = $wp_editor->parse_settings($editor_id, $set);
     734    $wp_editor->editor_settings($editor_id, $set);
    715735}
    716736
  • trunk/wp-includes/class-wp-editor.php

    r19316 r19408  
    11<?php
    22/**
    3  * Adds the WordPress editor used on the Write and Edit screens.
     3 * Facilitates adding of the WordPress editor as used on the Write and Edit screens.
    44 *
    55 * @package WordPress
    66 * @since 3.3
    77 *
    8  * NOTE: Do not instantiate this class directly. Please use the wp_editor() function that will include the file
    9  * and instantiate the class if needed. If you want to extend this class use the 'init' or earlier action to do it
    10  * and call wp_editor() as usual when you need to output the HTML.
    11  *
    12  * Outputs the HTML and JavaScript for the WordPress editors, TinyMCE and Quicktags.
    13  * TinyMCE is loaded separately from other Javascript by using wp-tinymce.php. It outputs concatenated
    14  * pre-compressed version of the core and all default plugins. Additional plugins are loaded directly
    15  * by TinyMCE using non-blocking method.
     8 * Private, not included by default. See wp_editor() in wp-includes/general-template.php.
    169 */
    1710
     
    3326    var $has_quicktags = false;
    3427    var $has_medialib = false;
     28    var $editor_buttons_css = true;
    3529
    3630    function __construct() {
     
    3933    }
    4034
    41     /**
    42      * Outputs the HTML and enqueues the JavaScript for a single instance of the editor.
    43      *
    44      * @param string $content The initial content of the editor.
    45      * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers).
    46      * @param array $settings See below for description.
    47      */
    48     function editor( $content, $editor_id, $settings = array() ) {
    49 
     35    function parse_settings($editor_id, $settings) {
    5036        $set = wp_parse_args( $settings,  array(
    5137            'wpautop' => true, // use wpautop?
     
    6450        $this->this_tinymce = !empty($set['tinymce']) && $this->can_richedit;
    6551        $this->this_quicktags = !empty($set['quicktags']);
     52
     53        if ( $this->this_tinymce )
     54            $this->has_tinymce = true;
     55
     56        if ( $this->this_quicktags )
     57            $this->has_quicktags = true;
     58
     59        return $set;
     60    }
     61
     62    /**
     63     * Outputs the HTML for a single instance of the editor.
     64     *
     65     * @param string $content The initial content of the editor.
     66     * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers).
     67     * @param array $settings See WP_Editor::_parse_settings for description.
     68     */
     69    function editor( $content, $editor_id, $settings = array() ) {
     70
     71        $set = $this->parse_settings($editor_id, $settings);
    6672        $editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"';
    6773        $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
     
    7581        if ( $this->this_quicktags && $this->this_tinymce ) {
    7682            $switch_class = 'html-active';
    77             $this->has_tinymce = $this->has_quicktags = true;
    7883
    7984            if ( 'html' == $this->default_editor ) {
     
    8691            $buttons .= '<a id="' . $editor_id . '-html" class="hide-if-no-js wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">' . __('HTML') . "</a>\n";
    8792            $buttons .= '<a id="' . $editor_id . '-tmce" class="hide-if-no-js wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">' . __('Visual') . "</a>\n";
    88         } else {
    89             if ( $this->this_tinymce )
    90                 $this->has_tinymce = true;
    91 
    92             if ( $this->this_quicktags )
    93                 $this->has_quicktags = true;
    9493        }
    9594
    9695        echo '<div id="wp-' . $editor_id . '-wrap" class="wp-editor-wrap ' . $switch_class . '">';
    9796
    98         if ( empty($this->first_init) )
     97        if ( $this->editor_buttons_css ) {
    9998            wp_print_styles('editor-buttons');
     99            $this->editor_buttons_css = false;
     100        }
    100101
    101102        if ( !empty($set['editor_css']) )
     
    125126        echo "\n</div>\n\n";
    126127
    127         if ( empty($this->first_init) ) {
    128             add_action( 'admin_print_footer_scripts', array($this, 'editor_js'), 50 );
    129             add_action( 'wp_print_footer_scripts', array($this, 'editor_js'), 50 );
    130             add_action( 'admin_footer', array($this, 'enqueue_scripts'), 1 );
    131             add_action( 'wp_footer', array($this, 'enqueue_scripts'), 1 );
    132         }
    133 
    134128        $this->editor_settings($editor_id, $set);
    135129    }
     
    138132        global $editor_styles;
    139133        $first_run = false;
     134
     135        if ( empty($this->first_init) ) {
     136            if ( is_admin() ) {
     137                add_action( 'admin_print_footer_scripts', array($this, 'editor_js'), 50 );
     138                add_action( 'admin_footer', array($this, 'enqueue_scripts'), 1 );
     139            } else {
     140                add_action( 'wp_print_footer_scripts', array($this, 'editor_js'), 50 );
     141                add_action( 'wp_footer', array($this, 'enqueue_scripts'), 1 );
     142            }
     143        }
    140144
    141145        if ( $this->this_quicktags ) {
     
    407411
    408412            $this->mce_settings[$editor_id] = $mceInit;
    409             $first_run = false;
    410413        } // end if $this->this_tinymce
    411414    }
Note: See TracChangeset for help on using the changeset viewer.