]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/class-wp-editor.php
WordPress 4.5
[autoinstalls/wordpress.git] / wp-includes / class-wp-editor.php
1 <?php
2 /**
3  * Facilitates adding of the WordPress editor as used on the Write and Edit screens.
4  *
5  * @package WordPress
6  * @since 3.3.0
7  *
8  * Private, not included by default. See wp_editor() in wp-includes/general-template.php.
9  */
10
11 final class _WP_Editors {
12         public static $mce_locale;
13
14         private static $mce_settings = array();
15         private static $qt_settings = array();
16         private static $plugins = array();
17         private static $qt_buttons = array();
18         private static $ext_plugins;
19         private static $baseurl;
20         private static $first_init;
21         private static $this_tinymce = false;
22         private static $this_quicktags = false;
23         private static $has_tinymce = false;
24         private static $has_quicktags = false;
25         private static $has_medialib = false;
26         private static $editor_buttons_css = true;
27         private static $drag_drop_upload = false;
28         private static $old_dfw_compat = false;
29
30         private function __construct() {}
31
32         /**
33          * Parse default arguments for the editor instance.
34          *
35          * @static
36          * @param string $editor_id ID for the current editor instance.
37          * @param array  $settings {
38          *     Array of editor arguments.
39          *
40          *     @type bool       $wpautop           Whether to use wpautop(). Default true.
41          *     @type bool       $media_buttons     Whether to show the Add Media/other media buttons.
42          *     @type string     $default_editor    When both TinyMCE and Quicktags are used, set which
43          *                                         editor is shown on page load. Default empty.
44          *     @type bool       $drag_drop_upload  Whether to enable drag & drop on the editor uploading. Default false.
45          *                                         Requires the media modal.
46          *     @type string     $textarea_name     Give the textarea a unique name here. Square brackets
47          *                                         can be used here. Default $editor_id.
48          *     @type int        $textarea_rows     Number rows in the editor textarea. Default 20.
49          *     @type string|int $tabindex          Tabindex value to use. Default empty.
50          *     @type string     $tabfocus_elements The previous and next element ID to move the focus to
51          *                                         when pressing the Tab key in TinyMCE. Default ':prev,:next'.
52          *     @type string     $editor_css        Intended for extra styles for both Visual and Text editors.
53          *                                         Should include `<style>` tags, and can use "scoped". Default empty.
54          *     @type string     $editor_class      Extra classes to add to the editor textarea element. Default empty.
55          *     @type bool       $teeny             Whether to output the minimal editor config. Examples include
56          *                                         Press This and the Comment editor. Default false.
57          *     @type bool       $dfw               Deprecated in 4.1. Since 4.3 used only to enqueue wp-fullscreen-stub.js for backwards compatibility.
58          *     @type bool|array $tinymce           Whether to load TinyMCE. Can be used to pass settings directly to
59          *                                         TinyMCE using an array. Default true.
60          *     @type bool|array $quicktags         Whether to load Quicktags. Can be used to pass settings directly to
61          *                                         Quicktags using an array. Default true.
62          * }
63          * @return array Parsed arguments array.
64          */
65         public static function parse_settings( $editor_id, $settings ) {
66
67                 /**
68                  * Filter the wp_editor() settings.
69                  *
70                  * @since 4.0.0
71                  *
72                  * @see _WP_Editors()::parse_settings()
73                  *
74                  * @param array  $settings  Array of editor arguments.
75                  * @param string $editor_id ID for the current editor instance.
76                  */
77                 $settings = apply_filters( 'wp_editor_settings', $settings, $editor_id );
78
79                 $set = wp_parse_args( $settings, array(
80                         'wpautop'             => true,
81                         'media_buttons'       => true,
82                         'default_editor'      => '',
83                         'drag_drop_upload'    => false,
84                         'textarea_name'       => $editor_id,
85                         'textarea_rows'       => 20,
86                         'tabindex'            => '',
87                         'tabfocus_elements'   => ':prev,:next',
88                         'editor_css'          => '',
89                         'editor_class'        => '',
90                         'teeny'               => false,
91                         'dfw'                 => false,
92                         '_content_editor_dfw' => false,
93                         'tinymce'             => true,
94                         'quicktags'           => true
95                 ) );
96
97                 self::$this_tinymce = ( $set['tinymce'] && user_can_richedit() );
98
99                 if ( self::$this_tinymce ) {
100                         if ( false !== strpos( $editor_id, '[' ) ) {
101                                 self::$this_tinymce = false;
102                                 _deprecated_argument( 'wp_editor()', '3.9', 'TinyMCE editor IDs cannot have brackets.' );
103                         }
104                 }
105
106                 self::$this_quicktags = (bool) $set['quicktags'];
107
108                 if ( self::$this_tinymce )
109                         self::$has_tinymce = true;
110
111                 if ( self::$this_quicktags )
112                         self::$has_quicktags = true;
113
114                 if ( $set['dfw'] ) {
115                         self::$old_dfw_compat = true;
116                 }
117
118                 if ( empty( $set['editor_height'] ) )
119                         return $set;
120
121                 if ( 'content' === $editor_id && empty( $set['tinymce']['wp_autoresize_on'] ) ) {
122                         // A cookie (set when a user resizes the editor) overrides the height.
123                         $cookie = (int) get_user_setting( 'ed_size' );
124
125                         if ( $cookie )
126                                 $set['editor_height'] = $cookie;
127                 }
128
129                 if ( $set['editor_height'] < 50 )
130                         $set['editor_height'] = 50;
131                 elseif ( $set['editor_height'] > 5000 )
132                         $set['editor_height'] = 5000;
133
134                 return $set;
135         }
136
137         /**
138          * Outputs the HTML for a single instance of the editor.
139          *
140          * @static
141          * @param string $content The initial content of the editor.
142          * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers).
143          * @param array $settings See the _parse_settings() method for description.
144          */
145         public static function editor( $content, $editor_id, $settings = array() ) {
146                 $set = self::parse_settings( $editor_id, $settings );
147                 $editor_class = ' class="' . trim( esc_attr( $set['editor_class'] ) . ' wp-editor-area' ) . '"';
148                 $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
149                 $default_editor = 'html';
150                 $buttons = $autocomplete = '';
151                 $editor_id_attr = esc_attr( $editor_id );
152
153                 if ( $set['drag_drop_upload'] ) {
154                         self::$drag_drop_upload = true;
155                 }
156
157                 if ( ! empty( $set['editor_height'] ) ) {
158                         $height = ' style="height: ' . (int) $set['editor_height'] . 'px"';
159                 } else {
160                         $height = ' rows="' . (int) $set['textarea_rows'] . '"';
161                 }
162
163                 if ( ! current_user_can( 'upload_files' ) ) {
164                         $set['media_buttons'] = false;
165                 }
166
167                 if ( self::$this_tinymce ) {
168                         $autocomplete = ' autocomplete="off"';
169
170                         if ( self::$this_quicktags ) {
171                                 $default_editor = $set['default_editor'] ? $set['default_editor'] : wp_default_editor();
172                                 // 'html' is used for the "Text" editor tab.
173                                 if ( 'html' !== $default_editor ) {
174                                         $default_editor = 'tinymce';
175                                 }
176
177                                 $buttons .= '<button type="button" id="' . $editor_id_attr . '-tmce" class="wp-switch-editor switch-tmce"' .
178                                         ' data-wp-editor-id="' . $editor_id_attr . '">' . __('Visual') . "</button>\n";
179                                 $buttons .= '<button type="button" id="' . $editor_id_attr . '-html" class="wp-switch-editor switch-html"' .
180                                         ' data-wp-editor-id="' . $editor_id_attr . '">' . _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ) . "</button>\n";
181                         } else {
182                                 $default_editor = 'tinymce';
183                         }
184                 }
185
186                 $switch_class = 'html' === $default_editor ? 'html-active' : 'tmce-active';
187                 $wrap_class = 'wp-core-ui wp-editor-wrap ' . $switch_class;
188
189                 if ( $set['_content_editor_dfw'] ) {
190                         $wrap_class .= ' has-dfw';
191                 }
192
193                 echo '<div id="wp-' . $editor_id_attr . '-wrap" class="' . $wrap_class . '">';
194
195                 if ( self::$editor_buttons_css ) {
196                         wp_print_styles( 'editor-buttons' );
197                         self::$editor_buttons_css = false;
198                 }
199
200                 if ( ! empty( $set['editor_css'] ) ) {
201                         echo $set['editor_css'] . "\n";
202                 }
203
204                 if ( ! empty( $buttons ) || $set['media_buttons'] ) {
205                         echo '<div id="wp-' . $editor_id_attr . '-editor-tools" class="wp-editor-tools hide-if-no-js">';
206
207                         if ( $set['media_buttons'] ) {
208                                 self::$has_medialib = true;
209
210                                 if ( ! function_exists( 'media_buttons' ) )
211                                         include( ABSPATH . 'wp-admin/includes/media.php' );
212
213                                 echo '<div id="wp-' . $editor_id_attr . '-media-buttons" class="wp-media-buttons">';
214
215                                 /**
216                                  * Fires after the default media button(s) are displayed.
217                                  *
218                                  * @since 2.5.0
219                                  *
220                                  * @param string $editor_id Unique editor identifier, e.g. 'content'.
221                                  */
222                                 do_action( 'media_buttons', $editor_id );
223                                 echo "</div>\n";
224                         }
225
226                         echo '<div class="wp-editor-tabs">' . $buttons . "</div>\n";
227                         echo "</div>\n";
228                 }
229
230                 $quicktags_toolbar = '';
231
232                 if ( self::$this_quicktags ) {
233                         if ( 'content' === $editor_id && ! empty( $GLOBALS['current_screen'] ) && $GLOBALS['current_screen']->base === 'post' ) {
234                                 $toolbar_id = 'ed_toolbar';
235                         } else {
236                                 $toolbar_id = 'qt_' . $editor_id_attr . '_toolbar';
237                         }
238
239                         $quicktags_toolbar = '<div id="' . $toolbar_id . '" class="quicktags-toolbar"></div>';
240                 }
241
242                 /**
243                  * Filter the HTML markup output that displays the editor.
244                  *
245                  * @since 2.1.0
246                  *
247                  * @param string $output Editor's HTML markup.
248                  */
249                 $the_editor = apply_filters( 'the_editor', '<div id="wp-' . $editor_id_attr . '-editor-container" class="wp-editor-container">' .
250                         $quicktags_toolbar .
251                         '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . esc_attr( $set['textarea_name'] ) . '" ' .
252                         'id="' . $editor_id_attr . '">%s</textarea></div>' );
253
254                 // Prepare the content for the Visual or Text editor, only when TinyMCE is used (back-compat).
255                 if ( self::$this_tinymce ) {
256                         add_filter( 'the_editor_content', 'format_for_editor', 10, 2 );
257                 }
258
259                 /**
260                  * Filter the default editor content.
261                  *
262                  * @since 2.1.0
263                  *
264                  * @param string $content        Default editor content.
265                  * @param string $default_editor The default editor for the current user.
266                  *                               Either 'html' or 'tinymce'.
267                  */
268                 $content = apply_filters( 'the_editor_content', $content, $default_editor );
269
270                 // Remove the filter as the next editor on the same page may not need it.
271                 if ( self::$this_tinymce ) {
272                         remove_filter( 'the_editor_content', 'format_for_editor' );
273                 }
274
275                 // Back-compat for the `htmledit_pre` and `richedit_pre` filters
276                 if ( 'html' === $default_editor && has_filter( 'htmledit_pre' ) ) {
277                         // TODO: needs _deprecated_filter(), use _deprecated_function() as substitute for now
278                         _deprecated_function( 'add_filter( htmledit_pre )', '4.3.0', 'add_filter( format_for_editor )' );
279                         $content = apply_filters( 'htmledit_pre', $content );
280                 } elseif ( 'tinymce' === $default_editor && has_filter( 'richedit_pre' ) ) {
281                         _deprecated_function( 'add_filter( richedit_pre )', '4.3.0', 'add_filter( format_for_editor )' );
282                         $content = apply_filters( 'richedit_pre', $content );
283                 }
284
285                 if ( false !== stripos( $content, 'textarea' ) ) {
286                         $content = preg_replace( '%</textarea%i', '&lt;/textarea', $content );
287                 }
288
289                 printf( $the_editor, $content );
290                 echo "\n</div>\n\n";
291
292                 self::editor_settings( $editor_id, $set );
293         }
294
295         /**
296          * @static
297          *
298          * @global string $wp_version
299          * @global string $tinymce_version
300          *
301          * @param string $editor_id
302          * @param array  $set
303          */
304         public static function editor_settings($editor_id, $set) {
305                 global $wp_version, $tinymce_version;
306
307                 if ( empty(self::$first_init) ) {
308                         if ( is_admin() ) {
309                                 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
310                                 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
311                         } else {
312                                 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
313                                 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
314                         }
315                 }
316
317                 if ( self::$this_quicktags ) {
318
319                         $qtInit = array(
320                                 'id' => $editor_id,
321                                 'buttons' => ''
322                         );
323
324                         if ( is_array($set['quicktags']) )
325                                 $qtInit = array_merge($qtInit, $set['quicktags']);
326
327                         if ( empty($qtInit['buttons']) )
328                                 $qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close';
329
330                         if ( $set['_content_editor_dfw'] ) {
331                                 $qtInit['buttons'] .= ',dfw';
332                         }
333
334                         /**
335                          * Filter the Quicktags settings.
336                          *
337                          * @since 3.3.0
338                          *
339                          * @param array  $qtInit    Quicktags settings.
340                          * @param string $editor_id The unique editor ID, e.g. 'content'.
341                          */
342                         $qtInit = apply_filters( 'quicktags_settings', $qtInit, $editor_id );
343
344                         self::$qt_settings[$editor_id] = $qtInit;
345
346                         self::$qt_buttons = array_merge( self::$qt_buttons, explode(',', $qtInit['buttons']) );
347                 }
348
349                 if ( self::$this_tinymce ) {
350
351                         if ( empty( self::$first_init ) ) {
352                                 self::$baseurl = includes_url( 'js/tinymce' );
353
354                                 $mce_locale = get_locale();
355                                 self::$mce_locale = $mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1
356
357                                 /** This filter is documented in wp-admin/includes/media.php */
358                                 $no_captions = (bool) apply_filters( 'disable_captions', '' );
359                                 $ext_plugins = '';
360
361                                 if ( $set['teeny'] ) {
362
363                                         /**
364                                          * Filter the list of teenyMCE plugins.
365                                          *
366                                          * @since 2.7.0
367                                          *
368                                          * @param array  $plugins   An array of teenyMCE plugins.
369                                          * @param string $editor_id Unique editor identifier, e.g. 'content'.
370                                          */
371                                         self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array( 'colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink' ), $editor_id );
372                                 } else {
373
374                                         /**
375                                          * Filter the list of TinyMCE external plugins.
376                                          *
377                                          * The filter takes an associative array of external plugins for
378                                          * TinyMCE in the form 'plugin_name' => 'url'.
379                                          *
380                                          * The url should be absolute, and should include the js filename
381                                          * to be loaded. For example:
382                                          * 'myplugin' => 'http://mysite.com/wp-content/plugins/myfolder/mce_plugin.js'.
383                                          *
384                                          * If the external plugin adds a button, it should be added with
385                                          * one of the 'mce_buttons' filters.
386                                          *
387                                          * @since 2.5.0
388                                          *
389                                          * @param array $external_plugins An array of external TinyMCE plugins.
390                                          */
391                                         $mce_external_plugins = apply_filters( 'mce_external_plugins', array() );
392
393                                         $plugins = array(
394                                                 'charmap',
395                                                 'colorpicker',
396                                                 'hr',
397                                                 'lists',
398                                                 'media',
399                                                 'paste',
400                                                 'tabfocus',
401                                                 'textcolor',
402                                                 'fullscreen',
403                                                 'wordpress',
404                                                 'wpautoresize',
405                                                 'wpeditimage',
406                                                 'wpemoji',
407                                                 'wpgallery',
408                                                 'wplink',
409                                                 'wpdialogs',
410                                                 'wptextpattern',
411                                                 'wpview',
412                                                 'wpembed',
413                                         );
414
415                                         if ( ! self::$has_medialib ) {
416                                                 $plugins[] = 'image';
417                                         }
418
419                                         /**
420                                          * Filter the list of default TinyMCE plugins.
421                                          *
422                                          * The filter specifies which of the default plugins included
423                                          * in WordPress should be added to the TinyMCE instance.
424                                          *
425                                          * @since 3.3.0
426                                          *
427                                          * @param array $plugins An array of default TinyMCE plugins.
428                                          */
429                                         $plugins = array_unique( apply_filters( 'tiny_mce_plugins', $plugins ) );
430
431                                         if ( ( $key = array_search( 'spellchecker', $plugins ) ) !== false ) {
432                                                 // Remove 'spellchecker' from the internal plugins if added with 'tiny_mce_plugins' filter to prevent errors.
433                                                 // It can be added with 'mce_external_plugins'.
434                                                 unset( $plugins[$key] );
435                                         }
436
437                                         if ( ! empty( $mce_external_plugins ) ) {
438
439                                                 /**
440                                                  * Filter the translations loaded for external TinyMCE 3.x plugins.
441                                                  *
442                                                  * The filter takes an associative array ('plugin_name' => 'path')
443                                                  * where 'path' is the include path to the file.
444                                                  *
445                                                  * The language file should follow the same format as wp_mce_translation(),
446                                                  * and should define a variable ($strings) that holds all translated strings.
447                                                  *
448                                                  * @since 2.5.0
449                                                  *
450                                                  * @param array $translations Translations for external TinyMCE plugins.
451                                                  */
452                                                 $mce_external_languages = apply_filters( 'mce_external_languages', array() );
453
454                                                 $loaded_langs = array();
455                                                 $strings = '';
456
457                                                 if ( ! empty( $mce_external_languages ) ) {
458                                                         foreach ( $mce_external_languages as $name => $path ) {
459                                                                 if ( @is_file( $path ) && @is_readable( $path ) ) {
460                                                                         include_once( $path );
461                                                                         $ext_plugins .= $strings . "\n";
462                                                                         $loaded_langs[] = $name;
463                                                                 }
464                                                         }
465                                                 }
466
467                                                 foreach ( $mce_external_plugins as $name => $url ) {
468                                                         if ( in_array( $name, $plugins, true ) ) {
469                                                                 unset( $mce_external_plugins[ $name ] );
470                                                                 continue;
471                                                         }
472
473                                                         $url = set_url_scheme( $url );
474                                                         $mce_external_plugins[ $name ] = $url;
475                                                         $plugurl = dirname( $url );
476                                                         $strings = '';
477
478                                                         // Try to load langs/[locale].js and langs/[locale]_dlg.js
479                                                         if ( ! in_array( $name, $loaded_langs, true ) ) {
480                                                                 $path = str_replace( content_url(), '', $plugurl );
481                                                                 $path = WP_CONTENT_DIR . $path . '/langs/';
482
483                                                                 if ( function_exists('realpath') )
484                                                                         $path = trailingslashit( realpath($path) );
485
486                                                                 if ( @is_file( $path . $mce_locale . '.js' ) )
487                                                                         $strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n";
488
489                                                                 if ( @is_file( $path . $mce_locale . '_dlg.js' ) )
490                                                                         $strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n";
491
492                                                                 if ( 'en' != $mce_locale && empty( $strings ) ) {
493                                                                         if ( @is_file( $path . 'en.js' ) ) {
494                                                                                 $str1 = @file_get_contents( $path . 'en.js' );
495                                                                                 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
496                                                                         }
497
498                                                                         if ( @is_file( $path . 'en_dlg.js' ) ) {
499                                                                                 $str2 = @file_get_contents( $path . 'en_dlg.js' );
500                                                                                 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";
501                                                                         }
502                                                                 }
503
504                                                                 if ( ! empty( $strings ) )
505                                                                         $ext_plugins .= "\n" . $strings . "\n";
506                                                         }
507
508                                                         $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
509                                                         $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
510                                                 }
511                                         }
512                                 }
513
514                                 self::$plugins = $plugins;
515                                 self::$ext_plugins = $ext_plugins;
516
517                                 self::$first_init = array(
518                                         'theme' => 'modern',
519                                         'skin' => 'lightgray',
520                                         'language' => self::$mce_locale,
521                                         'formats' => '{' .
522                                                 'alignleft: [' .
523                                                         '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"left"}},' .
524                                                         '{selector: "img,table,dl.wp-caption", classes: "alignleft"}' .
525                                                 '],' .
526                                                 'aligncenter: [' .
527                                                         '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"center"}},' .
528                                                         '{selector: "img,table,dl.wp-caption", classes: "aligncenter"}' .
529                                                 '],' .
530                                                 'alignright: [' .
531                                                         '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"right"}},' .
532                                                         '{selector: "img,table,dl.wp-caption", classes: "alignright"}' .
533                                                 '],' .
534                                                 'strikethrough: {inline: "del"}' .
535                                         '}',
536                                         'relative_urls' => false,
537                                         'remove_script_host' => false,
538                                         'convert_urls' => false,
539                                         'browser_spellcheck' => true,
540                                         'fix_list_elements' => true,
541                                         'entities' => '38,amp,60,lt,62,gt',
542                                         'entity_encoding' => 'raw',
543                                         'keep_styles' => false,
544                                         'cache_suffix' => 'wp-mce-' . $tinymce_version,
545
546                                         // Limit the preview styles in the menu/toolbar
547                                         'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform',
548
549                                         'end_container_on_empty_block' => true,
550                                         'wpeditimage_disable_captions' => $no_captions,
551                                         'wpeditimage_html5_captions' => current_theme_supports( 'html5', 'caption' ),
552                                         'plugins' => implode( ',', $plugins ),
553                                         'wp_lang_attr' => get_bloginfo( 'language' )
554                                 );
555
556                                 if ( ! empty( $mce_external_plugins ) ) {
557                                         self::$first_init['external_plugins'] = wp_json_encode( $mce_external_plugins );
558                                 }
559
560                                 $suffix = SCRIPT_DEBUG ? '' : '.min';
561                                 $version = 'ver=' . $wp_version;
562                                 $dashicons = includes_url( "css/dashicons$suffix.css?$version" );
563
564                                 // WordPress default stylesheet and dashicons
565                                 $mce_css = array(
566                                         $dashicons,
567                                         self::$baseurl . '/skins/wordpress/wp-content.css?' . $version
568                                 );
569
570                                 $editor_styles = get_editor_stylesheets();
571                                 if ( ! empty( $editor_styles ) ) {
572                                         foreach ( $editor_styles as $style ) {
573                                                 $mce_css[] = $style;
574                                         }
575                                 }
576
577                                 /**
578                                  * Filter the comma-delimited list of stylesheets to load in TinyMCE.
579                                  *
580                                  * @since 2.1.0
581                                  *
582                                  * @param string $stylesheets Comma-delimited list of stylesheets.
583                                  */
584                                 $mce_css = trim( apply_filters( 'mce_css', implode( ',', $mce_css ) ), ' ,' );
585
586                                 if ( ! empty($mce_css) )
587                                         self::$first_init['content_css'] = $mce_css;
588                         }
589
590                         if ( $set['teeny'] ) {
591
592                                 /**
593                                  * Filter the list of teenyMCE buttons (Text tab).
594                                  *
595                                  * @since 2.7.0
596                                  *
597                                  * @param array  $buttons   An array of teenyMCE buttons.
598                                  * @param string $editor_id Unique editor identifier, e.g. 'content'.
599                                  */
600                                 $mce_buttons = apply_filters( 'teeny_mce_buttons', array('bold', 'italic', 'underline', 'blockquote', 'strikethrough', 'bullist', 'numlist', 'alignleft', 'aligncenter', 'alignright', 'undo', 'redo', 'link', 'unlink', 'fullscreen'), $editor_id );
601                                 $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
602                         } else {
603                                 $mce_buttons = array( 'bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker' );
604
605                                 if ( ! wp_is_mobile() ) {
606                                         if ( $set['_content_editor_dfw'] ) {
607                                                 $mce_buttons[] = 'dfw';
608                                         } else {
609                                                 $mce_buttons[] = 'fullscreen';
610                                         }
611                                 }
612
613                                 $mce_buttons[] = 'wp_adv';
614
615                                 /**
616                                  * Filter the first-row list of TinyMCE buttons (Visual tab).
617                                  *
618                                  * @since 2.0.0
619                                  *
620                                  * @param array  $buttons   First-row list of buttons.
621                                  * @param string $editor_id Unique editor identifier, e.g. 'content'.
622                                  */
623                                 $mce_buttons = apply_filters( 'mce_buttons', $mce_buttons, $editor_id );
624
625                                 $mce_buttons_2 = array( 'formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo' );
626
627                                 if ( ! wp_is_mobile() ) {
628                                         $mce_buttons_2[] = 'wp_help';
629                                 }
630
631                                 /**
632                                  * Filter the second-row list of TinyMCE buttons (Visual tab).
633                                  *
634                                  * @since 2.0.0
635                                  *
636                                  * @param array  $buttons   Second-row list of buttons.
637                                  * @param string $editor_id Unique editor identifier, e.g. 'content'.
638                                  */
639                                 $mce_buttons_2 = apply_filters( 'mce_buttons_2', $mce_buttons_2, $editor_id );
640
641                                 /**
642                                  * Filter the third-row list of TinyMCE buttons (Visual tab).
643                                  *
644                                  * @since 2.0.0
645                                  *
646                                  * @param array  $buttons   Third-row list of buttons.
647                                  * @param string $editor_id Unique editor identifier, e.g. 'content'.
648                                  */
649                                 $mce_buttons_3 = apply_filters( 'mce_buttons_3', array(), $editor_id );
650
651                                 /**
652                                  * Filter the fourth-row list of TinyMCE buttons (Visual tab).
653                                  *
654                                  * @since 2.5.0
655                                  *
656                                  * @param array  $buttons   Fourth-row list of buttons.
657                                  * @param string $editor_id Unique editor identifier, e.g. 'content'.
658                                  */
659                                 $mce_buttons_4 = apply_filters( 'mce_buttons_4', array(), $editor_id );
660                         }
661
662                         $body_class = $editor_id;
663
664                         if ( $post = get_post() ) {
665                                 $body_class .= ' post-type-' . sanitize_html_class( $post->post_type ) . ' post-status-' . sanitize_html_class( $post->post_status );
666                                 if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
667                                         $post_format = get_post_format( $post );
668                                         if ( $post_format && ! is_wp_error( $post_format ) )
669                                                 $body_class .= ' post-format-' . sanitize_html_class( $post_format );
670                                         else
671                                                 $body_class .= ' post-format-standard';
672                                 }
673                         }
674
675                         $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
676
677                         if ( !empty($set['tinymce']['body_class']) ) {
678                                 $body_class .= ' ' . $set['tinymce']['body_class'];
679                                 unset($set['tinymce']['body_class']);
680                         }
681
682                         $mceInit = array (
683                                 'selector' => "#$editor_id",
684                                 'resize' => 'vertical',
685                                 'menubar' => false,
686                                 'wpautop' => (bool) $set['wpautop'],
687                                 'indent' => ! $set['wpautop'],
688                                 'toolbar1' => implode($mce_buttons, ','),
689                                 'toolbar2' => implode($mce_buttons_2, ','),
690                                 'toolbar3' => implode($mce_buttons_3, ','),
691                                 'toolbar4' => implode($mce_buttons_4, ','),
692                                 'tabfocus_elements' => $set['tabfocus_elements'],
693                                 'body_class' => $body_class
694                         );
695
696                         // Merge with the first part of the init array
697                         $mceInit = array_merge( self::$first_init, $mceInit );
698
699                         if ( is_array( $set['tinymce'] ) )
700                                 $mceInit = array_merge( $mceInit, $set['tinymce'] );
701
702                         /*
703                          * For people who really REALLY know what they're doing with TinyMCE
704                          * You can modify $mceInit to add, remove, change elements of the config
705                          * before tinyMCE.init. Setting "valid_elements", "invalid_elements"
706                          * and "extended_valid_elements" can be done through this filter. Best
707                          * is to use the default cleanup by not specifying valid_elements,
708                          * as TinyMCE checks against the full set of HTML 5.0 elements and attributes.
709                          */
710                         if ( $set['teeny'] ) {
711
712                                 /**
713                                  * Filter the teenyMCE config before init.
714                                  *
715                                  * @since 2.7.0
716                                  *
717                                  * @param array  $mceInit   An array with teenyMCE config.
718                                  * @param string $editor_id Unique editor identifier, e.g. 'content'.
719                                  */
720                                 $mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
721                         } else {
722
723                                 /**
724                                  * Filter the TinyMCE config before init.
725                                  *
726                                  * @since 2.5.0
727                                  *
728                                  * @param array  $mceInit   An array with TinyMCE config.
729                                  * @param string $editor_id Unique editor identifier, e.g. 'content'.
730                                  */
731                                 $mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );
732                         }
733
734                         if ( empty( $mceInit['toolbar3'] ) && ! empty( $mceInit['toolbar4'] ) ) {
735                                 $mceInit['toolbar3'] = $mceInit['toolbar4'];
736                                 $mceInit['toolbar4'] = '';
737                         }
738
739                         self::$mce_settings[$editor_id] = $mceInit;
740                 } // end if self::$this_tinymce
741         }
742
743         /**
744          *
745          * @static
746          * @param array $init
747          * @return string
748          */
749         private static function _parse_init($init) {
750                 $options = '';
751
752                 foreach ( $init as $k => $v ) {
753                         if ( is_bool($v) ) {
754                                 $val = $v ? 'true' : 'false';
755                                 $options .= $k . ':' . $val . ',';
756                                 continue;
757                         } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {
758                                 $options .= $k . ':' . $v . ',';
759                                 continue;
760                         }
761                         $options .= $k . ':"' . $v . '",';
762                 }
763
764                 return '{' . trim( $options, ' ,' ) . '}';
765         }
766
767         /**
768          *
769          * @static
770          */
771         public static function enqueue_scripts() {
772                 if ( self::$has_tinymce )
773                         wp_enqueue_script('editor');
774
775                 if ( self::$has_quicktags ) {
776                         wp_enqueue_script( 'quicktags' );
777                         wp_enqueue_style( 'buttons' );
778                 }
779
780                 if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {
781                         wp_enqueue_script('wplink');
782                         wp_enqueue_script( 'jquery-ui-autocomplete' );
783                 }
784
785                 if ( self::$old_dfw_compat ) {
786                         wp_enqueue_script('wp-fullscreen-stub');
787                 }
788
789                 if ( self::$has_medialib ) {
790                         add_thickbox();
791                         wp_enqueue_script('media-upload');
792                 }
793
794                 /**
795                  * Fires when scripts and styles are enqueued for the editor.
796                  *
797                  * @since 3.9.0
798                  *
799                  * @param array $to_load An array containing boolean values whether TinyMCE
800                  *                       and Quicktags are being loaded.
801                  */
802                 do_action( 'wp_enqueue_editor', array(
803                         'tinymce'   => self::$has_tinymce,
804                         'quicktags' => self::$has_quicktags,
805                 ) );
806         }
807
808         /**
809          * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
810          * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
811          *
812          * @static
813          * @param string $mce_locale The locale used for the editor.
814          * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
815          * @return string Translation object, JSON encoded.
816          */
817         public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
818
819                 $mce_translation = array(
820                         // Default TinyMCE strings
821                         'New document' => __( 'New document' ),
822                         'Formats' => _x( 'Formats', 'TinyMCE' ),
823
824                         'Headings' => _x( 'Headings', 'TinyMCE' ),
825                         'Heading 1' => __( 'Heading 1' ),
826                         'Heading 2' => __( 'Heading 2' ),
827                         'Heading 3' => __( 'Heading 3' ),
828                         'Heading 4' => __( 'Heading 4' ),
829                         'Heading 5' => __( 'Heading 5' ),
830                         'Heading 6' => __( 'Heading 6' ),
831
832                         /* translators: block tags */
833                         'Blocks' => _x( 'Blocks', 'TinyMCE' ),
834                         'Paragraph' => __( 'Paragraph' ),
835                         'Blockquote' => __( 'Blockquote' ),
836                         'Div' => _x( 'Div', 'HTML tag' ),
837                         'Pre' => _x( 'Pre', 'HTML tag' ),
838                         'Preformatted' => _x( 'Preformatted', 'HTML tag' ),
839                         'Address' => _x( 'Address', 'HTML tag' ),
840
841                         'Inline' => _x( 'Inline', 'HTML elements' ),
842                         'Underline' => __( 'Underline' ),
843                         'Strikethrough' => __( 'Strikethrough' ),
844                         'Subscript' => __( 'Subscript' ),
845                         'Superscript' => __( 'Superscript' ),
846                         'Clear formatting' => __( 'Clear formatting' ),
847                         'Bold' => __( 'Bold' ),
848                         'Italic' => __( 'Italic' ),
849                         'Code' => _x( 'Code', 'editor button' ),
850                         'Source code' => __( 'Source code' ),
851                         'Font Family' => __( 'Font Family' ),
852                         'Font Sizes' => __( 'Font Sizes' ),
853
854                         'Align center' => __( 'Align center' ),
855                         'Align right' => __( 'Align right' ),
856                         'Align left' => __( 'Align left' ),
857                         'Justify' => __( 'Justify' ),
858                         'Increase indent' => __( 'Increase indent' ),
859                         'Decrease indent' => __( 'Decrease indent' ),
860
861                         'Cut' => __( 'Cut' ),
862                         'Copy' => __( 'Copy' ),
863                         'Paste' => __( 'Paste' ),
864                         'Select all' => __( 'Select all' ),
865                         'Undo' => __( 'Undo' ),
866                         'Redo' => __( 'Redo' ),
867
868                         'Ok' => __( 'OK' ),
869                         'Cancel' => __( 'Cancel' ),
870                         'Close' => __( 'Close' ),
871                         'Visual aids' => __( 'Visual aids' ),
872
873                         'Bullet list' => __( 'Bulleted list' ),
874                         'Numbered list' => __( 'Numbered list' ),
875                         'Square' => _x( 'Square', 'list style' ),
876                         'Default' => _x( 'Default', 'list style' ),
877                         'Circle' => _x( 'Circle', 'list style' ),
878                         'Disc' => _x('Disc', 'list style' ),
879                         'Lower Greek' => _x( 'Lower Greek', 'list style' ),
880                         'Lower Alpha' => _x( 'Lower Alpha', 'list style' ),
881                         'Upper Alpha' => _x( 'Upper Alpha', 'list style' ),
882                         'Upper Roman' => _x( 'Upper Roman', 'list style' ),
883                         'Lower Roman' => _x( 'Lower Roman', 'list style' ),
884
885                         // Anchor plugin
886                         'Name' => _x( 'Name', 'Name of link anchor (TinyMCE)' ),
887                         'Anchor' => _x( 'Anchor', 'Link anchor (TinyMCE)' ),
888                         'Anchors' => _x( 'Anchors', 'Link anchors (TinyMCE)' ),
889
890                         // Fullpage plugin
891                         'Document properties' => __( 'Document properties' ),
892                         'Robots' => __( 'Robots' ),
893                         'Title' => __( 'Title' ),
894                         'Keywords' => __( 'Keywords' ),
895                         'Encoding' => __( 'Encoding' ),
896                         'Description' => __( 'Description' ),
897                         'Author' => __( 'Author' ),
898
899                         // Media, image plugins
900                         'Insert/edit image' => __( 'Insert/edit image' ),
901                         'General' => __( 'General' ),
902                         'Advanced' => __( 'Advanced' ),
903                         'Source' => __( 'Source' ),
904                         'Border' => __( 'Border' ),
905                         'Constrain proportions' => __( 'Constrain proportions' ),
906                         'Vertical space' => __( 'Vertical space' ),
907                         'Image description' => __( 'Image description' ),
908                         'Style' => __( 'Style' ),
909                         'Dimensions' => __( 'Dimensions' ),
910                         'Insert image' => __( 'Insert image' ),
911                         'Insert date/time' => __( 'Insert date/time' ),
912                         'Insert/edit video' => __( 'Insert/edit video' ),
913                         'Poster' => __( 'Poster' ),
914                         'Alternative source' => __( 'Alternative source' ),
915                         'Paste your embed code below:' => __( 'Paste your embed code below:' ),
916                         'Insert video' => __( 'Insert video' ),
917                         'Embed' => __( 'Embed' ),
918
919                         // Each of these have a corresponding plugin
920                         'Special character' => __( 'Special character' ),
921                         'Right to left' => _x( 'Right to left', 'editor button' ),
922                         'Left to right' => _x( 'Left to right', 'editor button' ),
923                         'Emoticons' => __( 'Emoticons' ),
924                         'Nonbreaking space' => __( 'Nonbreaking space' ),
925                         'Page break' => __( 'Page break' ),
926                         'Paste as text' => __( 'Paste as text' ),
927                         'Preview' => __( 'Preview' ),
928                         'Print' => __( 'Print' ),
929                         'Save' => __( 'Save' ),
930                         'Fullscreen' => __( 'Fullscreen' ),
931                         'Horizontal line' => __( 'Horizontal line' ),
932                         'Horizontal space' => __( 'Horizontal space' ),
933                         'Restore last draft' => __( 'Restore last draft' ),
934                         'Insert/edit link' => __( 'Insert/edit link' ),
935                         'Remove link' => __( 'Remove link' ),
936
937                         'Color' => __( 'Color' ),
938                         'Custom color' => __( 'Custom color' ),
939                         'Custom...' => _x( 'Custom...', 'label for custom color' ), // no ellipsis
940                         'No color' => __( 'No color' ),
941
942                         // Spelling, search/replace plugins
943                         'Could not find the specified string.' => __( 'Could not find the specified string.' ),
944                         'Replace' => _x( 'Replace', 'find/replace' ),
945                         'Next' => _x( 'Next', 'find/replace' ),
946                         /* translators: previous */
947                         'Prev' => _x( 'Prev', 'find/replace' ),
948                         'Whole words' => _x( 'Whole words', 'find/replace' ),
949                         'Find and replace' => __( 'Find and replace' ),
950                         'Replace with' => _x('Replace with', 'find/replace' ),
951                         'Find' => _x( 'Find', 'find/replace' ),
952                         'Replace all' => _x( 'Replace all', 'find/replace' ),
953                         'Match case' => __( 'Match case' ),
954                         'Spellcheck' => __( 'Check Spelling' ),
955                         'Finish' => _x( 'Finish', 'spellcheck' ),
956                         'Ignore all' => _x( 'Ignore all', 'spellcheck' ),
957                         'Ignore' => _x( 'Ignore', 'spellcheck' ),
958                         'Add to Dictionary' => __( 'Add to Dictionary' ),
959
960                         // TinyMCE tables
961                         'Insert table' => __( 'Insert table' ),
962                         'Delete table' => __( 'Delete table' ),
963                         'Table properties' => __( 'Table properties' ),
964                         'Row properties' => __( 'Table row properties' ),
965                         'Cell properties' => __( 'Table cell properties' ),
966                         'Border color' => __( 'Border color' ),
967
968                         'Row' => __( 'Row' ),
969                         'Rows' => __( 'Rows' ),
970                         'Column' => _x( 'Column', 'table column' ),
971                         'Cols' => _x( 'Cols', 'table columns' ),
972                         'Cell' => _x( 'Cell', 'table cell' ),
973                         'Header cell' => __( 'Header cell' ),
974                         'Header' => _x( 'Header', 'table header' ),
975                         'Body' => _x( 'Body', 'table body' ),
976                         'Footer' => _x( 'Footer', 'table footer' ),
977
978                         'Insert row before' => __( 'Insert row before' ),
979                         'Insert row after' => __( 'Insert row after' ),
980                         'Insert column before' => __( 'Insert column before' ),
981                         'Insert column after' => __( 'Insert column after' ),
982                         'Paste row before' => __( 'Paste table row before' ),
983                         'Paste row after' => __( 'Paste table row after' ),
984                         'Delete row' => __( 'Delete row' ),
985                         'Delete column' => __( 'Delete column' ),
986                         'Cut row' => __( 'Cut table row' ),
987                         'Copy row' => __( 'Copy table row' ),
988                         'Merge cells' => __( 'Merge table cells' ),
989                         'Split cell' => __( 'Split table cell' ),
990
991                         'Height' => __( 'Height' ),
992                         'Width' => __( 'Width' ),
993                         'Caption' => __( 'Caption' ),
994                         'Alignment' => __( 'Alignment' ),
995                         'H Align' => _x( 'H Align', 'horizontal table cell alignment' ),
996                         'Left' => __( 'Left' ),
997                         'Center' => __( 'Center' ),
998                         'Right' => __( 'Right' ),
999                         'None' => _x( 'None', 'table cell alignment attribute' ),
1000                         'V Align' => _x( 'V Align', 'vertical table cell alignment' ),
1001                         'Top' => __( 'Top' ),
1002                         'Middle' => __( 'Middle' ),
1003                         'Bottom' => __( 'Bottom' ),
1004
1005                         'Row group' => __( 'Row group' ),
1006                         'Column group' => __( 'Column group' ),
1007                         'Row type' => __( 'Row type' ),
1008                         'Cell type' => __( 'Cell type' ),
1009                         'Cell padding' => __( 'Cell padding' ),
1010                         'Cell spacing' => __( 'Cell spacing' ),
1011                         'Scope' => _x( 'Scope', 'table cell scope attribute' ),
1012
1013                         'Insert template' => _x( 'Insert template', 'TinyMCE' ),
1014                         'Templates' => _x( 'Templates', 'TinyMCE' ),
1015
1016                         'Background color' => __( 'Background color' ),
1017                         'Text color' => __( 'Text color' ),
1018                         'Show blocks' => _x( 'Show blocks', 'editor button' ),
1019                         'Show invisible characters' => __( 'Show invisible characters' ),
1020
1021                         /* translators: word count */
1022                         'Words: {0}' => sprintf( __( 'Words: %s' ), '{0}' ),
1023                         '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.' ),
1024                         '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' ),
1025                         '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.' ),
1026                         '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.' ),
1027
1028                         // TinyMCE menus
1029                         'Insert' => _x( 'Insert', 'TinyMCE menu' ),
1030                         'File' => _x( 'File', 'TinyMCE menu' ),
1031                         'Edit' => _x( 'Edit', 'TinyMCE menu' ),
1032                         'Tools' => _x( 'Tools', 'TinyMCE menu' ),
1033                         'View' => _x( 'View', 'TinyMCE menu' ),
1034                         'Table' => _x( 'Table', 'TinyMCE menu' ),
1035                         'Format' => _x( 'Format', 'TinyMCE menu' ),
1036
1037                         // WordPress strings
1038                         'Toolbar Toggle' => __( 'Toolbar Toggle' ),
1039                         'Insert Read More tag' => __( 'Insert Read More tag' ),
1040                         'Insert Page Break tag' => __( 'Insert Page Break tag' ),
1041                         'Read more...' => __( 'Read more...' ), // Title on the placeholder inside the editor (no ellipsis)
1042                         'Distraction-free writing mode' => __( 'Distraction-free writing mode' ),
1043                         'No alignment' => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar
1044                         'Remove' => __( 'Remove' ), // Tooltip for the 'remove' button in the image toolbar
1045                         'Edit ' => __( 'Edit' ), // Tooltip for the 'edit' button in the image toolbar
1046                         'Paste URL or type to search' => __( 'Paste URL or type to search' ), // Placeholder for the inline link dialog
1047                         'Apply'  => __( 'Apply' ), // Tooltip for the 'apply' button in the inline link dialog
1048                         'Link options'  => __( 'Link options' ), // Tooltip for the 'link options' button in the inline link dialog
1049
1050                         // Shortcuts help modal
1051                         'Keyboard Shortcuts' => __( 'Keyboard Shortcuts' ),
1052                         'Default shortcuts,' => __( 'Default shortcuts,' ),
1053                         'Additional shortcuts,' => __( 'Additional shortcuts,' ),
1054                         'Focus shortcuts:' => __( 'Focus shortcuts:' ),
1055                         'Inline toolbar (when an image, link or preview is selected)' => __( 'Inline toolbar (when an image, link or preview is selected)' ),
1056                         'Editor menu (when enabled)' => __( 'Editor menu (when enabled)' ),
1057                         'Editor toolbar' => __( 'Editor toolbar' ),
1058                         'Elements path' => __( 'Elements path' ),
1059                         'Ctrl + Alt + letter:' => __( 'Ctrl + Alt + letter:' ),
1060                         'Shift + Alt + letter:' => __( 'Shift + Alt + letter:' ),
1061                         'Cmd + letter:' => __( 'Cmd + letter:' ),
1062                         'Ctrl + letter:' => __( 'Ctrl + letter:' ),
1063                         'Letter' => __( 'Letter' ),
1064                         'Action' => __( 'Action' ),
1065                         '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.' =>
1066                                 __( '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.' ),
1067                         '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.' =>
1068                                 __( '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.' ),
1069                         'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' =>
1070                                 __( 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' ),
1071                         '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.' =>
1072                                 __( '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.' ),
1073                 );
1074
1075                 /**
1076                  * Link plugin (not included):
1077                  *      Insert link
1078                  *      Target
1079                  *      New window
1080                  *      Text to display
1081                  *      The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?
1082                  *      The URL you entered seems to be an external link. Do you want to add the required http:\/\/ prefix?
1083                  *      Url
1084                  */
1085
1086                 if ( ! $mce_locale ) {
1087                         $mce_locale = self::$mce_locale;
1088                 }
1089
1090                 /**
1091                  * Filter translated strings prepared for TinyMCE.
1092                  *
1093                  * @since 3.9.0
1094                  *
1095                  * @param array  $mce_translation Key/value pairs of strings.
1096                  * @param string $mce_locale      Locale.
1097                  */
1098                 $mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale );
1099
1100                 foreach ( $mce_translation as $key => $value ) {
1101                         // Remove strings that are not translated.
1102                         if ( $key === $value ) {
1103                                 unset( $mce_translation[$key] );
1104                                 continue;
1105                         }
1106
1107                         if ( false !== strpos( $value, '&' ) ) {
1108                                 $mce_translation[$key] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
1109                         }
1110                 }
1111
1112                 // Set direction
1113                 if ( is_rtl() ) {
1114                         $mce_translation['_dir'] = 'rtl';
1115                 }
1116
1117                 if ( $json_only ) {
1118                         return wp_json_encode( $mce_translation );
1119                 }
1120
1121                 $baseurl = self::$baseurl ? self::$baseurl : includes_url( 'js/tinymce' );
1122
1123                 return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
1124                         "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
1125         }
1126
1127         /**
1128          *
1129          * @static
1130          * @global string $wp_version
1131          * @global string $tinymce_version
1132          * @global bool   $concatenate_scripts
1133          * @global bool   $compress_scripts
1134          */
1135         public static function editor_js() {
1136                 global $wp_version, $tinymce_version, $concatenate_scripts, $compress_scripts;
1137
1138                 /**
1139                  * Filter "tiny_mce_version" is deprecated
1140                  *
1141                  * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
1142                  * These plugins can be refreshed by appending query string to the URL passed to "mce_external_plugins" filter.
1143                  * 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).
1144                  */
1145                 $version = 'ver=' . $tinymce_version;
1146                 $tmce_on = !empty(self::$mce_settings);
1147
1148                 if ( ! isset($concatenate_scripts) )
1149                         script_concat_settings();
1150
1151                 $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
1152                         && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
1153
1154                 $mceInit = $qtInit = '';
1155                 if ( $tmce_on ) {
1156                         foreach ( self::$mce_settings as $editor_id => $init ) {
1157                                 $options = self::_parse_init( $init );
1158                                 $mceInit .= "'$editor_id':{$options},";
1159                         }
1160                         $mceInit = '{' . trim($mceInit, ',') . '}';
1161                 } else {
1162                         $mceInit = '{}';
1163                 }
1164
1165                 if ( !empty(self::$qt_settings) ) {
1166                         foreach ( self::$qt_settings as $editor_id => $init ) {
1167                                 $options = self::_parse_init( $init );
1168                                 $qtInit .= "'$editor_id':{$options},";
1169                         }
1170                         $qtInit = '{' . trim($qtInit, ',') . '}';
1171                 } else {
1172                         $qtInit = '{}';
1173                 }
1174
1175                 $ref = array(
1176                         'plugins' => implode( ',', self::$plugins ),
1177                         'theme' => 'modern',
1178                         'language' => self::$mce_locale
1179                 );
1180
1181                 $suffix = SCRIPT_DEBUG ? '' : '.min';
1182
1183                 /**
1184                  * Fires immediately before the TinyMCE settings are printed.
1185                  *
1186                  * @since 3.2.0
1187                  *
1188                  * @param array $mce_settings TinyMCE settings array.
1189                  */
1190                 do_action( 'before_wp_tiny_mce', self::$mce_settings );
1191                 ?>
1192
1193                 <script type="text/javascript">
1194                 tinyMCEPreInit = {
1195                         baseURL: "<?php echo self::$baseurl; ?>",
1196                         suffix: "<?php echo $suffix; ?>",
1197                         <?php
1198
1199                         if ( self::$drag_drop_upload ) {
1200                                 echo 'dragDropUpload: true,';
1201                         }
1202
1203                         ?>
1204                         mceInit: <?php echo $mceInit; ?>,
1205                         qtInit: <?php echo $qtInit; ?>,
1206                         ref: <?php echo self::_parse_init( $ref ); ?>,
1207                         load_ext: function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
1208                 };
1209                 </script>
1210                 <?php
1211
1212                 $baseurl = self::$baseurl;
1213                 // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG)
1214                 $mce_suffix = false !== strpos( $wp_version, '-src' ) ? '' : '.min';
1215
1216                 if ( $tmce_on ) {
1217                         if ( $compressed ) {
1218                                 echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&amp;$version'></script>\n";
1219                         } else {
1220                                 echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n";
1221                                 echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n";
1222                         }
1223
1224                         echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";
1225
1226                         if ( self::$ext_plugins ) {
1227                                 // Load the old-format English strings to prevent unsightly labels in old style popups
1228                                 echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
1229                         }
1230                 }
1231
1232                 /**
1233                  * Fires after tinymce.js is loaded, but before any TinyMCE editor
1234                  * instances are created.
1235                  *
1236                  * @since 3.9.0
1237                  *
1238                  * @param array $mce_settings TinyMCE settings array.
1239                  */
1240                 do_action( 'wp_tiny_mce_init', self::$mce_settings );
1241
1242                 ?>
1243                 <script type="text/javascript">
1244                 <?php
1245
1246                 if ( self::$ext_plugins )
1247                         echo self::$ext_plugins . "\n";
1248
1249                 if ( ! is_admin() )
1250                         echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
1251
1252                 ?>
1253
1254                 ( function() {
1255                         var init, id, $wrap;
1256
1257                         if ( typeof tinymce !== 'undefined' ) {
1258                                 for ( id in tinyMCEPreInit.mceInit ) {
1259                                         init = tinyMCEPreInit.mceInit[id];
1260                                         $wrap = tinymce.$( '#wp-' + id + '-wrap' );
1261
1262                                         if ( ( $wrap.hasClass( 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( id ) ) && ! init.wp_skip_init ) {
1263                                                 tinymce.init( init );
1264
1265                                                 if ( ! window.wpActiveEditor ) {
1266                                                         window.wpActiveEditor = id;
1267                                                 }
1268                                         }
1269                                 }
1270                         }
1271
1272                         if ( typeof quicktags !== 'undefined' ) {
1273                                 for ( id in tinyMCEPreInit.qtInit ) {
1274                                         quicktags( tinyMCEPreInit.qtInit[id] );
1275
1276                                         if ( ! window.wpActiveEditor ) {
1277                                                 window.wpActiveEditor = id;
1278                                         }
1279                                 }
1280                         }
1281                 }());
1282                 </script>
1283                 <?php
1284
1285                 if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) )
1286                         self::wp_link_dialog();
1287
1288                 /**
1289                  * Fires after any core TinyMCE editor instances are created.
1290                  *
1291                  * @since 3.2.0
1292                  *
1293                  * @param array $mce_settings TinyMCE settings array.
1294                  */
1295                 do_action( 'after_wp_tiny_mce', self::$mce_settings );
1296         }
1297
1298         /**
1299          *
1300          * @static
1301          * @global int $content_width
1302          */
1303         public static function wp_fullscreen_html() {
1304                 _deprecated_function( __FUNCTION__, '4.3' );
1305         }
1306
1307         /**
1308          * Performs post queries for internal linking.
1309          *
1310          * @since 3.1.0
1311          *
1312          * @static
1313          * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
1314          * @return false|array Results.
1315          */
1316         public static function wp_link_query( $args = array() ) {
1317                 $pts = get_post_types( array( 'public' => true ), 'objects' );
1318                 $pt_names = array_keys( $pts );
1319
1320                 $query = array(
1321                         'post_type' => $pt_names,
1322                         'suppress_filters' => true,
1323                         'update_post_term_cache' => false,
1324                         'update_post_meta_cache' => false,
1325                         'post_status' => 'publish',
1326                         'posts_per_page' => 20,
1327                 );
1328
1329                 $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
1330
1331                 if ( isset( $args['s'] ) )
1332                         $query['s'] = $args['s'];
1333
1334                 $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
1335
1336                 /**
1337                  * Filter the link query arguments.
1338                  *
1339                  * Allows modification of the link query arguments before querying.
1340                  *
1341                  * @see WP_Query for a full list of arguments
1342                  *
1343                  * @since 3.7.0
1344                  *
1345                  * @param array $query An array of WP_Query arguments.
1346                  */
1347                 $query = apply_filters( 'wp_link_query_args', $query );
1348
1349                 // Do main query.
1350                 $get_posts = new WP_Query;
1351                 $posts = $get_posts->query( $query );
1352                 // Check if any posts were found.
1353                 if ( ! $get_posts->post_count )
1354                         return false;
1355
1356                 // Build results.
1357                 $results = array();
1358                 foreach ( $posts as $post ) {
1359                         if ( 'post' == $post->post_type )
1360                                 $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
1361                         else
1362                                 $info = $pts[ $post->post_type ]->labels->singular_name;
1363
1364                         $results[] = array(
1365                                 'ID' => $post->ID,
1366                                 'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
1367                                 'permalink' => get_permalink( $post->ID ),
1368                                 'info' => $info,
1369                         );
1370                 }
1371
1372                 /**
1373                  * Filter the link query results.
1374                  *
1375                  * Allows modification of the returned link query results.
1376                  *
1377                  * @since 3.7.0
1378                  *
1379                  * @see 'wp_link_query_args' filter
1380                  *
1381                  * @param array $results {
1382                  *     An associative array of query results.
1383                  *
1384                  *     @type array {
1385                  *         @type int    $ID        Post ID.
1386                  *         @type string $title     The trimmed, escaped post title.
1387                  *         @type string $permalink Post permalink.
1388                  *         @type string $info      A 'Y/m/d'-formatted date for 'post' post type,
1389                  *                                 the 'singular_name' post type label otherwise.
1390                  *     }
1391                  * }
1392                  * @param array $query  An array of WP_Query arguments.
1393                  */
1394                 return apply_filters( 'wp_link_query', $results, $query );
1395         }
1396
1397         /**
1398          * Dialog for internal linking.
1399          *
1400          * @since 3.1.0
1401          *
1402          * @static
1403          */
1404         public static function wp_link_dialog() {
1405                 // display: none is required here, see #WP27605
1406                 ?>
1407                 <div id="wp-link-backdrop" style="display: none"></div>
1408                 <div id="wp-link-wrap" class="wp-core-ui" style="display: none" role="dialog" aria-labelledby="link-modal-title">
1409                 <form id="wp-link" tabindex="-1">
1410                 <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
1411                 <h1 id="link-modal-title"><?php _e( 'Insert/edit link' ) ?></h1>
1412                 <button type="button" id="wp-link-close"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
1413                 <div id="link-selector">
1414                         <div id="link-options">
1415                                 <p class="howto" id="wplink-enter-url"><?php _e( 'Enter the destination URL' ); ?></p>
1416                                 <div>
1417                                         <label><span><?php _e( 'URL' ); ?></span>
1418                                         <input id="wp-link-url" type="text" aria-describedby="wplink-enter-url" /></label>
1419                                 </div>
1420                                 <div class="wp-link-text-field">
1421                                         <label><span><?php _e( 'Link Text' ); ?></span>
1422                                         <input id="wp-link-text" type="text" /></label>
1423                                 </div>
1424                                 <div class="link-target">
1425                                         <label><span></span>
1426                                         <input type="checkbox" id="wp-link-target" /> <?php _e( 'Open link in a new tab' ); ?></label>
1427                                 </div>
1428                         </div>
1429                         <p class="howto" id="wplink-link-existing-content"><?php _e( 'Or link to existing content' ); ?></p>
1430                         <div id="search-panel">
1431                                 <div class="link-search-wrapper">
1432                                         <label>
1433                                                 <span class="search-label"><?php _e( 'Search' ); ?></span>
1434                                                 <input type="search" id="wp-link-search" class="link-search-field" autocomplete="off" aria-describedby="wplink-link-existing-content" />
1435                                                 <span class="spinner"></span>
1436                                         </label>
1437                                 </div>
1438                                 <div id="search-results" class="query-results" tabindex="0">
1439                                         <ul></ul>
1440                                         <div class="river-waiting">
1441                                                 <span class="spinner"></span>
1442                                         </div>
1443                                 </div>
1444                                 <div id="most-recent-results" class="query-results" tabindex="0">
1445                                         <div class="query-notice" id="query-notice-message">
1446                                                 <em class="query-notice-default"><?php _e( 'No search term specified. Showing recent items.' ); ?></em>
1447                                                 <em class="query-notice-hint screen-reader-text"><?php _e( 'Search or use up and down arrow keys to select an item.' ); ?></em>
1448                                         </div>
1449                                         <ul></ul>
1450                                         <div class="river-waiting">
1451                                                 <span class="spinner"></span>
1452                                         </div>
1453                                 </div>
1454                         </div>
1455                 </div>
1456                 <div class="submitbox">
1457                         <div id="wp-link-cancel">
1458                                 <button type="button" class="button"><?php _e( 'Cancel' ); ?></button>
1459                         </div>
1460                         <div id="wp-link-update">
1461                                 <input type="submit" value="<?php esc_attr_e( 'Add Link' ); ?>" class="button button-primary" id="wp-link-submit" name="wp-link-submit">
1462                         </div>
1463                 </div>
1464                 </form>
1465                 </div>
1466                 <?php
1467         }
1468 }