3 * Facilitates adding of the WordPress editor as used on the Write and Edit screens.
8 * Private, not included by default. See wp_editor() in wp-includes/general-template.php.
11 final class _WP_Editors {
12 public static $mce_locale;
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 private static $translation;
31 private function __construct() {}
34 * Parse default arguments for the editor instance.
37 * @param string $editor_id ID for the current editor instance.
38 * @param array $settings {
39 * Array of editor arguments.
41 * @type bool $wpautop Whether to use wpautop(). Default true.
42 * @type bool $media_buttons Whether to show the Add Media/other media buttons.
43 * @type string $default_editor When both TinyMCE and Quicktags are used, set which
44 * editor is shown on page load. Default empty.
45 * @type bool $drag_drop_upload Whether to enable drag & drop on the editor uploading. Default false.
46 * Requires the media modal.
47 * @type string $textarea_name Give the textarea a unique name here. Square brackets
48 * can be used here. Default $editor_id.
49 * @type int $textarea_rows Number rows in the editor textarea. Default 20.
50 * @type string|int $tabindex Tabindex value to use. Default empty.
51 * @type string $tabfocus_elements The previous and next element ID to move the focus to
52 * when pressing the Tab key in TinyMCE. Default ':prev,:next'.
53 * @type string $editor_css Intended for extra styles for both Visual and Text editors.
54 * Should include `<style>` tags, and can use "scoped". Default empty.
55 * @type string $editor_class Extra classes to add to the editor textarea element. Default empty.
56 * @type bool $teeny Whether to output the minimal editor config. Examples include
57 * Press This and the Comment editor. Default false.
58 * @type bool $dfw Deprecated in 4.1. Since 4.3 used only to enqueue wp-fullscreen-stub.js
59 * for backward compatibility.
60 * @type bool|array $tinymce Whether to load TinyMCE. Can be used to pass settings directly to
61 * TinyMCE using an array. Default true.
62 * @type bool|array $quicktags Whether to load Quicktags. Can be used to pass settings directly to
63 * Quicktags using an array. Default true.
65 * @return array Parsed arguments array.
67 public static function parse_settings( $editor_id, $settings ) {
70 * Filters the wp_editor() settings.
74 * @see _WP_Editors()::parse_settings()
76 * @param array $settings Array of editor arguments.
77 * @param string $editor_id ID for the current editor instance.
79 $settings = apply_filters( 'wp_editor_settings', $settings, $editor_id );
81 $set = wp_parse_args( $settings, array(
83 'media_buttons' => true,
84 'default_editor' => '',
85 'drag_drop_upload' => false,
86 'textarea_name' => $editor_id,
87 'textarea_rows' => 20,
89 'tabfocus_elements' => ':prev,:next',
94 '_content_editor_dfw' => false,
99 self::$this_tinymce = ( $set['tinymce'] && user_can_richedit() );
101 if ( self::$this_tinymce ) {
102 if ( false !== strpos( $editor_id, '[' ) ) {
103 self::$this_tinymce = false;
104 _deprecated_argument( 'wp_editor()', '3.9.0', 'TinyMCE editor IDs cannot have brackets.' );
108 self::$this_quicktags = (bool) $set['quicktags'];
110 if ( self::$this_tinymce )
111 self::$has_tinymce = true;
113 if ( self::$this_quicktags )
114 self::$has_quicktags = true;
117 self::$old_dfw_compat = true;
120 if ( empty( $set['editor_height'] ) )
123 if ( 'content' === $editor_id && empty( $set['tinymce']['wp_autoresize_on'] ) ) {
124 // A cookie (set when a user resizes the editor) overrides the height.
125 $cookie = (int) get_user_setting( 'ed_size' );
128 $set['editor_height'] = $cookie;
131 if ( $set['editor_height'] < 50 )
132 $set['editor_height'] = 50;
133 elseif ( $set['editor_height'] > 5000 )
134 $set['editor_height'] = 5000;
140 * Outputs the HTML for a single instance of the editor.
143 * @param string $content The initial content of the editor.
144 * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers).
145 * @param array $settings See the _parse_settings() method for description.
147 public static function editor( $content, $editor_id, $settings = array() ) {
148 $set = self::parse_settings( $editor_id, $settings );
149 $editor_class = ' class="' . trim( esc_attr( $set['editor_class'] ) . ' wp-editor-area' ) . '"';
150 $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
151 $default_editor = 'html';
152 $buttons = $autocomplete = '';
153 $editor_id_attr = esc_attr( $editor_id );
155 if ( $set['drag_drop_upload'] ) {
156 self::$drag_drop_upload = true;
159 if ( ! empty( $set['editor_height'] ) ) {
160 $height = ' style="height: ' . (int) $set['editor_height'] . 'px"';
162 $height = ' rows="' . (int) $set['textarea_rows'] . '"';
165 if ( ! current_user_can( 'upload_files' ) ) {
166 $set['media_buttons'] = false;
169 if ( self::$this_tinymce ) {
170 $autocomplete = ' autocomplete="off"';
172 if ( self::$this_quicktags ) {
173 $default_editor = $set['default_editor'] ? $set['default_editor'] : wp_default_editor();
174 // 'html' is used for the "Text" editor tab.
175 if ( 'html' !== $default_editor ) {
176 $default_editor = 'tinymce';
179 $buttons .= '<button type="button" id="' . $editor_id_attr . '-tmce" class="wp-switch-editor switch-tmce"' .
180 ' data-wp-editor-id="' . $editor_id_attr . '">' . __('Visual') . "</button>\n";
181 $buttons .= '<button type="button" id="' . $editor_id_attr . '-html" class="wp-switch-editor switch-html"' .
182 ' data-wp-editor-id="' . $editor_id_attr . '">' . _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ) . "</button>\n";
184 $default_editor = 'tinymce';
188 $switch_class = 'html' === $default_editor ? 'html-active' : 'tmce-active';
189 $wrap_class = 'wp-core-ui wp-editor-wrap ' . $switch_class;
191 if ( $set['_content_editor_dfw'] ) {
192 $wrap_class .= ' has-dfw';
195 echo '<div id="wp-' . $editor_id_attr . '-wrap" class="' . $wrap_class . '">';
197 if ( self::$editor_buttons_css ) {
198 wp_print_styles( 'editor-buttons' );
199 self::$editor_buttons_css = false;
202 if ( ! empty( $set['editor_css'] ) ) {
203 echo $set['editor_css'] . "\n";
206 if ( ! empty( $buttons ) || $set['media_buttons'] ) {
207 echo '<div id="wp-' . $editor_id_attr . '-editor-tools" class="wp-editor-tools hide-if-no-js">';
209 if ( $set['media_buttons'] ) {
210 self::$has_medialib = true;
212 if ( ! function_exists( 'media_buttons' ) )
213 include( ABSPATH . 'wp-admin/includes/media.php' );
215 echo '<div id="wp-' . $editor_id_attr . '-media-buttons" class="wp-media-buttons">';
218 * Fires after the default media button(s) are displayed.
222 * @param string $editor_id Unique editor identifier, e.g. 'content'.
224 do_action( 'media_buttons', $editor_id );
228 echo '<div class="wp-editor-tabs">' . $buttons . "</div>\n";
232 $quicktags_toolbar = '';
234 if ( self::$this_quicktags ) {
235 if ( 'content' === $editor_id && ! empty( $GLOBALS['current_screen'] ) && $GLOBALS['current_screen']->base === 'post' ) {
236 $toolbar_id = 'ed_toolbar';
238 $toolbar_id = 'qt_' . $editor_id_attr . '_toolbar';
241 $quicktags_toolbar = '<div id="' . $toolbar_id . '" class="quicktags-toolbar"></div>';
245 * Filters the HTML markup output that displays the editor.
249 * @param string $output Editor's HTML markup.
251 $the_editor = apply_filters( 'the_editor', '<div id="wp-' . $editor_id_attr . '-editor-container" class="wp-editor-container">' .
253 '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . esc_attr( $set['textarea_name'] ) . '" ' .
254 'id="' . $editor_id_attr . '">%s</textarea></div>' );
256 // Prepare the content for the Visual or Text editor, only when TinyMCE is used (back-compat).
257 if ( self::$this_tinymce ) {
258 add_filter( 'the_editor_content', 'format_for_editor', 10, 2 );
262 * Filters the default editor content.
266 * @param string $content Default editor content.
267 * @param string $default_editor The default editor for the current user.
268 * Either 'html' or 'tinymce'.
270 $content = apply_filters( 'the_editor_content', $content, $default_editor );
272 // Remove the filter as the next editor on the same page may not need it.
273 if ( self::$this_tinymce ) {
274 remove_filter( 'the_editor_content', 'format_for_editor' );
277 // Back-compat for the `htmledit_pre` and `richedit_pre` filters
278 if ( 'html' === $default_editor && has_filter( 'htmledit_pre' ) ) {
279 // TODO: needs _deprecated_filter(), use _deprecated_function() as substitute for now
280 _deprecated_function( 'add_filter( htmledit_pre )', '4.3.0', 'add_filter( format_for_editor )' );
281 $content = apply_filters( 'htmledit_pre', $content );
282 } elseif ( 'tinymce' === $default_editor && has_filter( 'richedit_pre' ) ) {
283 _deprecated_function( 'add_filter( richedit_pre )', '4.3.0', 'add_filter( format_for_editor )' );
284 $content = apply_filters( 'richedit_pre', $content );
287 if ( false !== stripos( $content, 'textarea' ) ) {
288 $content = preg_replace( '%</textarea%i', '</textarea', $content );
291 printf( $the_editor, $content );
294 self::editor_settings( $editor_id, $set );
300 * @global string $tinymce_version
302 * @param string $editor_id
305 public static function editor_settings($editor_id, $set) {
306 global $tinymce_version;
308 if ( empty(self::$first_init) ) {
310 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
311 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
313 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
314 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
318 if ( self::$this_quicktags ) {
325 if ( is_array($set['quicktags']) )
326 $qtInit = array_merge($qtInit, $set['quicktags']);
328 if ( empty($qtInit['buttons']) )
329 $qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close';
331 if ( $set['_content_editor_dfw'] ) {
332 $qtInit['buttons'] .= ',dfw';
336 * Filters the Quicktags settings.
340 * @param array $qtInit Quicktags settings.
341 * @param string $editor_id The unique editor ID, e.g. 'content'.
343 $qtInit = apply_filters( 'quicktags_settings', $qtInit, $editor_id );
345 self::$qt_settings[$editor_id] = $qtInit;
347 self::$qt_buttons = array_merge( self::$qt_buttons, explode(',', $qtInit['buttons']) );
350 if ( self::$this_tinymce ) {
352 if ( empty( self::$first_init ) ) {
353 self::$baseurl = includes_url( 'js/tinymce' );
355 $mce_locale = get_user_locale();
356 self::$mce_locale = $mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1
358 /** This filter is documented in wp-admin/includes/media.php */
359 $no_captions = (bool) apply_filters( 'disable_captions', '' );
361 $shortcut_labels = array();
363 foreach ( self::get_translation() as $name => $value ) {
364 if ( is_array( $value ) ) {
365 $shortcut_labels[$name] = $value[1];
369 if ( $set['teeny'] ) {
372 * Filters the list of teenyMCE plugins.
376 * @param array $plugins An array of teenyMCE plugins.
377 * @param string $editor_id Unique editor identifier, e.g. 'content'.
379 self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array( 'colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink' ), $editor_id );
383 * Filters the list of TinyMCE external plugins.
385 * The filter takes an associative array of external plugins for
386 * TinyMCE in the form 'plugin_name' => 'url'.
388 * The url should be absolute, and should include the js filename
389 * to be loaded. For example:
390 * 'myplugin' => 'http://mysite.com/wp-content/plugins/myfolder/mce_plugin.js'.
392 * If the external plugin adds a button, it should be added with
393 * one of the 'mce_buttons' filters.
397 * @param array $external_plugins An array of external TinyMCE plugins.
399 $mce_external_plugins = apply_filters( 'mce_external_plugins', array() );
423 if ( ! self::$has_medialib ) {
424 $plugins[] = 'image';
428 * Filters the list of default TinyMCE plugins.
430 * The filter specifies which of the default plugins included
431 * in WordPress should be added to the TinyMCE instance.
435 * @param array $plugins An array of default TinyMCE plugins.
437 $plugins = array_unique( apply_filters( 'tiny_mce_plugins', $plugins ) );
439 if ( ( $key = array_search( 'spellchecker', $plugins ) ) !== false ) {
440 // Remove 'spellchecker' from the internal plugins if added with 'tiny_mce_plugins' filter to prevent errors.
441 // It can be added with 'mce_external_plugins'.
442 unset( $plugins[$key] );
445 if ( ! empty( $mce_external_plugins ) ) {
448 * Filters the translations loaded for external TinyMCE 3.x plugins.
450 * The filter takes an associative array ('plugin_name' => 'path')
451 * where 'path' is the include path to the file.
453 * The language file should follow the same format as wp_mce_translation(),
454 * and should define a variable ($strings) that holds all translated strings.
458 * @param array $translations Translations for external TinyMCE plugins.
460 $mce_external_languages = apply_filters( 'mce_external_languages', array() );
462 $loaded_langs = array();
465 if ( ! empty( $mce_external_languages ) ) {
466 foreach ( $mce_external_languages as $name => $path ) {
467 if ( @is_file( $path ) && @is_readable( $path ) ) {
468 include_once( $path );
469 $ext_plugins .= $strings . "\n";
470 $loaded_langs[] = $name;
475 foreach ( $mce_external_plugins as $name => $url ) {
476 if ( in_array( $name, $plugins, true ) ) {
477 unset( $mce_external_plugins[ $name ] );
481 $url = set_url_scheme( $url );
482 $mce_external_plugins[ $name ] = $url;
483 $plugurl = dirname( $url );
486 // Try to load langs/[locale].js and langs/[locale]_dlg.js
487 if ( ! in_array( $name, $loaded_langs, true ) ) {
488 $path = str_replace( content_url(), '', $plugurl );
489 $path = WP_CONTENT_DIR . $path . '/langs/';
491 if ( function_exists('realpath') )
492 $path = trailingslashit( realpath($path) );
494 if ( @is_file( $path . $mce_locale . '.js' ) )
495 $strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n";
497 if ( @is_file( $path . $mce_locale . '_dlg.js' ) )
498 $strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n";
500 if ( 'en' != $mce_locale && empty( $strings ) ) {
501 if ( @is_file( $path . 'en.js' ) ) {
502 $str1 = @file_get_contents( $path . 'en.js' );
503 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
506 if ( @is_file( $path . 'en_dlg.js' ) ) {
507 $str2 = @file_get_contents( $path . 'en_dlg.js' );
508 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";
512 if ( ! empty( $strings ) )
513 $ext_plugins .= "\n" . $strings . "\n";
516 $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
517 $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
522 self::$plugins = $plugins;
523 self::$ext_plugins = $ext_plugins;
525 self::$first_init = array(
527 'skin' => 'lightgray',
528 'language' => self::$mce_locale,
531 '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"left"}},' .
532 '{selector: "img,table,dl.wp-caption", classes: "alignleft"}' .
535 '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"center"}},' .
536 '{selector: "img,table,dl.wp-caption", classes: "aligncenter"}' .
539 '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"right"}},' .
540 '{selector: "img,table,dl.wp-caption", classes: "alignright"}' .
542 'strikethrough: {inline: "del"}' .
544 'relative_urls' => false,
545 'remove_script_host' => false,
546 'convert_urls' => false,
547 'browser_spellcheck' => true,
548 'fix_list_elements' => true,
549 'entities' => '38,amp,60,lt,62,gt',
550 'entity_encoding' => 'raw',
551 'keep_styles' => false,
552 'cache_suffix' => 'wp-mce-' . $tinymce_version,
554 // Limit the preview styles in the menu/toolbar
555 'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform',
557 'end_container_on_empty_block' => true,
558 'wpeditimage_disable_captions' => $no_captions,
559 'wpeditimage_html5_captions' => current_theme_supports( 'html5', 'caption' ),
560 'plugins' => implode( ',', $plugins ),
561 'wp_lang_attr' => get_bloginfo( 'language' ),
562 'wp_shortcut_labels' => wp_json_encode( $shortcut_labels ),
565 if ( ! empty( $mce_external_plugins ) ) {
566 self::$first_init['external_plugins'] = wp_json_encode( $mce_external_plugins );
569 $suffix = SCRIPT_DEBUG ? '' : '.min';
570 $version = 'ver=' . get_bloginfo( 'version' );
571 $dashicons = includes_url( "css/dashicons$suffix.css?$version" );
573 // WordPress default stylesheet and dashicons
576 self::$baseurl . '/skins/wordpress/wp-content.css?' . $version
579 $editor_styles = get_editor_stylesheets();
580 if ( ! empty( $editor_styles ) ) {
581 foreach ( $editor_styles as $style ) {
587 * Filters the comma-delimited list of stylesheets to load in TinyMCE.
591 * @param string $stylesheets Comma-delimited list of stylesheets.
593 $mce_css = trim( apply_filters( 'mce_css', implode( ',', $mce_css ) ), ' ,' );
595 if ( ! empty($mce_css) )
596 self::$first_init['content_css'] = $mce_css;
599 if ( $set['teeny'] ) {
602 * Filters the list of teenyMCE buttons (Text tab).
606 * @param array $buttons An array of teenyMCE buttons.
607 * @param string $editor_id Unique editor identifier, e.g. 'content'.
609 $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 );
610 $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
612 $mce_buttons = array( 'formatselect', 'bold', 'italic', 'bullist', 'numlist', 'blockquote', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker' );
614 if ( ! wp_is_mobile() ) {
615 if ( $set['_content_editor_dfw'] ) {
616 $mce_buttons[] = 'dfw';
618 $mce_buttons[] = 'fullscreen';
622 $mce_buttons[] = 'wp_adv';
625 * Filters the first-row list of TinyMCE buttons (Visual tab).
629 * @param array $buttons First-row list of buttons.
630 * @param string $editor_id Unique editor identifier, e.g. 'content'.
632 $mce_buttons = apply_filters( 'mce_buttons', $mce_buttons, $editor_id );
634 $mce_buttons_2 = array( 'strikethrough', 'hr', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo' );
636 if ( ! wp_is_mobile() ) {
637 $mce_buttons_2[] = 'wp_help';
641 * Filters the second-row list of TinyMCE buttons (Visual tab).
645 * @param array $buttons Second-row list of buttons.
646 * @param string $editor_id Unique editor identifier, e.g. 'content'.
648 $mce_buttons_2 = apply_filters( 'mce_buttons_2', $mce_buttons_2, $editor_id );
651 * Filters the third-row list of TinyMCE buttons (Visual tab).
655 * @param array $buttons Third-row list of buttons.
656 * @param string $editor_id Unique editor identifier, e.g. 'content'.
658 $mce_buttons_3 = apply_filters( 'mce_buttons_3', array(), $editor_id );
661 * Filters the fourth-row list of TinyMCE buttons (Visual tab).
665 * @param array $buttons Fourth-row list of buttons.
666 * @param string $editor_id Unique editor identifier, e.g. 'content'.
668 $mce_buttons_4 = apply_filters( 'mce_buttons_4', array(), $editor_id );
671 $body_class = $editor_id;
673 if ( $post = get_post() ) {
674 $body_class .= ' post-type-' . sanitize_html_class( $post->post_type ) . ' post-status-' . sanitize_html_class( $post->post_status );
676 if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
677 $post_format = get_post_format( $post );
678 if ( $post_format && ! is_wp_error( $post_format ) )
679 $body_class .= ' post-format-' . sanitize_html_class( $post_format );
681 $body_class .= ' post-format-standard';
684 if ( $page_template = get_page_template_slug( $post ) ) {
685 $page_template = str_replace( '.', '-', basename( $page_template, '.php' ) );
686 $body_class .= ' page-template-' . sanitize_html_class( $page_template );
690 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
692 if ( !empty($set['tinymce']['body_class']) ) {
693 $body_class .= ' ' . $set['tinymce']['body_class'];
694 unset($set['tinymce']['body_class']);
698 'selector' => "#$editor_id",
699 'resize' => 'vertical',
701 'wpautop' => (bool) $set['wpautop'],
702 'indent' => ! $set['wpautop'],
703 'toolbar1' => implode($mce_buttons, ','),
704 'toolbar2' => implode($mce_buttons_2, ','),
705 'toolbar3' => implode($mce_buttons_3, ','),
706 'toolbar4' => implode($mce_buttons_4, ','),
707 'tabfocus_elements' => $set['tabfocus_elements'],
708 'body_class' => $body_class
711 // Merge with the first part of the init array
712 $mceInit = array_merge( self::$first_init, $mceInit );
714 if ( is_array( $set['tinymce'] ) )
715 $mceInit = array_merge( $mceInit, $set['tinymce'] );
718 * For people who really REALLY know what they're doing with TinyMCE
719 * You can modify $mceInit to add, remove, change elements of the config
720 * before tinyMCE.init. Setting "valid_elements", "invalid_elements"
721 * and "extended_valid_elements" can be done through this filter. Best
722 * is to use the default cleanup by not specifying valid_elements,
723 * as TinyMCE checks against the full set of HTML 5.0 elements and attributes.
725 if ( $set['teeny'] ) {
728 * Filters the teenyMCE config before init.
732 * @param array $mceInit An array with teenyMCE config.
733 * @param string $editor_id Unique editor identifier, e.g. 'content'.
735 $mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
739 * Filters the TinyMCE config before init.
743 * @param array $mceInit An array with TinyMCE config.
744 * @param string $editor_id Unique editor identifier, e.g. 'content'.
746 $mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );
749 if ( empty( $mceInit['toolbar3'] ) && ! empty( $mceInit['toolbar4'] ) ) {
750 $mceInit['toolbar3'] = $mceInit['toolbar4'];
751 $mceInit['toolbar4'] = '';
754 self::$mce_settings[$editor_id] = $mceInit;
755 } // end if self::$this_tinymce
764 private static function _parse_init($init) {
767 foreach ( $init as $k => $v ) {
769 $val = $v ? 'true' : 'false';
770 $options .= $k . ':' . $val . ',';
772 } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {
773 $options .= $k . ':' . $v . ',';
776 $options .= $k . ':"' . $v . '",';
779 return '{' . trim( $options, ' ,' ) . '}';
786 public static function enqueue_scripts() {
787 if ( self::$has_tinymce )
788 wp_enqueue_script('editor');
790 if ( self::$has_quicktags ) {
791 wp_enqueue_script( 'quicktags' );
792 wp_enqueue_style( 'buttons' );
795 if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {
796 wp_enqueue_script('wplink');
797 wp_enqueue_script( 'jquery-ui-autocomplete' );
800 if ( self::$old_dfw_compat ) {
801 wp_enqueue_script('wp-fullscreen-stub');
804 if ( self::$has_medialib ) {
806 wp_enqueue_script( 'media-upload' );
807 wp_enqueue_script( 'wp-embed' );
811 * Fires when scripts and styles are enqueued for the editor.
815 * @param array $to_load An array containing boolean values whether TinyMCE
816 * and Quicktags are being loaded.
818 do_action( 'wp_enqueue_editor', array(
819 'tinymce' => self::$has_tinymce,
820 'quicktags' => self::$has_quicktags,
824 private static function get_translation() {
825 if ( empty( self::$translation ) ) {
826 self::$translation = array(
827 // Default TinyMCE strings
828 'New document' => __( 'New document' ),
829 'Formats' => _x( 'Formats', 'TinyMCE' ),
831 'Headings' => _x( 'Headings', 'TinyMCE' ),
832 'Heading 1' => array( __( 'Heading 1' ), 'access1' ),
833 'Heading 2' => array( __( 'Heading 2' ), 'access2' ),
834 'Heading 3' => array( __( 'Heading 3' ), 'access3' ),
835 'Heading 4' => array( __( 'Heading 4' ), 'access4' ),
836 'Heading 5' => array( __( 'Heading 5' ), 'access5' ),
837 'Heading 6' => array( __( 'Heading 6' ), 'access6' ),
839 /* translators: block tags */
840 'Blocks' => _x( 'Blocks', 'TinyMCE' ),
841 'Paragraph' => array( __( 'Paragraph' ), 'access7' ),
842 'Blockquote' => array( __( 'Blockquote' ), 'accessQ' ),
843 'Div' => _x( 'Div', 'HTML tag' ),
844 'Pre' => _x( 'Pre', 'HTML tag' ),
845 'Preformatted' => _x( 'Preformatted', 'HTML tag' ),
846 'Address' => _x( 'Address', 'HTML tag' ),
848 'Inline' => _x( 'Inline', 'HTML elements' ),
849 'Underline' => array( __( 'Underline' ), 'metaU' ),
850 'Strikethrough' => array( __( 'Strikethrough' ), 'accessD' ),
851 'Subscript' => __( 'Subscript' ),
852 'Superscript' => __( 'Superscript' ),
853 'Clear formatting' => __( 'Clear formatting' ),
854 'Bold' => array( __( 'Bold' ), 'metaB' ),
855 'Italic' => array( __( 'Italic' ), 'metaI' ),
856 'Code' => array( __( 'Code' ), 'accessX' ),
857 'Source code' => __( 'Source code' ),
858 'Font Family' => __( 'Font Family' ),
859 'Font Sizes' => __( 'Font Sizes' ),
861 'Align center' => array( __( 'Align center' ), 'accessC' ),
862 'Align right' => array( __( 'Align right' ), 'accessR' ),
863 'Align left' => array( __( 'Align left' ), 'accessL' ),
864 'Justify' => array( __( 'Justify' ), 'accessJ' ),
865 'Increase indent' => __( 'Increase indent' ),
866 'Decrease indent' => __( 'Decrease indent' ),
868 'Cut' => array( __( 'Cut' ), 'metaX' ),
869 'Copy' => array( __( 'Copy' ), 'metaC' ),
870 'Paste' => array( __( 'Paste' ), 'metaV' ),
871 'Select all' => array( __( 'Select all' ), 'metaA' ),
872 'Undo' => array( __( 'Undo' ), 'metaZ' ),
873 'Redo' => array( __( 'Redo' ), 'metaY' ),
876 'Cancel' => __( 'Cancel' ),
877 'Close' => __( 'Close' ),
878 'Visual aids' => __( 'Visual aids' ),
880 'Bullet list' => array( __( 'Bulleted list' ), 'accessU' ),
881 'Numbered list' => array( __( 'Numbered list' ), 'accessO' ),
882 'Square' => _x( 'Square', 'list style' ),
883 'Default' => _x( 'Default', 'list style' ),
884 'Circle' => _x( 'Circle', 'list style' ),
885 'Disc' => _x('Disc', 'list style' ),
886 'Lower Greek' => _x( 'Lower Greek', 'list style' ),
887 'Lower Alpha' => _x( 'Lower Alpha', 'list style' ),
888 'Upper Alpha' => _x( 'Upper Alpha', 'list style' ),
889 'Upper Roman' => _x( 'Upper Roman', 'list style' ),
890 'Lower Roman' => _x( 'Lower Roman', 'list style' ),
893 'Name' => _x( 'Name', 'Name of link anchor (TinyMCE)' ),
894 'Anchor' => _x( 'Anchor', 'Link anchor (TinyMCE)' ),
895 'Anchors' => _x( 'Anchors', 'Link anchors (TinyMCE)' ),
898 'Document properties' => __( 'Document properties' ),
899 'Robots' => __( 'Robots' ),
900 'Title' => __( 'Title' ),
901 'Keywords' => __( 'Keywords' ),
902 'Encoding' => __( 'Encoding' ),
903 'Description' => __( 'Description' ),
904 'Author' => __( 'Author' ),
906 // Media, image plugins
907 'Insert/edit image' => array( __( 'Insert/edit image' ), 'accessM' ),
908 'General' => __( 'General' ),
909 'Advanced' => __( 'Advanced' ),
910 'Source' => __( 'Source' ),
911 'Border' => __( 'Border' ),
912 'Constrain proportions' => __( 'Constrain proportions' ),
913 'Vertical space' => __( 'Vertical space' ),
914 'Image description' => __( 'Image description' ),
915 'Style' => __( 'Style' ),
916 'Dimensions' => __( 'Dimensions' ),
917 'Insert image' => __( 'Insert image' ),
918 'Insert date/time' => __( 'Insert date/time' ),
919 'Insert/edit video' => __( 'Insert/edit video' ),
920 'Poster' => __( 'Poster' ),
921 'Alternative source' => __( 'Alternative source' ),
922 'Paste your embed code below:' => __( 'Paste your embed code below:' ),
923 'Insert video' => __( 'Insert video' ),
924 'Embed' => __( 'Embed' ),
926 // Each of these have a corresponding plugin
927 'Special character' => __( 'Special character' ),
928 'Right to left' => _x( 'Right to left', 'editor button' ),
929 'Left to right' => _x( 'Left to right', 'editor button' ),
930 'Emoticons' => __( 'Emoticons' ),
931 'Nonbreaking space' => __( 'Nonbreaking space' ),
932 'Page break' => __( 'Page break' ),
933 'Paste as text' => __( 'Paste as text' ),
934 'Preview' => __( 'Preview' ),
935 'Print' => __( 'Print' ),
936 'Save' => __( 'Save' ),
937 'Fullscreen' => __( 'Fullscreen' ),
938 'Horizontal line' => __( 'Horizontal line' ),
939 'Horizontal space' => __( 'Horizontal space' ),
940 'Restore last draft' => __( 'Restore last draft' ),
941 'Insert/edit link' => array( __( 'Insert/edit link' ), 'metaK' ),
942 'Remove link' => array( __( 'Remove link' ), 'accessS' ),
944 'Color' => __( 'Color' ),
945 'Custom color' => __( 'Custom color' ),
946 'Custom...' => _x( 'Custom...', 'label for custom color' ), // no ellipsis
947 'No color' => __( 'No color' ),
949 // Spelling, search/replace plugins
950 'Could not find the specified string.' => __( 'Could not find the specified string.' ),
951 'Replace' => _x( 'Replace', 'find/replace' ),
952 'Next' => _x( 'Next', 'find/replace' ),
953 /* translators: previous */
954 'Prev' => _x( 'Prev', 'find/replace' ),
955 'Whole words' => _x( 'Whole words', 'find/replace' ),
956 'Find and replace' => __( 'Find and replace' ),
957 'Replace with' => _x('Replace with', 'find/replace' ),
958 'Find' => _x( 'Find', 'find/replace' ),
959 'Replace all' => _x( 'Replace all', 'find/replace' ),
960 'Match case' => __( 'Match case' ),
961 'Spellcheck' => __( 'Check Spelling' ),
962 'Finish' => _x( 'Finish', 'spellcheck' ),
963 'Ignore all' => _x( 'Ignore all', 'spellcheck' ),
964 'Ignore' => _x( 'Ignore', 'spellcheck' ),
965 'Add to Dictionary' => __( 'Add to Dictionary' ),
968 'Insert table' => __( 'Insert table' ),
969 'Delete table' => __( 'Delete table' ),
970 'Table properties' => __( 'Table properties' ),
971 'Row properties' => __( 'Table row properties' ),
972 'Cell properties' => __( 'Table cell properties' ),
973 'Border color' => __( 'Border color' ),
975 'Row' => __( 'Row' ),
976 'Rows' => __( 'Rows' ),
977 'Column' => _x( 'Column', 'table column' ),
978 'Cols' => _x( 'Cols', 'table columns' ),
979 'Cell' => _x( 'Cell', 'table cell' ),
980 'Header cell' => __( 'Header cell' ),
981 'Header' => _x( 'Header', 'table header' ),
982 'Body' => _x( 'Body', 'table body' ),
983 'Footer' => _x( 'Footer', 'table footer' ),
985 'Insert row before' => __( 'Insert row before' ),
986 'Insert row after' => __( 'Insert row after' ),
987 'Insert column before' => __( 'Insert column before' ),
988 'Insert column after' => __( 'Insert column after' ),
989 'Paste row before' => __( 'Paste table row before' ),
990 'Paste row after' => __( 'Paste table row after' ),
991 'Delete row' => __( 'Delete row' ),
992 'Delete column' => __( 'Delete column' ),
993 'Cut row' => __( 'Cut table row' ),
994 'Copy row' => __( 'Copy table row' ),
995 'Merge cells' => __( 'Merge table cells' ),
996 'Split cell' => __( 'Split table cell' ),
998 'Height' => __( 'Height' ),
999 'Width' => __( 'Width' ),
1000 'Caption' => __( 'Caption' ),
1001 'Alignment' => __( 'Alignment' ),
1002 'H Align' => _x( 'H Align', 'horizontal table cell alignment' ),
1003 'Left' => __( 'Left' ),
1004 'Center' => __( 'Center' ),
1005 'Right' => __( 'Right' ),
1006 'None' => _x( 'None', 'table cell alignment attribute' ),
1007 'V Align' => _x( 'V Align', 'vertical table cell alignment' ),
1008 'Top' => __( 'Top' ),
1009 'Middle' => __( 'Middle' ),
1010 'Bottom' => __( 'Bottom' ),
1012 'Row group' => __( 'Row group' ),
1013 'Column group' => __( 'Column group' ),
1014 'Row type' => __( 'Row type' ),
1015 'Cell type' => __( 'Cell type' ),
1016 'Cell padding' => __( 'Cell padding' ),
1017 'Cell spacing' => __( 'Cell spacing' ),
1018 'Scope' => _x( 'Scope', 'table cell scope attribute' ),
1020 'Insert template' => _x( 'Insert template', 'TinyMCE' ),
1021 'Templates' => _x( 'Templates', 'TinyMCE' ),
1023 'Background color' => __( 'Background color' ),
1024 'Text color' => __( 'Text color' ),
1025 'Show blocks' => _x( 'Show blocks', 'editor button' ),
1026 'Show invisible characters' => __( 'Show invisible characters' ),
1028 /* translators: word count */
1029 'Words: {0}' => sprintf( __( 'Words: %s' ), '{0}' ),
1030 '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’re looking to paste rich content from Microsoft Word, try turning this option off. The editor will clean up text pasted from Word automatically.' ),
1031 '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.' ),
1032 'Rich Text Area. Press Control-Option-H for help.' => __( 'Rich Text Area. Press Control-Option-H for help.' ),
1033 '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.' ),
1034 '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’s edit menu instead.' ),
1037 'Insert' => _x( 'Insert', 'TinyMCE menu' ),
1038 'File' => _x( 'File', 'TinyMCE menu' ),
1039 'Edit' => _x( 'Edit', 'TinyMCE menu' ),
1040 'Tools' => _x( 'Tools', 'TinyMCE menu' ),
1041 'View' => _x( 'View', 'TinyMCE menu' ),
1042 'Table' => _x( 'Table', 'TinyMCE menu' ),
1043 'Format' => _x( 'Format', 'TinyMCE menu' ),
1045 // WordPress strings
1046 'Toolbar Toggle' => array( __( 'Toolbar Toggle' ), 'accessZ' ),
1047 'Insert Read More tag' => array( __( 'Insert Read More tag' ), 'accessT' ),
1048 'Insert Page Break tag' => array( __( 'Insert Page Break tag' ), 'accessP' ),
1049 'Read more...' => __( 'Read more...' ), // Title on the placeholder inside the editor (no ellipsis)
1050 'Distraction-free writing mode' => array( __( 'Distraction-free writing mode' ), 'accessW' ),
1051 'No alignment' => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar
1052 'Remove' => __( 'Remove' ), // Tooltip for the 'remove' button in the image toolbar
1053 'Edit ' => __( 'Edit' ), // Tooltip for the 'edit' button in the image toolbar
1054 'Paste URL or type to search' => __( 'Paste URL or type to search' ), // Placeholder for the inline link dialog
1055 'Apply' => __( 'Apply' ), // Tooltip for the 'apply' button in the inline link dialog
1056 'Link options' => __( 'Link options' ), // Tooltip for the 'link options' button in the inline link dialog
1058 // Shortcuts help modal
1059 'Keyboard Shortcuts' => array( __( 'Keyboard Shortcuts' ), 'accessH' ),
1060 'Default shortcuts,' => __( 'Default shortcuts,' ),
1061 'Additional shortcuts,' => __( 'Additional shortcuts,' ),
1062 'Focus shortcuts:' => __( 'Focus shortcuts:' ),
1063 'Inline toolbar (when an image, link or preview is selected)' => __( 'Inline toolbar (when an image, link or preview is selected)' ),
1064 'Editor menu (when enabled)' => __( 'Editor menu (when enabled)' ),
1065 'Editor toolbar' => __( 'Editor toolbar' ),
1066 'Elements path' => __( 'Elements path' ),
1067 'Ctrl + Alt + letter:' => __( 'Ctrl + Alt + letter:' ),
1068 'Shift + Alt + letter:' => __( 'Shift + Alt + letter:' ),
1069 'Cmd + letter:' => __( 'Cmd + letter:' ),
1070 'Ctrl + letter:' => __( 'Ctrl + letter:' ),
1071 'Letter' => __( 'Letter' ),
1072 'Action' => __( 'Action' ),
1073 '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.' ),
1074 '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.' =>
1075 __( '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.' ),
1076 '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.' =>
1077 __( '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.' ),
1078 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' =>
1079 __( 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' ),
1080 '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.' =>
1081 __( '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.' ),
1086 * Link plugin (not included):
1091 * The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?
1092 * The URL you entered seems to be an external link. Do you want to add the required http:\/\/ prefix?
1096 return self::$translation;
1100 * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
1101 * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
1104 * @param string $mce_locale The locale used for the editor.
1105 * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
1106 * @return string Translation object, JSON encoded.
1108 public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
1109 if ( ! $mce_locale ) {
1110 $mce_locale = self::$mce_locale;
1113 $mce_translation = self::get_translation();
1115 foreach ( $mce_translation as $name => $value ) {
1116 if ( is_array( $value ) ) {
1117 $mce_translation[$name] = $value[0];
1122 * Filters translated strings prepared for TinyMCE.
1126 * @param array $mce_translation Key/value pairs of strings.
1127 * @param string $mce_locale Locale.
1129 $mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale );
1131 foreach ( $mce_translation as $key => $value ) {
1132 // Remove strings that are not translated.
1133 if ( $key === $value ) {
1134 unset( $mce_translation[$key] );
1138 if ( false !== strpos( $value, '&' ) ) {
1139 $mce_translation[$key] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
1145 $mce_translation['_dir'] = 'rtl';
1149 return wp_json_encode( $mce_translation );
1152 $baseurl = self::$baseurl ? self::$baseurl : includes_url( 'js/tinymce' );
1154 return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
1155 "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
1161 * @global string $tinymce_version
1162 * @global bool $concatenate_scripts
1163 * @global bool $compress_scripts
1165 public static function editor_js() {
1166 global $tinymce_version, $concatenate_scripts, $compress_scripts;
1169 * Filters "tiny_mce_version" is deprecated
1171 * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
1172 * These plugins can be refreshed by appending query string to the URL passed to "mce_external_plugins" filter.
1173 * If the plugin has a popup dialog, a query string can be added to the button action that opens it (in the plugin's code).
1175 $version = 'ver=' . $tinymce_version;
1176 $tmce_on = !empty(self::$mce_settings);
1178 if ( ! isset($concatenate_scripts) )
1179 script_concat_settings();
1181 $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
1182 && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
1184 $mceInit = $qtInit = '';
1186 foreach ( self::$mce_settings as $editor_id => $init ) {
1187 $options = self::_parse_init( $init );
1188 $mceInit .= "'$editor_id':{$options},";
1190 $mceInit = '{' . trim($mceInit, ',') . '}';
1195 if ( !empty(self::$qt_settings) ) {
1196 foreach ( self::$qt_settings as $editor_id => $init ) {
1197 $options = self::_parse_init( $init );
1198 $qtInit .= "'$editor_id':{$options},";
1200 $qtInit = '{' . trim($qtInit, ',') . '}';
1206 'plugins' => implode( ',', self::$plugins ),
1207 'theme' => 'modern',
1208 'language' => self::$mce_locale
1211 $suffix = SCRIPT_DEBUG ? '' : '.min';
1214 * Fires immediately before the TinyMCE settings are printed.
1218 * @param array $mce_settings TinyMCE settings array.
1220 do_action( 'before_wp_tiny_mce', self::$mce_settings );
1223 <script type="text/javascript">
1225 baseURL: "<?php echo self::$baseurl; ?>",
1226 suffix: "<?php echo $suffix; ?>",
1229 if ( self::$drag_drop_upload ) {
1230 echo 'dragDropUpload: true,';
1234 mceInit: <?php echo $mceInit; ?>,
1235 qtInit: <?php echo $qtInit; ?>,
1236 ref: <?php echo self::_parse_init( $ref ); ?>,
1237 load_ext: function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
1242 $baseurl = self::$baseurl;
1243 // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG)
1244 $mce_suffix = false !== strpos( get_bloginfo( 'version' ), '-src' ) ? '' : '.min';
1247 if ( $compressed ) {
1248 echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&$version'></script>\n";
1250 echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n";
1251 echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n";
1254 echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";
1256 if ( self::$ext_plugins ) {
1257 // Load the old-format English strings to prevent unsightly labels in old style popups
1258 echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
1263 * Fires after tinymce.js is loaded, but before any TinyMCE editor
1264 * instances are created.
1268 * @param array $mce_settings TinyMCE settings array.
1270 do_action( 'wp_tiny_mce_init', self::$mce_settings );
1273 <script type="text/javascript">
1276 if ( self::$ext_plugins )
1277 echo self::$ext_plugins . "\n";
1280 echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
1285 var init, id, $wrap;
1287 if ( typeof tinymce !== 'undefined' ) {
1288 for ( id in tinyMCEPreInit.mceInit ) {
1289 init = tinyMCEPreInit.mceInit[id];
1290 $wrap = tinymce.$( '#wp-' + id + '-wrap' );
1292 if ( ( $wrap.hasClass( 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( id ) ) && ! init.wp_skip_init ) {
1293 tinymce.init( init );
1295 if ( ! window.wpActiveEditor ) {
1296 window.wpActiveEditor = id;
1302 if ( typeof quicktags !== 'undefined' ) {
1303 for ( id in tinyMCEPreInit.qtInit ) {
1304 quicktags( tinyMCEPreInit.qtInit[id] );
1306 if ( ! window.wpActiveEditor ) {
1307 window.wpActiveEditor = id;
1315 if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) ) {
1316 self::wp_link_dialog();
1320 * Fires after any core TinyMCE editor instances are created.
1324 * @param array $mce_settings TinyMCE settings array.
1326 do_action( 'after_wp_tiny_mce', self::$mce_settings );
1332 * @global int $content_width
1334 public static function wp_fullscreen_html() {
1335 _deprecated_function( __FUNCTION__, '4.3.0' );
1339 * Performs post queries for internal linking.
1344 * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
1345 * @return false|array Results.
1347 public static function wp_link_query( $args = array() ) {
1348 $pts = get_post_types( array( 'public' => true ), 'objects' );
1349 $pt_names = array_keys( $pts );
1352 'post_type' => $pt_names,
1353 'suppress_filters' => true,
1354 'update_post_term_cache' => false,
1355 'update_post_meta_cache' => false,
1356 'post_status' => 'publish',
1357 'posts_per_page' => 20,
1360 $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
1362 if ( isset( $args['s'] ) )
1363 $query['s'] = $args['s'];
1365 $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
1368 * Filters the link query arguments.
1370 * Allows modification of the link query arguments before querying.
1372 * @see WP_Query for a full list of arguments
1376 * @param array $query An array of WP_Query arguments.
1378 $query = apply_filters( 'wp_link_query_args', $query );
1381 $get_posts = new WP_Query;
1382 $posts = $get_posts->query( $query );
1383 // Check if any posts were found.
1384 if ( ! $get_posts->post_count )
1389 foreach ( $posts as $post ) {
1390 if ( 'post' == $post->post_type )
1391 $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
1393 $info = $pts[ $post->post_type ]->labels->singular_name;
1397 'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
1398 'permalink' => get_permalink( $post->ID ),
1404 * Filters the link query results.
1406 * Allows modification of the returned link query results.
1410 * @see 'wp_link_query_args' filter
1412 * @param array $results {
1413 * An associative array of query results.
1416 * @type int $ID Post ID.
1417 * @type string $title The trimmed, escaped post title.
1418 * @type string $permalink Post permalink.
1419 * @type string $info A 'Y/m/d'-formatted date for 'post' post type,
1420 * the 'singular_name' post type label otherwise.
1423 * @param array $query An array of WP_Query arguments.
1425 return apply_filters( 'wp_link_query', $results, $query );
1429 * Dialog for internal linking.
1435 public static function wp_link_dialog() {
1436 // display: none is required here, see #WP27605
1438 <div id="wp-link-backdrop" style="display: none"></div>
1439 <div id="wp-link-wrap" class="wp-core-ui" style="display: none" role="dialog" aria-labelledby="link-modal-title">
1440 <form id="wp-link" tabindex="-1">
1441 <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
1442 <h1 id="link-modal-title"><?php _e( 'Insert/edit link' ) ?></h1>
1443 <button type="button" id="wp-link-close"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
1444 <div id="link-selector">
1445 <div id="link-options">
1446 <p class="howto" id="wplink-enter-url"><?php _e( 'Enter the destination URL' ); ?></p>
1448 <label><span><?php _e( 'URL' ); ?></span>
1449 <input id="wp-link-url" type="text" aria-describedby="wplink-enter-url" /></label>
1451 <div class="wp-link-text-field">
1452 <label><span><?php _e( 'Link Text' ); ?></span>
1453 <input id="wp-link-text" type="text" /></label>
1455 <div class="link-target">
1456 <label><span></span>
1457 <input type="checkbox" id="wp-link-target" /> <?php _e( 'Open link in a new tab' ); ?></label>
1460 <p class="howto" id="wplink-link-existing-content"><?php _e( 'Or link to existing content' ); ?></p>
1461 <div id="search-panel">
1462 <div class="link-search-wrapper">
1464 <span class="search-label"><?php _e( 'Search' ); ?></span>
1465 <input type="search" id="wp-link-search" class="link-search-field" autocomplete="off" aria-describedby="wplink-link-existing-content" />
1466 <span class="spinner"></span>
1469 <div id="search-results" class="query-results" tabindex="0">
1471 <div class="river-waiting">
1472 <span class="spinner"></span>
1475 <div id="most-recent-results" class="query-results" tabindex="0">
1476 <div class="query-notice" id="query-notice-message">
1477 <em class="query-notice-default"><?php _e( 'No search term specified. Showing recent items.' ); ?></em>
1478 <em class="query-notice-hint screen-reader-text"><?php _e( 'Search or use up and down arrow keys to select an item.' ); ?></em>
1481 <div class="river-waiting">
1482 <span class="spinner"></span>
1487 <div class="submitbox">
1488 <div id="wp-link-cancel">
1489 <button type="button" class="button"><?php _e( 'Cancel' ); ?></button>
1491 <div id="wp-link-update">
1492 <input type="submit" value="<?php esc_attr_e( 'Add Link' ); ?>" class="button button-primary" id="wp-link-submit" name="wp-link-submit">