]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/class-wp-editor.php
WordPress 4.6.3-scripts
[autoinstalls/wordpress.git] / wp-includes / class-wp-editor.php
index a016df52693b76033391407cca39cc9f9541e599..f7137f83ed805d4095d6b640918dd68165ce8388 100644 (file)
@@ -48,13 +48,14 @@ final class _WP_Editors {
         *     @type int        $textarea_rows     Number rows in the editor textarea. Default 20.
         *     @type string|int $tabindex          Tabindex value to use. Default empty.
         *     @type string     $tabfocus_elements The previous and next element ID to move the focus to
-        *                                         when pressing the Tab key in TinyMCE. Defualt ':prev,:next'.
+        *                                         when pressing the Tab key in TinyMCE. Default ':prev,:next'.
         *     @type string     $editor_css        Intended for extra styles for both Visual and Text editors.
         *                                         Should include `<style>` tags, and can use "scoped". Default empty.
-        *     @type string     $editor_class      Extra classes to add to the editor textarea elemen. Default empty.
+        *     @type string     $editor_class      Extra classes to add to the editor textarea element. Default empty.
         *     @type bool       $teeny             Whether to output the minimal editor config. Examples include
         *                                         Press This and the Comment editor. Default false.
-        *     @type bool       $dfw               Deprecated in 4.1. Since 4.3 used only to enqueue wp-fullscreen-stub.js for backwards compatibility.
+        *     @type bool       $dfw               Deprecated in 4.1. Since 4.3 used only to enqueue wp-fullscreen-stub.js
+        *                                         for backward compatibility.
         *     @type bool|array $tinymce           Whether to load TinyMCE. Can be used to pass settings directly to
         *                                         TinyMCE using an array. Default true.
         *     @type bool|array $quicktags         Whether to load Quicktags. Can be used to pass settings directly to
@@ -65,7 +66,7 @@ final class _WP_Editors {
        public static function parse_settings( $editor_id, $settings ) {
 
                /**
-                * Filter the wp_editor() settings.
+                * Filters the wp_editor() settings.
                 *
                 * @since 4.0.0
                 *
@@ -99,7 +100,7 @@ final class _WP_Editors {
                if ( self::$this_tinymce ) {
                        if ( false !== strpos( $editor_id, '[' ) ) {
                                self::$this_tinymce = false;
-                               _deprecated_argument( 'wp_editor()', '3.9', 'TinyMCE editor IDs cannot have brackets.' );
+                               _deprecated_argument( 'wp_editor()', '3.9.0', 'TinyMCE editor IDs cannot have brackets.' );
                        }
                }
 
@@ -147,7 +148,7 @@ final class _WP_Editors {
                $editor_class = ' class="' . trim( esc_attr( $set['editor_class'] ) . ' wp-editor-area' ) . '"';
                $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
                $default_editor = 'html';
-               $toolbar = $buttons = $autocomplete = '';
+               $buttons = $autocomplete = '';
                $editor_id_attr = esc_attr( $editor_id );
 
                if ( $set['drag_drop_upload'] ) {
@@ -240,7 +241,7 @@ final class _WP_Editors {
                }
 
                /**
-                * Filter the HTML markup output that displays the editor.
+                * Filters the HTML markup output that displays the editor.
                 *
                 * @since 2.1.0
                 *
@@ -251,20 +252,27 @@ final class _WP_Editors {
                        '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . esc_attr( $set['textarea_name'] ) . '" ' .
                        'id="' . $editor_id_attr . '">%s</textarea></div>' );
 
-               // Prepare the content for the Visual or Text editor
+               // Prepare the content for the Visual or Text editor, only when TinyMCE is used (back-compat).
                if ( self::$this_tinymce ) {
                        add_filter( 'the_editor_content', 'format_for_editor', 10, 2 );
                }
 
                /**
-                * Filter the default editor content.
+                * Filters the default editor content.
                 *
                 * @since 2.1.0
                 *
-                * @param string $content Default editor content.
+                * @param string $content        Default editor content.
+                * @param string $default_editor The default editor for the current user.
+                *                               Either 'html' or 'tinymce'.
                 */
                $content = apply_filters( 'the_editor_content', $content, $default_editor );
 
+               // Remove the filter as the next editor on the same page may not need it.
+               if ( self::$this_tinymce ) {
+                       remove_filter( 'the_editor_content', 'format_for_editor' );
+               }
+
                // Back-compat for the `htmledit_pre` and `richedit_pre` filters
                if ( 'html' === $default_editor && has_filter( 'htmledit_pre' ) ) {
                        // TODO: needs _deprecated_filter(), use _deprecated_function() as substitute for now
@@ -297,8 +305,6 @@ final class _WP_Editors {
        public static function editor_settings($editor_id, $set) {
                global $wp_version, $tinymce_version;
 
-               $first_run = false;
-
                if ( empty(self::$first_init) ) {
                        if ( is_admin() ) {
                                add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
@@ -327,7 +333,7 @@ final class _WP_Editors {
                        }
 
                        /**
-                        * Filter the Quicktags settings.
+                        * Filters the Quicktags settings.
                         *
                         * @since 3.3.0
                         *
@@ -351,13 +357,12 @@ final class _WP_Editors {
 
                                /** This filter is documented in wp-admin/includes/media.php */
                                $no_captions = (bool) apply_filters( 'disable_captions', '' );
-                               $first_run = true;
                                $ext_plugins = '';
 
                                if ( $set['teeny'] ) {
 
                                        /**
-                                        * Filter the list of teenyMCE plugins.
+                                        * Filters the list of teenyMCE plugins.
                                         *
                                         * @since 2.7.0
                                         *
@@ -368,7 +373,7 @@ final class _WP_Editors {
                                } else {
 
                                        /**
-                                        * Filter the list of TinyMCE external plugins.
+                                        * Filters the list of TinyMCE external plugins.
                                         *
                                         * The filter takes an associative array of external plugins for
                                         * TinyMCE in the form 'plugin_name' => 'url'.
@@ -404,7 +409,8 @@ final class _WP_Editors {
                                                'wplink',
                                                'wpdialogs',
                                                'wptextpattern',
-                                               'wpview'
+                                               'wpview',
+                                               'wpembed',
                                        );
 
                                        if ( ! self::$has_medialib ) {
@@ -412,7 +418,7 @@ final class _WP_Editors {
                                        }
 
                                        /**
-                                        * Filter the list of default TinyMCE plugins.
+                                        * Filters the list of default TinyMCE plugins.
                                         *
                                         * The filter specifies which of the default plugins included
                                         * in WordPress should be added to the TinyMCE instance.
@@ -432,7 +438,7 @@ final class _WP_Editors {
                                        if ( ! empty( $mce_external_plugins ) ) {
 
                                                /**
-                                                * Filter the translations loaded for external TinyMCE 3.x plugins.
+                                                * Filters the translations loaded for external TinyMCE 3.x plugins.
                                                 *
                                                 * The filter takes an associative array ('plugin_name' => 'path')
                                                 * where 'path' is the include path to the file.
@@ -545,6 +551,7 @@ final class _WP_Editors {
                                        'wpeditimage_disable_captions' => $no_captions,
                                        'wpeditimage_html5_captions' => current_theme_supports( 'html5', 'caption' ),
                                        'plugins' => implode( ',', $plugins ),
+                                       'wp_lang_attr' => get_bloginfo( 'language' )
                                );
 
                                if ( ! empty( $mce_external_plugins ) ) {
@@ -569,11 +576,11 @@ final class _WP_Editors {
                                }
 
                                /**
-                                * Filter the comma-delimited list of stylesheets to load in TinyMCE.
+                                * Filters the comma-delimited list of stylesheets to load in TinyMCE.
                                 *
                                 * @since 2.1.0
                                 *
-                                * @param array $stylesheets Comma-delimited list of stylesheets.
+                                * @param string $stylesheets Comma-delimited list of stylesheets.
                                 */
                                $mce_css = trim( apply_filters( 'mce_css', implode( ',', $mce_css ) ), ' ,' );
 
@@ -584,7 +591,7 @@ final class _WP_Editors {
                        if ( $set['teeny'] ) {
 
                                /**
-                                * Filter the list of teenyMCE buttons (Text tab).
+                                * Filters the list of teenyMCE buttons (Text tab).
                                 *
                                 * @since 2.7.0
                                 *
@@ -596,16 +603,18 @@ final class _WP_Editors {
                        } else {
                                $mce_buttons = array( 'bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker' );
 
-                               if ( $set['_content_editor_dfw'] ) {
-                                       $mce_buttons[] = 'dfw';
-                               } else {
-                                       $mce_buttons[] = 'fullscreen';
+                               if ( ! wp_is_mobile() ) {
+                                       if ( $set['_content_editor_dfw'] ) {
+                                               $mce_buttons[] = 'dfw';
+                                       } else {
+                                               $mce_buttons[] = 'fullscreen';
+                                       }
                                }
 
                                $mce_buttons[] = 'wp_adv';
 
                                /**
-                                * Filter the first-row list of TinyMCE buttons (Visual tab).
+                                * Filters the first-row list of TinyMCE buttons (Visual tab).
                                 *
                                 * @since 2.0.0
                                 *
@@ -621,7 +630,7 @@ final class _WP_Editors {
                                }
 
                                /**
-                                * Filter the second-row list of TinyMCE buttons (Visual tab).
+                                * Filters the second-row list of TinyMCE buttons (Visual tab).
                                 *
                                 * @since 2.0.0
                                 *
@@ -631,7 +640,7 @@ final class _WP_Editors {
                                $mce_buttons_2 = apply_filters( 'mce_buttons_2', $mce_buttons_2, $editor_id );
 
                                /**
-                                * Filter the third-row list of TinyMCE buttons (Visual tab).
+                                * Filters the third-row list of TinyMCE buttons (Visual tab).
                                 *
                                 * @since 2.0.0
                                 *
@@ -641,7 +650,7 @@ final class _WP_Editors {
                                $mce_buttons_3 = apply_filters( 'mce_buttons_3', array(), $editor_id );
 
                                /**
-                                * Filter the fourth-row list of TinyMCE buttons (Visual tab).
+                                * Filters the fourth-row list of TinyMCE buttons (Visual tab).
                                 *
                                 * @since 2.5.0
                                 *
@@ -702,7 +711,7 @@ final class _WP_Editors {
                        if ( $set['teeny'] ) {
 
                                /**
-                                * Filter the teenyMCE config before init.
+                                * Filters the teenyMCE config before init.
                                 *
                                 * @since 2.7.0
                                 *
@@ -713,7 +722,7 @@ final class _WP_Editors {
                        } else {
 
                                /**
-                                * Filter the TinyMCE config before init.
+                                * Filters the TinyMCE config before init.
                                 *
                                 * @since 2.5.0
                                 *
@@ -771,6 +780,7 @@ final class _WP_Editors {
 
                if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {
                        wp_enqueue_script('wplink');
+                       wp_enqueue_script( 'jquery-ui-autocomplete' );
                }
 
                if ( self::$old_dfw_compat ) {
@@ -779,7 +789,8 @@ final class _WP_Editors {
 
                if ( self::$has_medialib ) {
                        add_thickbox();
-                       wp_enqueue_script('media-upload');
+                       wp_enqueue_script( 'media-upload' );
+                       wp_enqueue_script( 'wp-embed' );
                }
 
                /**
@@ -837,7 +848,7 @@ final class _WP_Editors {
                        'Clear formatting' => __( 'Clear formatting' ),
                        'Bold' => __( 'Bold' ),
                        'Italic' => __( 'Italic' ),
-                       'Code' => _x( 'Code', 'editor button' ),
+                       'Code' => __( 'Code' ),
                        'Source code' => __( 'Source code' ),
                        'Font Family' => __( 'Font Family' ),
                        'Font Sizes' => __( 'Font Sizes' ),
@@ -927,7 +938,7 @@ final class _WP_Editors {
 
                        'Color' => __( 'Color' ),
                        'Custom color' => __( 'Custom color' ),
-                       'Custom...' => _x( 'Custom...', 'label for custom color' ),
+                       'Custom...' => _x( 'Custom...', 'label for custom color' ), // no ellipsis
                        'No color' => __( 'No color' ),
 
                        // Spelling, search/replace plugins
@@ -1012,7 +1023,8 @@ final class _WP_Editors {
                        /* translators: word count */
                        'Words: {0}' => sprintf( __( 'Words: %s' ), '{0}' ),
                        '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.' ),
-                       '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' ),
+                       '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.' ),
+                       'Rich Text Area. Press Control-Option-H for help.' => __( 'Rich Text Area. Press Control-Option-H for help.' ),
                        '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.' ),
                        '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.' ),
 
@@ -1029,11 +1041,14 @@ final class _WP_Editors {
                        'Toolbar Toggle' => __( 'Toolbar Toggle' ),
                        'Insert Read More tag' => __( 'Insert Read More tag' ),
                        'Insert Page Break tag' => __( 'Insert Page Break tag' ),
-                       'Read more...' => __( 'Read more...' ), // Title on the placeholder inside the editor
+                       'Read more...' => __( 'Read more...' ), // Title on the placeholder inside the editor (no ellipsis)
                        'Distraction-free writing mode' => __( 'Distraction-free writing mode' ),
                        'No alignment' => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar
                        'Remove' => __( 'Remove' ), // Tooltip for the 'remove' button in the image toolbar
                        'Edit ' => __( 'Edit' ), // Tooltip for the 'edit' button in the image toolbar
+                       'Paste URL or type to search' => __( 'Paste URL or type to search' ), // Placeholder for the inline link dialog
+                       'Apply'  => __( 'Apply' ), // Tooltip for the 'apply' button in the inline link dialog
+                       'Link options'  => __( 'Link options' ), // Tooltip for the 'link options' button in the inline link dialog
 
                        // Shortcuts help modal
                        'Keyboard Shortcuts' => __( 'Keyboard Shortcuts' ),
@@ -1050,12 +1065,15 @@ final class _WP_Editors {
                        'Ctrl + letter:' => __( 'Ctrl + letter:' ),
                        'Letter' => __( 'Letter' ),
                        'Action' => __( 'Action' ),
+                       'Warning: the link has been inserted but may have errors. Please test it.' => __( 'Warning: the link has been inserted but may have errors. Please test it.' ),
                        'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' =>
                                __( 'To move focus to other buttons use Tab or the arrow keys. To return focus to the editor press Escape or use one of the buttons.' ),
                        'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' =>
                                __( 'When starting a new paragraph with one of these formatting shortcuts followed by a space, the formatting will be applied automatically. Press Backspace or Escape to undo.' ),
                        'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' =>
                                __( 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' ),
+                       'The next group of formatting shortcuts are applied as you type or when you insert them around plain text in the same paragraph. Press Escape or the Undo button to undo.' =>
+                               __( 'The next group of formatting shortcuts are applied as you type or when you insert them around plain text in the same paragraph. Press Escape or the Undo button to undo.' ),
                );
 
                /**
@@ -1074,7 +1092,7 @@ final class _WP_Editors {
                }
 
                /**
-                * Filter translated strings prepared for TinyMCE.
+                * Filters translated strings prepared for TinyMCE.
                 *
                 * @since 3.9.0
                 *
@@ -1122,7 +1140,7 @@ final class _WP_Editors {
                global $wp_version, $tinymce_version, $concatenate_scripts, $compress_scripts;
 
                /**
-                * Filter "tiny_mce_version" is deprecated
+                * Filters "tiny_mce_version" is deprecated
                 *
                 * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
                 * These plugins can be refreshed by appending query string to the URL passed to "mce_external_plugins" filter.
@@ -1241,6 +1259,14 @@ final class _WP_Editors {
                        var init, id, $wrap;
 
                        if ( typeof tinymce !== 'undefined' ) {
+                               // Fix RTL
+                               tinymce.on( 'addeditor', function( event ) {
+                                       event.editor.rtl = event.editor.settings.rtl_ui ||
+                                               ( event.editor.editorManager &&
+                                               event.editor.editorManager.i18n &&
+                                               event.editor.editorManager.i18n.rtl );
+                               }, true );
+
                                for ( id in tinyMCEPreInit.mceInit ) {
                                        init = tinyMCEPreInit.mceInit[id];
                                        $wrap = tinymce.$( '#wp-' + id + '-wrap' );
@@ -1268,8 +1294,9 @@ final class _WP_Editors {
                </script>
                <?php
 
-               if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) )
+               if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) ) {
                        self::wp_link_dialog();
+               }
 
                /**
                 * Fires after any core TinyMCE editor instances are created.
@@ -1287,7 +1314,7 @@ final class _WP_Editors {
         * @global int $content_width
         */
        public static function wp_fullscreen_html() {
-               _deprecated_function( __FUNCTION__, '4.3' );
+               _deprecated_function( __FUNCTION__, '4.3.0' );
        }
 
        /**
@@ -1320,7 +1347,7 @@ final class _WP_Editors {
                $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
 
                /**
-                * Filter the link query arguments.
+                * Filters the link query arguments.
                 *
                 * Allows modification of the link query arguments before querying.
                 *
@@ -1356,7 +1383,7 @@ final class _WP_Editors {
                }
 
                /**
-                * Filter the link query results.
+                * Filters the link query results.
                 *
                 * Allows modification of the returned link query results.
                 *
@@ -1388,37 +1415,36 @@ final class _WP_Editors {
         * @static
         */
        public static function wp_link_dialog() {
-               $search_panel_visible = '1' == get_user_setting( 'wplink', '0' ) ? ' search-panel-visible' : '';
-
                // display: none is required here, see #WP27605
                ?>
                <div id="wp-link-backdrop" style="display: none"></div>
-               <div id="wp-link-wrap" class="wp-core-ui<?php echo $search_panel_visible; ?>" style="display: none">
+               <div id="wp-link-wrap" class="wp-core-ui" style="display: none" role="dialog" aria-labelledby="link-modal-title">
                <form id="wp-link" tabindex="-1">
                <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
-               <div id="link-modal-title">
-                       <?php _e( 'Insert/edit link' ) ?>
-                       <button type="button" id="wp-link-close"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
-               </div>
+               <h1 id="link-modal-title"><?php _e( 'Insert/edit link' ) ?></h1>
+               <button type="button" id="wp-link-close"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
                <div id="link-selector">
                        <div id="link-options">
-                               <p class="howto"><?php _e( 'Enter the destination URL' ); ?></p>
+                               <p class="howto" id="wplink-enter-url"><?php _e( 'Enter the destination URL' ); ?></p>
                                <div>
-                                       <label><span><?php _e( 'URL' ); ?></span><input id="wp-link-url" type="text" /></label>
+                                       <label><span><?php _e( 'URL' ); ?></span>
+                                       <input id="wp-link-url" type="text" aria-describedby="wplink-enter-url" /></label>
                                </div>
                                <div class="wp-link-text-field">
-                                       <label><span><?php _e( 'Link Text' ); ?></span><input id="wp-link-text" type="text" /></label>
+                                       <label><span><?php _e( 'Link Text' ); ?></span>
+                                       <input id="wp-link-text" type="text" /></label>
                                </div>
                                <div class="link-target">
-                                       <label><span>&nbsp;</span><input type="checkbox" id="wp-link-target" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
+                                       <label><span></span>
+                                       <input type="checkbox" id="wp-link-target" /> <?php _e( 'Open link in a new tab' ); ?></label>
                                </div>
                        </div>
-                       <p class="howto"><a href="#" id="wp-link-search-toggle"><?php _e( 'Or link to existing content' ); ?></a></p>
+                       <p class="howto" id="wplink-link-existing-content"><?php _e( 'Or link to existing content' ); ?></p>
                        <div id="search-panel">
                                <div class="link-search-wrapper">
                                        <label>
                                                <span class="search-label"><?php _e( 'Search' ); ?></span>
-                                               <input type="search" id="wp-link-search" class="link-search-field" autocomplete="off" />
+                                               <input type="search" id="wp-link-search" class="link-search-field" autocomplete="off" aria-describedby="wplink-link-existing-content" />
                                                <span class="spinner"></span>
                                        </label>
                                </div>
@@ -1437,12 +1463,12 @@ final class _WP_Editors {
                                        <div class="river-waiting">
                                                <span class="spinner"></span>
                                        </div>
-                               </div>
-                       </div>
+                               </div>
+                       </div>
                </div>
                <div class="submitbox">
                        <div id="wp-link-cancel">
-                               <a class="submitdelete deletion" href="#"><?php _e( 'Cancel' ); ?></a>
+                               <button type="button" class="button"><?php _e( 'Cancel' ); ?></button>
                        </div>
                        <div id="wp-link-update">
                                <input type="submit" value="<?php esc_attr_e( 'Add Link' ); ?>" class="button button-primary" id="wp-link-submit" name="wp-link-submit">