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;
30 private function __construct() {}
33 * Parse default arguments for the editor instance.
36 * @param string $editor_id ID for the current editor instance.
37 * @param array $settings {
38 * Array of editor arguments.
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.
63 * @return array Parsed arguments array.
65 public static function parse_settings( $editor_id, $settings ) {
68 * Filter the wp_editor() settings.
72 * @see _WP_Editors()::parse_settings()
74 * @param array $settings Array of editor arguments.
75 * @param string $editor_id ID for the current editor instance.
77 $settings = apply_filters( 'wp_editor_settings', $settings, $editor_id );
79 $set = wp_parse_args( $settings, array(
81 'media_buttons' => true,
82 'default_editor' => '',
83 'drag_drop_upload' => false,
84 'textarea_name' => $editor_id,
85 'textarea_rows' => 20,
87 'tabfocus_elements' => ':prev,:next',
92 '_content_editor_dfw' => false,
97 self::$this_tinymce = ( $set['tinymce'] && user_can_richedit() );
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.' );
106 self::$this_quicktags = (bool) $set['quicktags'];
108 if ( self::$this_tinymce )
109 self::$has_tinymce = true;
111 if ( self::$this_quicktags )
112 self::$has_quicktags = true;
115 self::$old_dfw_compat = true;
118 if ( empty( $set['editor_height'] ) )
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' );
126 $set['editor_height'] = $cookie;
129 if ( $set['editor_height'] < 50 )
130 $set['editor_height'] = 50;
131 elseif ( $set['editor_height'] > 5000 )
132 $set['editor_height'] = 5000;
138 * Outputs the HTML for a single instance of the editor.
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.
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 );
153 if ( $set['drag_drop_upload'] ) {
154 self::$drag_drop_upload = true;
157 if ( ! empty( $set['editor_height'] ) ) {
158 $height = ' style="height: ' . (int) $set['editor_height'] . 'px"';
160 $height = ' rows="' . (int) $set['textarea_rows'] . '"';
163 if ( ! current_user_can( 'upload_files' ) ) {
164 $set['media_buttons'] = false;
167 if ( self::$this_tinymce ) {
168 $autocomplete = ' autocomplete="off"';
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';
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";
182 $default_editor = 'tinymce';
186 $switch_class = 'html' === $default_editor ? 'html-active' : 'tmce-active';
187 $wrap_class = 'wp-core-ui wp-editor-wrap ' . $switch_class;
189 if ( $set['_content_editor_dfw'] ) {
190 $wrap_class .= ' has-dfw';
193 echo '<div id="wp-' . $editor_id_attr . '-wrap" class="' . $wrap_class . '">';
195 if ( self::$editor_buttons_css ) {
196 wp_print_styles( 'editor-buttons' );
197 self::$editor_buttons_css = false;
200 if ( ! empty( $set['editor_css'] ) ) {
201 echo $set['editor_css'] . "\n";
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">';
207 if ( $set['media_buttons'] ) {
208 self::$has_medialib = true;
210 if ( ! function_exists( 'media_buttons' ) )
211 include( ABSPATH . 'wp-admin/includes/media.php' );
213 echo '<div id="wp-' . $editor_id_attr . '-media-buttons" class="wp-media-buttons">';
216 * Fires after the default media button(s) are displayed.
220 * @param string $editor_id Unique editor identifier, e.g. 'content'.
222 do_action( 'media_buttons', $editor_id );
226 echo '<div class="wp-editor-tabs">' . $buttons . "</div>\n";
230 $quicktags_toolbar = '';
232 if ( self::$this_quicktags ) {
233 if ( 'content' === $editor_id && ! empty( $GLOBALS['current_screen'] ) && $GLOBALS['current_screen']->base === 'post' ) {
234 $toolbar_id = 'ed_toolbar';
236 $toolbar_id = 'qt_' . $editor_id_attr . '_toolbar';
239 $quicktags_toolbar = '<div id="' . $toolbar_id . '" class="quicktags-toolbar"></div>';
243 * Filter the HTML markup output that displays the editor.
247 * @param string $output Editor's HTML markup.
249 $the_editor = apply_filters( 'the_editor', '<div id="wp-' . $editor_id_attr . '-editor-container" class="wp-editor-container">' .
251 '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . esc_attr( $set['textarea_name'] ) . '" ' .
252 'id="' . $editor_id_attr . '">%s</textarea></div>' );
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 );
260 * Filter the default editor content.
264 * @param string $content Default editor content.
265 * @param string $default_editor The default editor for the current user.
266 * Either 'html' or 'tinymce'.
268 $content = apply_filters( 'the_editor_content', $content, $default_editor );
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' );
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 );
285 if ( false !== stripos( $content, 'textarea' ) ) {
286 $content = preg_replace( '%</textarea%i', '</textarea', $content );
289 printf( $the_editor, $content );
292 self::editor_settings( $editor_id, $set );
298 * @global string $wp_version
299 * @global string $tinymce_version
301 * @param string $editor_id
304 public static function editor_settings($editor_id, $set) {
305 global $wp_version, $tinymce_version;
307 if ( empty(self::$first_init) ) {
309 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
310 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
312 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
313 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
317 if ( self::$this_quicktags ) {
324 if ( is_array($set['quicktags']) )
325 $qtInit = array_merge($qtInit, $set['quicktags']);
327 if ( empty($qtInit['buttons']) )
328 $qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close';
330 if ( $set['_content_editor_dfw'] ) {
331 $qtInit['buttons'] .= ',dfw';
335 * Filter the Quicktags settings.
339 * @param array $qtInit Quicktags settings.
340 * @param string $editor_id The unique editor ID, e.g. 'content'.
342 $qtInit = apply_filters( 'quicktags_settings', $qtInit, $editor_id );
344 self::$qt_settings[$editor_id] = $qtInit;
346 self::$qt_buttons = array_merge( self::$qt_buttons, explode(',', $qtInit['buttons']) );
349 if ( self::$this_tinymce ) {
351 if ( empty( self::$first_init ) ) {
352 self::$baseurl = includes_url( 'js/tinymce' );
354 $mce_locale = get_locale();
355 self::$mce_locale = $mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1
357 /** This filter is documented in wp-admin/includes/media.php */
358 $no_captions = (bool) apply_filters( 'disable_captions', '' );
361 if ( $set['teeny'] ) {
364 * Filter the list of teenyMCE plugins.
368 * @param array $plugins An array of teenyMCE plugins.
369 * @param string $editor_id Unique editor identifier, e.g. 'content'.
371 self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array( 'colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink' ), $editor_id );
375 * Filter the list of TinyMCE external plugins.
377 * The filter takes an associative array of external plugins for
378 * TinyMCE in the form 'plugin_name' => 'url'.
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'.
384 * If the external plugin adds a button, it should be added with
385 * one of the 'mce_buttons' filters.
389 * @param array $external_plugins An array of external TinyMCE plugins.
391 $mce_external_plugins = apply_filters( 'mce_external_plugins', array() );
415 if ( ! self::$has_medialib ) {
416 $plugins[] = 'image';
420 * Filter the list of default TinyMCE plugins.
422 * The filter specifies which of the default plugins included
423 * in WordPress should be added to the TinyMCE instance.
427 * @param array $plugins An array of default TinyMCE plugins.
429 $plugins = array_unique( apply_filters( 'tiny_mce_plugins', $plugins ) );
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] );
437 if ( ! empty( $mce_external_plugins ) ) {
440 * Filter the translations loaded for external TinyMCE 3.x plugins.
442 * The filter takes an associative array ('plugin_name' => 'path')
443 * where 'path' is the include path to the file.
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.
450 * @param array $translations Translations for external TinyMCE plugins.
452 $mce_external_languages = apply_filters( 'mce_external_languages', array() );
454 $loaded_langs = array();
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;
467 foreach ( $mce_external_plugins as $name => $url ) {
468 if ( in_array( $name, $plugins, true ) ) {
469 unset( $mce_external_plugins[ $name ] );
473 $url = set_url_scheme( $url );
474 $mce_external_plugins[ $name ] = $url;
475 $plugurl = dirname( $url );
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/';
483 if ( function_exists('realpath') )
484 $path = trailingslashit( realpath($path) );
486 if ( @is_file( $path . $mce_locale . '.js' ) )
487 $strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n";
489 if ( @is_file( $path . $mce_locale . '_dlg.js' ) )
490 $strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n";
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";
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";
504 if ( ! empty( $strings ) )
505 $ext_plugins .= "\n" . $strings . "\n";
508 $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
509 $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
514 self::$plugins = $plugins;
515 self::$ext_plugins = $ext_plugins;
517 self::$first_init = array(
519 'skin' => 'lightgray',
520 'language' => self::$mce_locale,
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"}' .
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"}' .
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"}' .
534 'strikethrough: {inline: "del"}' .
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,
546 // Limit the preview styles in the menu/toolbar
547 'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform',
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' )
556 if ( ! empty( $mce_external_plugins ) ) {
557 self::$first_init['external_plugins'] = wp_json_encode( $mce_external_plugins );
560 $suffix = SCRIPT_DEBUG ? '' : '.min';
561 $version = 'ver=' . $wp_version;
562 $dashicons = includes_url( "css/dashicons$suffix.css?$version" );
564 // WordPress default stylesheet and dashicons
567 self::$baseurl . '/skins/wordpress/wp-content.css?' . $version
570 $editor_styles = get_editor_stylesheets();
571 if ( ! empty( $editor_styles ) ) {
572 foreach ( $editor_styles as $style ) {
578 * Filter the comma-delimited list of stylesheets to load in TinyMCE.
582 * @param string $stylesheets Comma-delimited list of stylesheets.
584 $mce_css = trim( apply_filters( 'mce_css', implode( ',', $mce_css ) ), ' ,' );
586 if ( ! empty($mce_css) )
587 self::$first_init['content_css'] = $mce_css;
590 if ( $set['teeny'] ) {
593 * Filter the list of teenyMCE buttons (Text tab).
597 * @param array $buttons An array of teenyMCE buttons.
598 * @param string $editor_id Unique editor identifier, e.g. 'content'.
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();
603 $mce_buttons = array( 'bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker' );
605 if ( ! wp_is_mobile() ) {
606 if ( $set['_content_editor_dfw'] ) {
607 $mce_buttons[] = 'dfw';
609 $mce_buttons[] = 'fullscreen';
613 $mce_buttons[] = 'wp_adv';
616 * Filter the first-row list of TinyMCE buttons (Visual tab).
620 * @param array $buttons First-row list of buttons.
621 * @param string $editor_id Unique editor identifier, e.g. 'content'.
623 $mce_buttons = apply_filters( 'mce_buttons', $mce_buttons, $editor_id );
625 $mce_buttons_2 = array( 'formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo' );
627 if ( ! wp_is_mobile() ) {
628 $mce_buttons_2[] = 'wp_help';
632 * Filter the second-row list of TinyMCE buttons (Visual tab).
636 * @param array $buttons Second-row list of buttons.
637 * @param string $editor_id Unique editor identifier, e.g. 'content'.
639 $mce_buttons_2 = apply_filters( 'mce_buttons_2', $mce_buttons_2, $editor_id );
642 * Filter the third-row list of TinyMCE buttons (Visual tab).
646 * @param array $buttons Third-row list of buttons.
647 * @param string $editor_id Unique editor identifier, e.g. 'content'.
649 $mce_buttons_3 = apply_filters( 'mce_buttons_3', array(), $editor_id );
652 * Filter the fourth-row list of TinyMCE buttons (Visual tab).
656 * @param array $buttons Fourth-row list of buttons.
657 * @param string $editor_id Unique editor identifier, e.g. 'content'.
659 $mce_buttons_4 = apply_filters( 'mce_buttons_4', array(), $editor_id );
662 $body_class = $editor_id;
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 );
671 $body_class .= ' post-format-standard';
675 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
677 if ( !empty($set['tinymce']['body_class']) ) {
678 $body_class .= ' ' . $set['tinymce']['body_class'];
679 unset($set['tinymce']['body_class']);
683 'selector' => "#$editor_id",
684 'resize' => 'vertical',
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
696 // Merge with the first part of the init array
697 $mceInit = array_merge( self::$first_init, $mceInit );
699 if ( is_array( $set['tinymce'] ) )
700 $mceInit = array_merge( $mceInit, $set['tinymce'] );
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.
710 if ( $set['teeny'] ) {
713 * Filter the teenyMCE config before init.
717 * @param array $mceInit An array with teenyMCE config.
718 * @param string $editor_id Unique editor identifier, e.g. 'content'.
720 $mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
724 * Filter the TinyMCE config before init.
728 * @param array $mceInit An array with TinyMCE config.
729 * @param string $editor_id Unique editor identifier, e.g. 'content'.
731 $mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );
734 if ( empty( $mceInit['toolbar3'] ) && ! empty( $mceInit['toolbar4'] ) ) {
735 $mceInit['toolbar3'] = $mceInit['toolbar4'];
736 $mceInit['toolbar4'] = '';
739 self::$mce_settings[$editor_id] = $mceInit;
740 } // end if self::$this_tinymce
749 private static function _parse_init($init) {
752 foreach ( $init as $k => $v ) {
754 $val = $v ? 'true' : 'false';
755 $options .= $k . ':' . $val . ',';
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 . ',';
761 $options .= $k . ':"' . $v . '",';
764 return '{' . trim( $options, ' ,' ) . '}';
771 public static function enqueue_scripts() {
772 if ( self::$has_tinymce )
773 wp_enqueue_script('editor');
775 if ( self::$has_quicktags ) {
776 wp_enqueue_script( 'quicktags' );
777 wp_enqueue_style( 'buttons' );
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' );
785 if ( self::$old_dfw_compat ) {
786 wp_enqueue_script('wp-fullscreen-stub');
789 if ( self::$has_medialib ) {
791 wp_enqueue_script('media-upload');
795 * Fires when scripts and styles are enqueued for the editor.
799 * @param array $to_load An array containing boolean values whether TinyMCE
800 * and Quicktags are being loaded.
802 do_action( 'wp_enqueue_editor', array(
803 'tinymce' => self::$has_tinymce,
804 'quicktags' => self::$has_quicktags,
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.
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.
817 public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
819 $mce_translation = array(
820 // Default TinyMCE strings
821 'New document' => __( 'New document' ),
822 'Formats' => _x( 'Formats', 'TinyMCE' ),
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' ),
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' ),
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' ),
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' ),
861 'Cut' => __( 'Cut' ),
862 'Copy' => __( 'Copy' ),
863 'Paste' => __( 'Paste' ),
864 'Select all' => __( 'Select all' ),
865 'Undo' => __( 'Undo' ),
866 'Redo' => __( 'Redo' ),
869 'Cancel' => __( 'Cancel' ),
870 'Close' => __( 'Close' ),
871 'Visual aids' => __( 'Visual aids' ),
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' ),
886 'Name' => _x( 'Name', 'Name of link anchor (TinyMCE)' ),
887 'Anchor' => _x( 'Anchor', 'Link anchor (TinyMCE)' ),
888 'Anchors' => _x( 'Anchors', 'Link anchors (TinyMCE)' ),
891 'Document properties' => __( 'Document properties' ),
892 'Robots' => __( 'Robots' ),
893 'Title' => __( 'Title' ),
894 'Keywords' => __( 'Keywords' ),
895 'Encoding' => __( 'Encoding' ),
896 'Description' => __( 'Description' ),
897 'Author' => __( 'Author' ),
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' ),
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' ),
937 'Color' => __( 'Color' ),
938 'Custom color' => __( 'Custom color' ),
939 'Custom...' => _x( 'Custom...', 'label for custom color' ), // no ellipsis
940 'No color' => __( 'No color' ),
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' ),
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' ),
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' ),
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' ),
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' ),
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' ),
1013 'Insert template' => _x( 'Insert template', 'TinyMCE' ),
1014 'Templates' => _x( 'Templates', 'TinyMCE' ),
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' ),
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’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’s edit menu instead.' ),
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' ),
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
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.' ),
1076 * Link plugin (not included):
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?
1086 if ( ! $mce_locale ) {
1087 $mce_locale = self::$mce_locale;
1091 * Filter translated strings prepared for TinyMCE.
1095 * @param array $mce_translation Key/value pairs of strings.
1096 * @param string $mce_locale Locale.
1098 $mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale );
1100 foreach ( $mce_translation as $key => $value ) {
1101 // Remove strings that are not translated.
1102 if ( $key === $value ) {
1103 unset( $mce_translation[$key] );
1107 if ( false !== strpos( $value, '&' ) ) {
1108 $mce_translation[$key] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
1114 $mce_translation['_dir'] = 'rtl';
1118 return wp_json_encode( $mce_translation );
1121 $baseurl = self::$baseurl ? self::$baseurl : includes_url( 'js/tinymce' );
1123 return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
1124 "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
1130 * @global string $wp_version
1131 * @global string $tinymce_version
1132 * @global bool $concatenate_scripts
1133 * @global bool $compress_scripts
1135 public static function editor_js() {
1136 global $wp_version, $tinymce_version, $concatenate_scripts, $compress_scripts;
1139 * Filter "tiny_mce_version" is deprecated
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).
1145 $version = 'ver=' . $tinymce_version;
1146 $tmce_on = !empty(self::$mce_settings);
1148 if ( ! isset($concatenate_scripts) )
1149 script_concat_settings();
1151 $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
1152 && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
1154 $mceInit = $qtInit = '';
1156 foreach ( self::$mce_settings as $editor_id => $init ) {
1157 $options = self::_parse_init( $init );
1158 $mceInit .= "'$editor_id':{$options},";
1160 $mceInit = '{' . trim($mceInit, ',') . '}';
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},";
1170 $qtInit = '{' . trim($qtInit, ',') . '}';
1176 'plugins' => implode( ',', self::$plugins ),
1177 'theme' => 'modern',
1178 'language' => self::$mce_locale
1181 $suffix = SCRIPT_DEBUG ? '' : '.min';
1184 * Fires immediately before the TinyMCE settings are printed.
1188 * @param array $mce_settings TinyMCE settings array.
1190 do_action( 'before_wp_tiny_mce', self::$mce_settings );
1193 <script type="text/javascript">
1195 baseURL: "<?php echo self::$baseurl; ?>",
1196 suffix: "<?php echo $suffix; ?>",
1199 if ( self::$drag_drop_upload ) {
1200 echo 'dragDropUpload: true,';
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');}
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';
1217 if ( $compressed ) {
1218 echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&$version'></script>\n";
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";
1224 echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";
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";
1233 * Fires after tinymce.js is loaded, but before any TinyMCE editor
1234 * instances are created.
1238 * @param array $mce_settings TinyMCE settings array.
1240 do_action( 'wp_tiny_mce_init', self::$mce_settings );
1243 <script type="text/javascript">
1246 if ( self::$ext_plugins )
1247 echo self::$ext_plugins . "\n";
1250 echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
1255 var init, id, $wrap;
1257 if ( typeof tinymce !== 'undefined' ) {
1258 for ( id in tinyMCEPreInit.mceInit ) {
1259 init = tinyMCEPreInit.mceInit[id];
1260 $wrap = tinymce.$( '#wp-' + id + '-wrap' );
1262 if ( ( $wrap.hasClass( 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( id ) ) && ! init.wp_skip_init ) {
1263 tinymce.init( init );
1265 if ( ! window.wpActiveEditor ) {
1266 window.wpActiveEditor = id;
1272 if ( typeof quicktags !== 'undefined' ) {
1273 for ( id in tinyMCEPreInit.qtInit ) {
1274 quicktags( tinyMCEPreInit.qtInit[id] );
1276 if ( ! window.wpActiveEditor ) {
1277 window.wpActiveEditor = id;
1285 if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) )
1286 self::wp_link_dialog();
1289 * Fires after any core TinyMCE editor instances are created.
1293 * @param array $mce_settings TinyMCE settings array.
1295 do_action( 'after_wp_tiny_mce', self::$mce_settings );
1301 * @global int $content_width
1303 public static function wp_fullscreen_html() {
1304 _deprecated_function( __FUNCTION__, '4.3' );
1308 * Performs post queries for internal linking.
1313 * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
1314 * @return false|array Results.
1316 public static function wp_link_query( $args = array() ) {
1317 $pts = get_post_types( array( 'public' => true ), 'objects' );
1318 $pt_names = array_keys( $pts );
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,
1329 $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
1331 if ( isset( $args['s'] ) )
1332 $query['s'] = $args['s'];
1334 $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
1337 * Filter the link query arguments.
1339 * Allows modification of the link query arguments before querying.
1341 * @see WP_Query for a full list of arguments
1345 * @param array $query An array of WP_Query arguments.
1347 $query = apply_filters( 'wp_link_query_args', $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 )
1358 foreach ( $posts as $post ) {
1359 if ( 'post' == $post->post_type )
1360 $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
1362 $info = $pts[ $post->post_type ]->labels->singular_name;
1366 'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
1367 'permalink' => get_permalink( $post->ID ),
1373 * Filter the link query results.
1375 * Allows modification of the returned link query results.
1379 * @see 'wp_link_query_args' filter
1381 * @param array $results {
1382 * An associative array of query results.
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.
1392 * @param array $query An array of WP_Query arguments.
1394 return apply_filters( 'wp_link_query', $results, $query );
1398 * Dialog for internal linking.
1404 public static function wp_link_dialog() {
1405 // display: none is required here, see #WP27605
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>
1417 <label><span><?php _e( 'URL' ); ?></span>
1418 <input id="wp-link-url" type="text" aria-describedby="wplink-enter-url" /></label>
1420 <div class="wp-link-text-field">
1421 <label><span><?php _e( 'Link Text' ); ?></span>
1422 <input id="wp-link-text" type="text" /></label>
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>
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">
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>
1438 <div id="search-results" class="query-results" tabindex="0">
1440 <div class="river-waiting">
1441 <span class="spinner"></span>
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>
1450 <div class="river-waiting">
1451 <span class="spinner"></span>
1456 <div class="submitbox">
1457 <div id="wp-link-cancel">
1458 <button type="button" class="button"><?php _e( 'Cancel' ); ?></button>
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">