Make WordPress Core

Ticket #35760: 35760.patch

File 35760.patch, 28.1 KB (added by azaozz, 8 years ago)
  • src/wp-admin/includes/ajax-actions.php

     
    14971497
    14981498        $args['pagenum'] = ! empty( $_POST['page'] ) ? absint( $_POST['page'] ) : 1;
    14991499
    1500         require(ABSPATH . WPINC . '/class-wp-editor.php');
     1500        if ( ! class_exists( '_WP_Editors', false ) ) {
     1501                require( ABSPATH . WPINC . '/class-wp-editor.php' );
     1502        }
     1503
    15011504        $results = _WP_Editors::wp_link_query( $args );
    15021505
    15031506        if ( ! isset( $results ) )
  • src/wp-admin/js/editor.js

     
     1window.wp = window.wp || {};
    12
    2 ( function( $ ) {
     3( function( $, wp ) {
     4        wp.editor = wp.editor || {};
     5
    36        /**
    47         * @summary Utility functions for the editor.
    58         *
     
    484487                        } );
    485488                }
    486489
    487                 window.wp = window.wp || {};
    488                 window.wp.editor = window.wp.editor || {};
    489                 window.wp.editor.autop = wpautop;
    490                 window.wp.editor.removep = pre_wpautop;
     490                wp.editor.autop = wpautop;
     491                wp.editor.removep = pre_wpautop;
    491492
    492493                exports = {
    493494                        go: switchEditor,
     
    505506         * Expose the switch editors to be used globally.
    506507         */
    507508        window.switchEditors = new SwitchEditors();
    508 }( window.jQuery ));
     509
     510        /**
     511         * Initialize TinyMCE and/or Quicktags. For use with wp_enqueue_editor() (PHP).
     512         *
     513         * Intended for use with an existing textarea that will become the Text editor tab.
     514         * The editor width will be the width of the textarea container, height will be adjustable.
     515         *
     516         * Settings for both TinyMCE and Quicktags can be passed on initialization, and are "filtered"
     517         * with custom jQuery events on the document element, wp-before-tinymce-init and wp-before-quicktags-init.
     518         *
     519         * @since 4.8
     520         *
     521         * @param {string} id The HTML id of the textarea that is used for the editor.
     522         *                    Has to be jQuery compliant. No brackets, special chars, etc.
     523         * @param {object} settings Example:
     524         * settings = {
     525         *    // See https://www.tinymce.com/docs/configure/integration-and-setup/.
     526         *    // Alternatively set to `true` to use the defaults.
     527         *    tinymce: {
     528         *        setup: function( editor ) {
     529         *            console.log( 'Editor initialized', editor );
     530         *        }
     531         *    }
     532         *
     533         *    // Alternatively set to `true` to use the defaults.
     534         *        quicktags: {
     535         *        buttons: 'strong,em,link'
     536         *    }
     537         * }
     538         */
     539        wp.editor.initialize = function( id, settings ) {
     540                var init;
     541                var defaults;
     542
     543                if ( ! $ || ! id || ! wp.editor.getDefaultSettings ) {
     544                        return;
     545                }
     546
     547                defaults = wp.editor.getDefaultSettings();
     548
     549                // Add wrap and the Visual|Text tabs.
     550                if ( settings.tinymce && settings.quicktags ) {
     551                        var $textarea = $( '#' + id );
     552                        var $wrap = $( '<div>' ).attr( {
     553                                        'class': 'wp-core-ui wp-editor-wrap tmce-active',
     554                                        id: 'wp-' + id + '-wrap'
     555                                } );
     556                        var $button = $( '<button>' ).attr( {
     557                                        type: 'button',
     558                                        'data-wp-editor-id': id
     559                                } );
     560
     561                        $wrap.append(
     562                                $( '<div class="wp-editor-tools">' )
     563                                        .append( $( '<div class="wp-editor-tabs">' )
     564                                                .append( $button.clone().attr({
     565                                                        id: id + '-tmce',
     566                                                        'class': 'wp-switch-editor switch-tmce'
     567                                                }).text( window.tinymce.translate( 'Visual' ) ) )
     568                                                .append( $button.clone().attr({
     569                                                        id: id + '-html',
     570                                                        'class': 'wp-switch-editor switch-html'
     571                                                }).text( window.tinymce.translate( 'Text' ) ) )
     572                                )
     573                        );
     574
     575                        $textarea.after( $wrap );
     576                        $wrap.append( $textarea );
     577                }
     578
     579                if ( window.tinymce && settings.tinymce ) {
     580                        if ( typeof settings.tinymce !== 'object' ) {
     581                                settings.tinymce = {};
     582                        }
     583
     584                        init = $.extend( {}, defaults.tinymce, settings.tinymce );
     585                        init.selector = '#' + id;
     586
     587                        $( document ).trigger( 'wp-before-tinymce-init', init );
     588                        window.tinymce.init( init );
     589
     590                        if ( ! window.wpActiveEditor ) {
     591                                window.wpActiveEditor = id;
     592                        }
     593                }
     594
     595                if ( window.quicktags && settings.quicktags ) {
     596                        if ( typeof settings.quicktags !== 'object' ) {
     597                                settings.quicktags = {};
     598                        }
     599
     600                        init = $.extend( {}, defaults.quicktags, settings.quicktags );
     601                        init.id = id;
     602
     603                        $( document ).trigger( 'wp-before-quicktags-init', init );
     604                        window.quicktags( init );
     605
     606                        if ( ! window.wpActiveEditor ) {
     607                                window.wpActiveEditor = init.id;
     608                        }
     609                }
     610        };
     611
     612        /**
     613         * Get the editor content.
     614         *
     615         * Intended for use with editors that were initialized with wp.editor.initialize().
     616         *
     617         * @since 4.8
     618         *
     619         * @param {string} id The HTML id of the editor textarea.
     620         * @return The editor content.
     621         */
     622        wp.editor.getContent = function( id ) {
     623                var editor;
     624
     625                if ( ! $ || ! id ) {
     626                        return;
     627                }
     628
     629                if ( window.tinymce ) {
     630                        editor = window.tinymce.get( id );
     631
     632                        if ( editor && ! editor.isHidden() ) {
     633                                editor.save();
     634                        }
     635                }
     636
     637                return $( '#' + id ).val();
     638        };
     639
     640}( window.jQuery, window.wp ));
  • src/wp-includes/class-wp-editor.php

     
    2727        private static $drag_drop_upload = false;
    2828        private static $old_dfw_compat = false;
    2929        private static $translation;
     30        private static $tinymce_scripts_printed = false;
     31        private static $link_dialog_printed = false;
    3032
    3133        private function __construct() {}
    3234
     
    350352                if ( self::$this_tinymce ) {
    351353
    352354                        if ( empty( self::$first_init ) ) {
    353                                 self::$baseurl = includes_url( 'js/tinymce' );
    354 
    355                                 $mce_locale = get_user_locale();
    356                                 self::$mce_locale = $mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1
    357 
    358                                 /** This filter is documented in wp-admin/includes/media.php */
    359                                 $no_captions = (bool) apply_filters( 'disable_captions', '' );
     355                                $baseurl = self::get_baseurl();
     356                                $mce_locale = self::get_mce_locale();
    360357                                $ext_plugins = '';
    361                                 $shortcut_labels = array();
    362358
    363                                 foreach ( self::get_translation() as $name => $value ) {
    364                                         if ( is_array( $value ) ) {
    365                                                 $shortcut_labels[$name] = $value[1];
    366                                         }
    367                                 }
    368 
    369359                                if ( $set['teeny'] ) {
    370360
    371361                                        /**
     
    376366                                         * @param array  $plugins   An array of teenyMCE plugins.
    377367                                         * @param string $editor_id Unique editor identifier, e.g. 'content'.
    378368                                         */
    379                                         self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array( 'colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink' ), $editor_id );
     369                                        $plugins = apply_filters( 'teeny_mce_plugins', array( 'colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink' ), $editor_id );
    380370                                } else {
    381371
    382372                                        /**
     
    521511                                self::$plugins = $plugins;
    522512                                self::$ext_plugins = $ext_plugins;
    523513
    524                                 self::$first_init = array(
    525                                         'theme' => 'modern',
    526                                         'skin' => 'lightgray',
    527                                         'language' => self::$mce_locale,
    528                                         'formats' => '{' .
    529                                                 'alignleft: [' .
    530                                                         '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"left"}},' .
    531                                                         '{selector: "img,table,dl.wp-caption", classes: "alignleft"}' .
    532                                                 '],' .
    533                                                 'aligncenter: [' .
    534                                                         '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"center"}},' .
    535                                                         '{selector: "img,table,dl.wp-caption", classes: "aligncenter"}' .
    536                                                 '],' .
    537                                                 'alignright: [' .
    538                                                         '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"right"}},' .
    539                                                         '{selector: "img,table,dl.wp-caption", classes: "alignright"}' .
    540                                                 '],' .
    541                                                 'strikethrough: {inline: "del"}' .
    542                                         '}',
    543                                         'relative_urls' => false,
    544                                         'remove_script_host' => false,
    545                                         'convert_urls' => false,
    546                                         'browser_spellcheck' => true,
    547                                         'fix_list_elements' => true,
    548                                         'entities' => '38,amp,60,lt,62,gt',
    549                                         'entity_encoding' => 'raw',
    550                                         'keep_styles' => false,
    551                                         'cache_suffix' => 'wp-mce-' . $tinymce_version,
     514                                $settings = self::default_settings();
     515                                $settings['plugins'] = implode( ',', $plugins );
    552516
    553                                         // Limit the preview styles in the menu/toolbar
    554                                         'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform',
    555 
    556                                         'end_container_on_empty_block' => true,
    557                                         'wpeditimage_disable_captions' => $no_captions,
    558                                         'wpeditimage_html5_captions' => current_theme_supports( 'html5', 'caption' ),
    559                                         'plugins' => implode( ',', $plugins ),
    560                                         'wp_lang_attr' => get_bloginfo( 'language' ),
    561                                         'wp_shortcut_labels' => wp_json_encode( $shortcut_labels ),
    562                                 );
    563 
    564517                                if ( ! empty( $mce_external_plugins ) ) {
    565                                         self::$first_init['external_plugins'] = wp_json_encode( $mce_external_plugins );
     518                                        $settings['external_plugins'] = wp_json_encode( $mce_external_plugins );
    566519                                }
    567520
    568                                 $suffix = SCRIPT_DEBUG ? '' : '.min';
    569                                 $version = 'ver=' . get_bloginfo( 'version' );
    570                                 $dashicons = includes_url( "css/dashicons$suffix.css?$version" );
     521                                /** This filter is documented in wp-admin/includes/media.php */
     522                                if ( apply_filters( 'disable_captions', '' ) ) {
     523                                        $settings['wpeditimage_disable_captions'] = true;
     524                                }
    571525
    572                                 // WordPress default stylesheet and dashicons
    573                                 $mce_css = array(
    574                                         $dashicons,
    575                                         self::$baseurl . '/skins/wordpress/wp-content.css?' . $version
    576                                 );
     526                                $mce_css = $settings['content_css'];
     527                                $editor_styles = get_editor_stylesheets();
    577528
    578                                 $editor_styles = get_editor_stylesheets();
    579529                                if ( ! empty( $editor_styles ) ) {
    580                                         foreach ( $editor_styles as $style ) {
    581                                                 $mce_css[] = $style;
    582                                         }
     530                                        $mce_css .= ',' . implode( ',', $editor_styles );
    583531                                }
    584532
    585533                                /**
     
    589537                                 *
    590538                                 * @param string $stylesheets Comma-delimited list of stylesheets.
    591539                                 */
    592                                 $mce_css = trim( apply_filters( 'mce_css', implode( ',', $mce_css ) ), ' ,' );
     540                                $mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' );
    593541
    594                                 if ( ! empty($mce_css) )
    595                                         self::$first_init['content_css'] = $mce_css;
     542                                if ( ! empty( $mce_css ) ) {
     543                                        $settings['content_css'] = $mce_css;
     544                                } else {
     545                                        unset( $settings['content_css'] );
     546                                }
     547
     548                                self::$first_init = $settings;
    596549                        }
    597550
    598551                        if ( $set['teeny'] ) {
     
    690643
    691644                        $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
    692645
    693                         if ( !empty($set['tinymce']['body_class']) ) {
     646                        if ( ! empty( $set['tinymce']['body_class'] ) ) {
    694647                                $body_class .= ' ' . $set['tinymce']['body_class'];
    695                                 unset($set['tinymce']['body_class']);
     648                                unset( $set['tinymce']['body_class'] );
    696649                        }
    697650
    698651                        $mceInit = array (
    699652                                'selector' => "#$editor_id",
    700                                 'resize' => 'vertical',
    701                                 'menubar' => false,
    702653                                'wpautop' => (bool) $set['wpautop'],
    703654                                'indent' => ! $set['wpautop'],
    704                                 'toolbar1' => implode($mce_buttons, ','),
    705                                 'toolbar2' => implode($mce_buttons_2, ','),
    706                                 'toolbar3' => implode($mce_buttons_3, ','),
    707                                 'toolbar4' => implode($mce_buttons_4, ','),
     655                                'toolbar1' => implode( ',', $mce_buttons ),
     656                                'toolbar2' => implode( ',', $mce_buttons_2 ),
     657                                'toolbar3' => implode( ',', $mce_buttons_3 ),
     658                                'toolbar4' => implode( ',', $mce_buttons_4 ),
    708659                                'tabfocus_elements' => $set['tabfocus_elements'],
    709660                                'body_class' => $body_class
    710661                        );
     
    762713         * @param array $init
    763714         * @return string
    764715         */
    765         private static function _parse_init($init) {
     716        private static function _parse_init( $init ) {
    766717                $options = '';
    767718
    768                 foreach ( $init as $k => $v ) {
    769                         if ( is_bool($v) ) {
    770                                 $val = $v ? 'true' : 'false';
    771                                 $options .= $k . ':' . $val . ',';
     719                foreach ( $init as $key => $value ) {
     720                        if ( is_bool( $value ) ) {
     721                                $val = $value ? 'true' : 'false';
     722                                $options .= $key . ':' . $val . ',';
    772723                                continue;
    773                         } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {
    774                                 $options .= $k . ':' . $v . ',';
     724                        } elseif ( ! empty( $value ) && is_string( $value ) && (
     725                                ( '{' == $value{0} && '}' == $value{strlen( $value ) - 1} ) ||
     726                                ( '[' == $value{0} && ']' == $value{strlen( $value ) - 1} ) ||
     727                                preg_match( '/^\(?function ?\(/', $value ) ) ) {
     728
     729                                $options .= $key . ':' . $value . ',';
    775730                                continue;
    776731                        }
    777                         $options .= $k . ':"' . $v . '",';
     732                        $options .= $key . ':"' . $value . '",';
    778733                }
    779734
    780735                return '{' . trim( $options, ' ,' ) . '}';
     
    784739         *
    785740         * @static
    786741         */
    787         public static function enqueue_scripts() {
    788                 if ( self::$has_tinymce )
    789                         wp_enqueue_script('editor');
     742        public static function enqueue_scripts( $default_scripts = false ) {
     743                if ( $default_scripts || self::$has_tinymce ) {
     744                        wp_enqueue_script( 'editor' );
     745                }
    790746
    791                 if ( self::$has_quicktags ) {
     747                if ( $default_scripts || self::$has_quicktags ) {
    792748                        wp_enqueue_script( 'quicktags' );
    793749                        wp_enqueue_style( 'buttons' );
    794750                }
    795751
    796                 if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {
    797                         wp_enqueue_script('wplink');
     752                if ( $default_scripts || in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) ) {
     753                        wp_enqueue_script( 'wplink' );
    798754                        wp_enqueue_script( 'jquery-ui-autocomplete' );
    799755                }
    800756
    801757                if ( self::$old_dfw_compat ) {
    802                         wp_enqueue_script('wp-fullscreen-stub');
     758                        wp_enqueue_script( 'wp-fullscreen-stub' );
    803759                }
    804760
    805761                if ( self::$has_medialib ) {
     
    806762                        add_thickbox();
    807763                        wp_enqueue_script( 'media-upload' );
    808764                        wp_enqueue_script( 'wp-embed' );
     765                } elseif ( $default_scripts ) {
     766                        wp_enqueue_script( 'media-upload' );
    809767                }
    810768
    811769                /**
     
    817775                 *                       and Quicktags are being loaded.
    818776                 */
    819777                do_action( 'wp_enqueue_editor', array(
    820                         'tinymce'   => self::$has_tinymce,
    821                         'quicktags' => self::$has_quicktags,
     778                        'tinymce'   => ( $default_scripts || self::$has_tinymce ),
     779                        'quicktags' => ( $default_scripts || self::$has_quicktags ),
    822780                ) );
    823781        }
    824782
     783        public static function enqueue_default_editor() {
     784                // We are past the point where scripts can be enqueued properly.
     785                if ( did_action( 'wp_enqueue_editor' ) ) {
     786                        return;
     787                }
     788
     789                self::enqueue_scripts( true );
     790
     791                // Also add wp-includes/css/editor.css
     792                wp_enqueue_style( 'editor-buttons' );
     793
     794                if ( is_admin() ) {
     795                        add_action( 'admin_print_footer_scripts', array( __CLASS__, 'print_default_editor_scripts' ), 45 );
     796                } else {
     797                        add_action( 'wp_print_footer_scripts', array( __CLASS__, 'print_default_editor_scripts' ), 45 );
     798                }
     799        }
     800
     801        public static function print_default_editor_scripts() {
     802                $settings = self::default_settings();
     803
     804                $settings['toolbar1'] = 'bold,italic,bullist,numlist,link';
     805                $settings['wpautop'] = false;
     806                $settings['indent'] = true;
     807                $settings['elementpath'] = false;
     808
     809                // In production all plugins are loaded (they are in wp-editor.js.gz)
     810                // but only these will be initialized by default.
     811                $settings['plugins'] = implode( ',', array(
     812                        'charmap',
     813                        'colorpicker',
     814                        'hr',
     815                        'lists',
     816        //              'media',
     817                        'paste',
     818                        'tabfocus',
     819                        'textcolor',
     820                        'fullscreen',
     821                        'wordpress',
     822        //              'wpautoresize',
     823                        'wpeditimage',
     824                        'wpemoji',
     825                        'wpgallery',
     826                        'wplink',
     827        //              'wpdialogs',
     828                        'wptextpattern',
     829        //              'wpview',
     830                ) );
     831
     832                $settings = self::_parse_init( $settings );
     833
     834                $suffix = SCRIPT_DEBUG ? '' : '.min';
     835                $baseurl = self::get_baseurl();
     836
     837                ?>
     838                <script type="text/javascript">
     839                window.wp = window.wp || {};
     840                window.wp.editor = window.wp.editor || {};
     841                window.wp.editor.getDefaultSettings = function() {
     842                        return {
     843                                tinymce: <?php echo $settings; ?>,
     844                                quicktags: {
     845                                        buttons: 'strong,em,link,ul,ol,li,code'
     846                                }
     847                        };
     848                };
     849
     850                var tinyMCEPreInit = {
     851                        baseURL: "<?php echo $baseurl; ?>",
     852                        suffix: "<?php echo $suffix; ?>",
     853                        mceInit: {},
     854                        qtInit: {},
     855                        load_ext: function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
     856                };
     857                </script>
     858                <?php
     859
     860                self::print_tinymce_scripts();
     861
     862                self::wp_link_dialog();
     863        }
     864
     865        public static function get_mce_locale() {
     866                if ( empty( self::$mce_locale ) ) {
     867                        $mce_locale = get_user_locale();
     868                        self::$mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1
     869                }
     870
     871                return self::$mce_locale;
     872        }
     873
     874        public static function get_baseurl() {
     875                if ( empty( self::$baseurl ) ) {
     876                        self::$baseurl = includes_url( 'js/tinymce' );
     877                }
     878
     879                return self::$baseurl;
     880        }
     881
     882        // Only default settings. Doesn't include plugins, buttons, editor selector.
     883        private static function default_settings() {
     884                global $tinymce_version;
     885
     886                $shortcut_labels = array();
     887
     888                foreach ( self::get_translation() as $name => $value ) {
     889                        if ( is_array( $value ) ) {
     890                                $shortcut_labels[$name] = $value[1];
     891                        }
     892                }
     893
     894                $settings = array(
     895                        'theme' => 'modern',
     896                        'skin' => 'lightgray',
     897                        'language' => self::get_mce_locale(),
     898                        'formats' => '{' .
     899                                'alignleft: [' .
     900                                        '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"left"}},' .
     901                                        '{selector: "img,table,dl.wp-caption", classes: "alignleft"}' .
     902                                '],' .
     903                                'aligncenter: [' .
     904                                        '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"center"}},' .
     905                                        '{selector: "img,table,dl.wp-caption", classes: "aligncenter"}' .
     906                                '],' .
     907                                'alignright: [' .
     908                                        '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"right"}},' .
     909                                        '{selector: "img,table,dl.wp-caption", classes: "alignright"}' .
     910                                '],' .
     911                                'strikethrough: {inline: "del"}' .
     912                        '}',
     913                        'relative_urls' => false,
     914                        'remove_script_host' => false,
     915                        'convert_urls' => false,
     916                        'browser_spellcheck' => true,
     917                        'fix_list_elements' => true,
     918                        'entities' => '38,amp,60,lt,62,gt',
     919                        'entity_encoding' => 'raw',
     920                        'keep_styles' => false,
     921                        'cache_suffix' => 'wp-mce-' . $tinymce_version,
     922                        'resize' => 'vertical',
     923                        'menubar' => false,
     924
     925                        // Limit the preview styles in the menu/toolbar
     926                        'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform',
     927
     928                        'end_container_on_empty_block' => true,
     929                        'wpeditimage_html5_captions' => true,
     930                        'wp_lang_attr' => get_bloginfo( 'language' ),
     931                        'wp_shortcut_labels' => wp_json_encode( $shortcut_labels ),
     932                );
     933
     934                $suffix = SCRIPT_DEBUG ? '' : '.min';
     935                $version = 'ver=' . get_bloginfo( 'version' );
     936
     937                // Default stylesheets
     938                $settings['content_css'] = includes_url( "css/dashicons$suffix.css?$version" ) . ',' .
     939                        includes_url( "js/tinymce/skins/wordpress/wp-content.css?$version" );
     940
     941                return $settings;
     942        }
     943
    825944        private static function get_translation() {
    826945                if ( empty( self::$translation ) ) {
    827946                        self::$translation = array(
     
    10281147
    10291148                        /* translators: word count */
    10301149                        'Words: {0}' => sprintf( __( 'Words: %s' ), '{0}' ),
    1031                         'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' => __( 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' ) . "\n\n" . __( 'If you&#8217;re looking to paste rich content from Microsoft Word, try turning this option off. The editor will clean up text pasted from Word automatically.' ),
    1032                         'Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help' => __( 'Rich Text Area. Press Alt-Shift-H for help.' ),
     1150                        'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' =>
     1151                                __( 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' ) . "\n\n" .
     1152                                __( 'If you&#8217;re looking to paste rich content from Microsoft Word, try turning this option off. The editor will clean up text pasted from Word automatically.' ),
     1153                        'Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help' =>
     1154                                __( 'Rich Text Area. Press Alt-Shift-H for help.' ),
    10331155                        'Rich Text Area. Press Control-Option-H for help.' => __( 'Rich Text Area. Press Control-Option-H for help.' ),
    1034                         'You have unsaved changes are you sure you want to navigate away?' => __( 'The changes you made will be lost if you navigate away from this page.' ),
    1035                         'Your browser doesn\'t support direct access to the clipboard. Please use the Ctrl+X/C/V keyboard shortcuts instead.' => __( 'Your browser does not support direct access to the clipboard. Please use keyboard shortcuts or your browser&#8217;s edit menu instead.' ),
     1156                        'You have unsaved changes are you sure you want to navigate away?' =>
     1157                                __( 'The changes you made will be lost if you navigate away from this page.' ),
     1158                        'Your browser doesn\'t support direct access to the clipboard. Please use the Ctrl+X/C/V keyboard shortcuts instead.' =>
     1159                                __( 'Your browser does not support direct access to the clipboard. Please use keyboard shortcuts or your browser&#8217;s edit menu instead.' ),
    10361160
    10371161                        // TinyMCE menus
    10381162                        'Insert' => _x( 'Insert', 'TinyMCE menu' ),
     
    10551179                        'Paste URL or type to search' => __( 'Paste URL or type to search' ), // Placeholder for the inline link dialog
    10561180                        'Apply'  => __( 'Apply' ), // Tooltip for the 'apply' button in the inline link dialog
    10571181                        'Link options'  => __( 'Link options' ), // Tooltip for the 'link options' button in the inline link dialog
     1182                        'Visual' => __( 'Visual' ), // Editor switch tab label
     1183                        'Text' => __( 'Text' ), // Editor switch tab label
    10581184
    10591185                        // Shortcuts help modal
    10601186                        'Keyboard Shortcuts' => array( __( 'Keyboard Shortcuts' ), 'accessH' ),
     
    10981224        }
    10991225
    11001226        /**
    1101          * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
    1102          * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
     1227         * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n(),
     1228         * or as JS snippet that should run after tinymce.js is loaded.
    11031229         *
    11041230         * @static
    11051231         * @param string $mce_locale The locale used for the editor.
     
    11081234         */
    11091235        public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
    11101236                if ( ! $mce_locale ) {
    1111                         $mce_locale = self::$mce_locale;
     1237                        $mce_locale = self::get_mce_locale();
    11121238                }
    11131239
    11141240                $mce_translation = self::get_translation();
    1115                
     1241
    11161242                foreach ( $mce_translation as $name => $value ) {
    11171243                        if ( is_array( $value ) ) {
    11181244                                $mce_translation[$name] = $value[0];
     
    11501276                        return wp_json_encode( $mce_translation );
    11511277                }
    11521278
    1153                 $baseurl = self::$baseurl ? self::$baseurl : includes_url( 'js/tinymce' );
     1279                $baseurl = self::get_baseurl();
    11541280
    11551281                return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
    11561282                        "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
    11571283        }
    11581284
     1285        public static function print_tinymce_scripts() {
     1286                global $tinymce_version, $concatenate_scripts, $compress_scripts;
     1287
     1288                if ( self::$tinymce_scripts_printed ) {
     1289                        return;
     1290                }
     1291
     1292                self::$tinymce_scripts_printed = true;
     1293
     1294                if ( ! isset( $concatenate_scripts ) ) {
     1295                        script_concat_settings();
     1296                }
     1297
     1298                $version = 'ver=' . $tinymce_version;
     1299                $baseurl = self::get_baseurl();
     1300
     1301                $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
     1302                        && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
     1303
     1304                // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG)
     1305                $mce_suffix = false !== strpos( get_bloginfo( 'version' ), '-src' ) ? '' : '.min';
     1306
     1307                if ( $compressed ) {
     1308                        echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
     1309                } else {
     1310                        echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n";
     1311                        echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n";
     1312                }
     1313
     1314                echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";
     1315        }
     1316
    11591317        /**
    11601318         *
    11611319         * @static
     
    11661324        public static function editor_js() {
    11671325                global $tinymce_version, $concatenate_scripts, $compress_scripts;
    11681326
    1169                 /**
    1170                  * Filters "tiny_mce_version" is deprecated
    1171                  *
    1172                  * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
    1173                  * These plugins can be refreshed by appending query string to the URL passed to "mce_external_plugins" filter.
    1174                  * If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code).
    1175                  */
    1176                 $version = 'ver=' . $tinymce_version;
    1177                 $tmce_on = !empty(self::$mce_settings);
     1327                $tmce_on = ! empty( self::$mce_settings );
     1328                $mceInit = $qtInit = '';
    11781329
    1179                 if ( ! isset($concatenate_scripts) )
    1180                         script_concat_settings();
    1181 
    1182                 $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
    1183                         && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
    1184 
    1185                 $mceInit = $qtInit = '';
    11861330                if ( $tmce_on ) {
    11871331                        foreach ( self::$mce_settings as $editor_id => $init ) {
    11881332                                $options = self::_parse_init( $init );
    11891333                                $mceInit .= "'$editor_id':{$options},";
    11901334                        }
    1191                         $mceInit = '{' . trim($mceInit, ',') . '}';
     1335                        $mceInit = '{' . trim( $mceInit, ',' ) . '}';
    11921336                } else {
    11931337                        $mceInit = '{}';
    11941338                }
    11951339
    1196                 if ( !empty(self::$qt_settings) ) {
     1340                if ( ! empty( self::$qt_settings ) ) {
    11971341                        foreach ( self::$qt_settings as $editor_id => $init ) {
    11981342                                $options = self::_parse_init( $init );
    11991343                                $qtInit .= "'$editor_id':{$options},";
    12001344                        }
    1201                         $qtInit = '{' . trim($qtInit, ',') . '}';
     1345                        $qtInit = '{' . trim( $qtInit, ',' ) . '}';
    12021346                } else {
    12031347                        $qtInit = '{}';
    12041348                }
     
    12101354                );
    12111355
    12121356                $suffix = SCRIPT_DEBUG ? '' : '.min';
     1357                $baseurl = self::get_baseurl();
    12131358
    12141359                /**
    12151360                 * Fires immediately before the TinyMCE settings are printed.
     
    12231368
    12241369                <script type="text/javascript">
    12251370                tinyMCEPreInit = {
    1226                         baseURL: "<?php echo self::$baseurl; ?>",
     1371                        baseURL: "<?php echo $baseurl; ?>",
    12271372                        suffix: "<?php echo $suffix; ?>",
    12281373                        <?php
    12291374
     
    12401385                </script>
    12411386                <?php
    12421387
    1243                 $baseurl = self::$baseurl;
    1244                 // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG)
    1245                 $mce_suffix = false !== strpos( get_bloginfo( 'version' ), '-src' ) ? '' : '.min';
    1246 
    12471388                if ( $tmce_on ) {
    1248                         if ( $compressed ) {
    1249                                 echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
    1250                         } else {
    1251                                 echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n";
    1252                                 echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n";
    1253                         }
     1389                        self::print_tinymce_scripts();
    12541390
    1255                         echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";
    1256 
    12571391                        if ( self::$ext_plugins ) {
    12581392                                // Load the old-format English strings to prevent unsightly labels in old style popups
    12591393                                echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
     
    14341568         * @static
    14351569         */
    14361570        public static function wp_link_dialog() {
     1571                // Run once
     1572                if ( self::$link_dialog_printed ) {
     1573                        return;
     1574                }
     1575
     1576                self::$link_dialog_printed = true;
     1577
    14371578                // display: none is required here, see #WP27605
    14381579                ?>
    14391580                <div id="wp-link-backdrop" style="display: none"></div>
  • src/wp-includes/general-template.php

     
    30573057}
    30583058
    30593059/**
     3060 * Outputs the editor scripts, stylesheets, and default settings.
     3061 *
     3062 * The editor can be initialized when needed after page load.
     3063 * See wp.editor.initialize() in wp-admin/js/editor.js for initialization options.
     3064 *
     3065 * @uses _WP_Editors
     3066 * @since 4.8.0
     3067 */
     3068function wp_enqueue_editor() {
     3069        if ( ! class_exists( '_WP_Editors', false ) ) {
     3070                require( ABSPATH . WPINC . '/class-wp-editor.php' );
     3071        }
     3072
     3073        _WP_Editors::enqueue_default_editor();
     3074}
     3075
     3076/**
    30603077 * Retrieves the contents of the search WordPress query variable.
    30613078 *
    30623079 * The search query string is passed through esc_attr() to ensure that it is safe