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;
29 private function __construct() {}
32 * Parse default arguments for the editor instance.
34 * @param string $editor_id ID for the current editor instance.
35 * @param array $settings {
36 * Array of editor arguments.
38 * @type bool $wpautop Whether to use wpautop(). Default true.
39 * @type bool $media_buttons Whether to show the Add Media/other media buttons.
40 * @type string $default_editor When both TinyMCE and Quicktags are used, set which
41 * editor is shown on page load. Default empty.
42 * @type bool $drag_drop_upload Whether to enable drag & drop on the editor uploading. Default false.
43 * Requires the media modal.
44 * @type string $textarea_name Give the textarea a unique name here. Square brackets
45 * can be used here. Default $editor_id.
46 * @type int $textarea_rows Number rows in the editor textarea. Default 20.
47 * @type string|int $tabindex Tabindex value to use. Default empty.
48 * @type string $tabfocus_elements The previous and next element ID to move the focus to
49 * when pressing the Tab key in TinyMCE. Defualt ':prev,:next'.
50 * @type string $editor_css Intended for extra styles for both Visual and Text editors.
51 * Should include `<style>` tags, and can use "scoped". Default empty.
52 * @type string $editor_class Extra classes to add to the editor textarea elemen. Default empty.
53 * @type bool $teeny Whether to output the minimal editor config. Examples include
54 * Press This and the Comment editor. Default false.
55 * @type bool $dfw Whether to replace the default fullscreen with "Distraction Free
56 * Writing". DFW requires specific DOM elements and css). Default false.
57 * @type bool|array $tinymce Whether to load TinyMCE. Can be used to pass settings directly to
58 * TinyMCE using an array. Default true.
59 * @type bool|array $quicktags Whether to load Quicktags. Can be used to pass settings directly to
60 * Quicktags using an array. Default true.
62 * @return array Parsed arguments array.
64 public static function parse_settings( $editor_id, $settings ) {
67 * Filter the wp_editor() settings.
71 * @see _WP_Editors()::parse_settings()
73 * @param array $settings Array of editor arguments.
74 * @param string $editor_id ID for the current editor instance.
76 $settings = apply_filters( 'wp_editor_settings', $settings, $editor_id );
78 $set = wp_parse_args( $settings, array(
80 'media_buttons' => true,
81 'default_editor' => '',
82 'drag_drop_upload' => false,
83 'textarea_name' => $editor_id,
84 'textarea_rows' => 20,
86 'tabfocus_elements' => ':prev,:next',
91 '_content_editor_dfw' => false,
96 self::$this_tinymce = ( $set['tinymce'] && user_can_richedit() );
98 if ( self::$this_tinymce ) {
99 if ( false !== strpos( $editor_id, '[' ) ) {
100 self::$this_tinymce = false;
101 _deprecated_argument( 'wp_editor()', '3.9', 'TinyMCE editor IDs cannot have brackets.' );
105 self::$this_quicktags = (bool) $set['quicktags'];
107 if ( self::$this_tinymce )
108 self::$has_tinymce = true;
110 if ( self::$this_quicktags )
111 self::$has_quicktags = true;
113 if ( empty( $set['editor_height'] ) )
116 if ( 'content' === $editor_id && empty( $set['tinymce']['wp_autoresize_on'] ) ) {
117 // A cookie (set when a user resizes the editor) overrides the height.
118 $cookie = (int) get_user_setting( 'ed_size' );
121 $set['editor_height'] = $cookie;
124 if ( $set['editor_height'] < 50 )
125 $set['editor_height'] = 50;
126 elseif ( $set['editor_height'] > 5000 )
127 $set['editor_height'] = 5000;
133 * Outputs the HTML for a single instance of the editor.
135 * @param string $content The initial content of the editor.
136 * @param string $editor_id ID for the textarea and TinyMCE and Quicktags instances (can contain only ASCII letters and numbers).
137 * @param array $settings See the _parse_settings() method for description.
139 public static function editor( $content, $editor_id, $settings = array() ) {
141 $set = self::parse_settings( $editor_id, $settings );
142 $editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"';
143 $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
144 $switch_class = 'html-active';
145 $toolbar = $buttons = $autocomplete = '';
147 if ( $set['drag_drop_upload'] ) {
148 self::$drag_drop_upload = true;
151 if ( ! empty( $set['editor_height'] ) )
152 $height = ' style="height: ' . $set['editor_height'] . 'px"';
154 $height = ' rows="' . $set['textarea_rows'] . '"';
156 if ( !current_user_can( 'upload_files' ) )
157 $set['media_buttons'] = false;
159 if ( ! self::$this_quicktags && self::$this_tinymce ) {
160 $switch_class = 'tmce-active';
161 $autocomplete = ' autocomplete="off"';
162 } elseif ( self::$this_quicktags && self::$this_tinymce ) {
163 $default_editor = $set['default_editor'] ? $set['default_editor'] : wp_default_editor();
164 $autocomplete = ' autocomplete="off"';
166 // 'html' is used for the "Text" editor tab.
167 if ( 'html' === $default_editor ) {
168 add_filter('the_editor_content', 'wp_htmledit_pre');
169 $switch_class = 'html-active';
171 add_filter('the_editor_content', 'wp_richedit_pre');
172 $switch_class = 'tmce-active';
175 $buttons .= '<button type="button" id="' . $editor_id . '-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">' . __('Visual') . "</button>\n";
176 $buttons .= '<button type="button" id="' . $editor_id . '-html" class="wp-switch-editor switch-html" onclick="switchEditors.switchto(this);">' . _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ) . "</button>\n";
179 $wrap_class = 'wp-core-ui wp-editor-wrap ' . $switch_class;
181 if ( $set['_content_editor_dfw'] ) {
182 $wrap_class .= ' has-dfw';
185 echo '<div id="wp-' . $editor_id . '-wrap" class="' . $wrap_class . '">';
187 if ( self::$editor_buttons_css ) {
188 wp_print_styles('editor-buttons');
189 self::$editor_buttons_css = false;
192 if ( !empty($set['editor_css']) )
193 echo $set['editor_css'] . "\n";
195 if ( !empty($buttons) || $set['media_buttons'] ) {
196 echo '<div id="wp-' . $editor_id . '-editor-tools" class="wp-editor-tools hide-if-no-js">';
198 if ( $set['media_buttons'] ) {
199 self::$has_medialib = true;
201 if ( !function_exists('media_buttons') )
202 include(ABSPATH . 'wp-admin/includes/media.php');
204 echo '<div id="wp-' . $editor_id . '-media-buttons" class="wp-media-buttons">';
207 * Fires after the default media button(s) are displayed.
211 * @param string $editor_id Unique editor identifier, e.g. 'content'.
213 do_action( 'media_buttons', $editor_id );
217 echo '<div class="wp-editor-tabs">' . $buttons . "</div>\n";
222 * Filter the HTML markup output that displays the editor.
226 * @param string $output Editor's HTML markup.
228 $the_editor = apply_filters( 'the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container">' .
229 '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . $set['textarea_name'] . '" ' .
230 'id="' . $editor_id . '">%s</textarea></div>' );
233 * Filter the default editor content.
237 * @param string $content Default editor content.
239 $content = apply_filters( 'the_editor_content', $content );
241 printf( $the_editor, $content );
244 self::editor_settings($editor_id, $set);
248 * @param string $editor_id
251 public static function editor_settings($editor_id, $set) {
254 if ( empty(self::$first_init) ) {
256 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
257 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
259 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
260 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
264 if ( self::$this_quicktags ) {
271 if ( is_array($set['quicktags']) )
272 $qtInit = array_merge($qtInit, $set['quicktags']);
274 if ( empty($qtInit['buttons']) )
275 $qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close';
278 $qtInit['buttons'] .= ',fullscreen';
280 if ( $set['_content_editor_dfw'] ) {
281 $qtInit['buttons'] .= ',dfw';
285 * Filter the Quicktags settings.
289 * @param array $qtInit Quicktags settings.
290 * @param string $editor_id The unique editor ID, e.g. 'content'.
292 $qtInit = apply_filters( 'quicktags_settings', $qtInit, $editor_id );
294 self::$qt_settings[$editor_id] = $qtInit;
296 self::$qt_buttons = array_merge( self::$qt_buttons, explode(',', $qtInit['buttons']) );
299 if ( self::$this_tinymce ) {
301 if ( empty( self::$first_init ) ) {
302 self::$baseurl = includes_url( 'js/tinymce' );
304 $mce_locale = get_locale();
305 self::$mce_locale = $mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1
307 /** This filter is documented in wp-admin/includes/media.php */
308 $no_captions = (bool) apply_filters( 'disable_captions', '' );
312 if ( $set['teeny'] ) {
315 * Filter the list of teenyMCE plugins.
319 * @param array $plugins An array of teenyMCE plugins.
320 * @param string $editor_id Unique editor identifier, e.g. 'content'.
322 self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array( 'colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink' ), $editor_id );
326 * Filter the list of TinyMCE external plugins.
328 * The filter takes an associative array of external plugins for
329 * TinyMCE in the form 'plugin_name' => 'url'.
331 * The url should be absolute, and should include the js filename
332 * to be loaded. For example:
333 * 'myplugin' => 'http://mysite.com/wp-content/plugins/myfolder/mce_plugin.js'.
335 * If the external plugin adds a button, it should be added with
336 * one of the 'mce_buttons' filters.
340 * @param array $external_plugins An array of external TinyMCE plugins.
342 $mce_external_plugins = apply_filters( 'mce_external_plugins', array() );
364 if ( ! self::$has_medialib ) {
365 $plugins[] = 'image';
369 * Filter the list of default TinyMCE plugins.
371 * The filter specifies which of the default plugins included
372 * in WordPress should be added to the TinyMCE instance.
376 * @param array $plugins An array of default TinyMCE plugins.
378 $plugins = array_unique( apply_filters( 'tiny_mce_plugins', $plugins ) );
380 if ( ( $key = array_search( 'spellchecker', $plugins ) ) !== false ) {
381 // Remove 'spellchecker' from the internal plugins if added with 'tiny_mce_plugins' filter to prevent errors.
382 // It can be added with 'mce_external_plugins'.
383 unset( $plugins[$key] );
386 if ( ! empty( $mce_external_plugins ) ) {
389 * Filter the translations loaded for external TinyMCE 3.x plugins.
391 * The filter takes an associative array ('plugin_name' => 'path')
392 * where 'path' is the include path to the file.
394 * The language file should follow the same format as wp_mce_translation(),
395 * and should define a variable ($strings) that holds all translated strings.
399 * @param array $translations Translations for external TinyMCE plugins.
401 $mce_external_languages = apply_filters( 'mce_external_languages', array() );
403 $loaded_langs = array();
406 if ( ! empty( $mce_external_languages ) ) {
407 foreach ( $mce_external_languages as $name => $path ) {
408 if ( @is_file( $path ) && @is_readable( $path ) ) {
409 include_once( $path );
410 $ext_plugins .= $strings . "\n";
411 $loaded_langs[] = $name;
416 foreach ( $mce_external_plugins as $name => $url ) {
417 if ( in_array( $name, $plugins, true ) ) {
418 unset( $mce_external_plugins[ $name ] );
422 $url = set_url_scheme( $url );
423 $mce_external_plugins[ $name ] = $url;
424 $plugurl = dirname( $url );
427 // Try to load langs/[locale].js and langs/[locale]_dlg.js
428 if ( ! in_array( $name, $loaded_langs, true ) ) {
429 $path = str_replace( content_url(), '', $plugurl );
430 $path = WP_CONTENT_DIR . $path . '/langs/';
432 if ( function_exists('realpath') )
433 $path = trailingslashit( realpath($path) );
435 if ( @is_file( $path . $mce_locale . '.js' ) )
436 $strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n";
438 if ( @is_file( $path . $mce_locale . '_dlg.js' ) )
439 $strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n";
441 if ( 'en' != $mce_locale && empty( $strings ) ) {
442 if ( @is_file( $path . 'en.js' ) ) {
443 $str1 = @file_get_contents( $path . 'en.js' );
444 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
447 if ( @is_file( $path . 'en_dlg.js' ) ) {
448 $str2 = @file_get_contents( $path . 'en_dlg.js' );
449 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";
453 if ( ! empty( $strings ) )
454 $ext_plugins .= "\n" . $strings . "\n";
457 $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
458 $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
464 $plugins[] = 'wpfullscreen';
466 self::$plugins = $plugins;
467 self::$ext_plugins = $ext_plugins;
469 self::$first_init = array(
471 'skin' => 'lightgray',
472 'language' => self::$mce_locale,
475 {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles: {textAlign:'left'}},
476 {selector: 'img,table,dl.wp-caption', classes: 'alignleft'}
479 {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles: {textAlign:'center'}},
480 {selector: 'img,table,dl.wp-caption', classes: 'aligncenter'}
483 {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles: {textAlign:'right'}},
484 {selector: 'img,table,dl.wp-caption', classes: 'alignright'}
486 strikethrough: {inline: 'del'}
488 'relative_urls' => false,
489 'remove_script_host' => false,
490 'convert_urls' => false,
491 'browser_spellcheck' => true,
492 'fix_list_elements' => true,
493 'entities' => '38,amp,60,lt,62,gt',
494 'entity_encoding' => 'raw',
495 'keep_styles' => false,
496 'cache_suffix' => 'wp-mce-' . $GLOBALS['tinymce_version'],
498 // Limit the preview styles in the menu/toolbar
499 'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform',
501 'end_container_on_empty_block' => true,
502 'wpeditimage_disable_captions' => $no_captions,
503 'wpeditimage_html5_captions' => current_theme_supports( 'html5', 'caption' ),
504 'plugins' => implode( ',', $plugins ),
507 if ( ! empty( $mce_external_plugins ) ) {
508 self::$first_init['external_plugins'] = wp_json_encode( $mce_external_plugins );
511 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
512 $version = 'ver=' . $GLOBALS['wp_version'];
513 $dashicons = includes_url( "css/dashicons$suffix.css?$version" );
515 // WordPress default stylesheet and dashicons
518 self::$baseurl . '/skins/wordpress/wp-content.css?' . $version
521 $editor_styles = get_editor_stylesheets();
522 if ( ! empty( $editor_styles ) ) {
523 foreach ( $editor_styles as $style ) {
529 * Filter the comma-delimited list of stylesheets to load in TinyMCE.
533 * @param array $stylesheets Comma-delimited list of stylesheets.
535 $mce_css = trim( apply_filters( 'mce_css', implode( ',', $mce_css ) ), ' ,' );
537 if ( ! empty($mce_css) )
538 self::$first_init['content_css'] = $mce_css;
541 if ( $set['teeny'] ) {
544 * Filter the list of teenyMCE buttons (Text tab).
548 * @param array $buttons An array of teenyMCE buttons.
549 * @param string $editor_id Unique editor identifier, e.g. 'content'.
551 $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 );
552 $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
554 $mce_buttons = array( 'bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker' );
556 if ( $set['_content_editor_dfw'] ) {
557 $mce_buttons[] = 'dfw';
559 $mce_buttons[] = 'fullscreen';
562 $mce_buttons[] = 'wp_adv';
565 * Filter the first-row list of TinyMCE buttons (Visual tab).
569 * @param array $buttons First-row list of buttons.
570 * @param string $editor_id Unique editor identifier, e.g. 'content'.
572 $mce_buttons = apply_filters( 'mce_buttons', $mce_buttons, $editor_id );
574 $mce_buttons_2 = array( 'formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo' );
576 if ( ! wp_is_mobile() ) {
577 $mce_buttons_2[] = 'wp_help';
581 * Filter the second-row list of TinyMCE buttons (Visual tab).
585 * @param array $buttons Second-row list of buttons.
586 * @param string $editor_id Unique editor identifier, e.g. 'content'.
588 $mce_buttons_2 = apply_filters( 'mce_buttons_2', $mce_buttons_2, $editor_id );
591 * Filter the third-row list of TinyMCE buttons (Visual tab).
595 * @param array $buttons Third-row list of buttons.
596 * @param string $editor_id Unique editor identifier, e.g. 'content'.
598 $mce_buttons_3 = apply_filters( 'mce_buttons_3', array(), $editor_id );
601 * Filter the fourth-row list of TinyMCE buttons (Visual tab).
605 * @param array $buttons Fourth-row list of buttons.
606 * @param string $editor_id Unique editor identifier, e.g. 'content'.
608 $mce_buttons_4 = apply_filters( 'mce_buttons_4', array(), $editor_id );
611 $body_class = $editor_id;
613 if ( $post = get_post() ) {
614 $body_class .= ' post-type-' . sanitize_html_class( $post->post_type ) . ' post-status-' . sanitize_html_class( $post->post_status );
615 if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
616 $post_format = get_post_format( $post );
617 if ( $post_format && ! is_wp_error( $post_format ) )
618 $body_class .= ' post-format-' . sanitize_html_class( $post_format );
620 $body_class .= ' post-format-standard';
624 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
626 if ( !empty($set['tinymce']['body_class']) ) {
627 $body_class .= ' ' . $set['tinymce']['body_class'];
628 unset($set['tinymce']['body_class']);
632 // replace the first 'fullscreen' with 'wp_fullscreen'
633 if ( ($key = array_search('fullscreen', $mce_buttons)) !== false )
634 $mce_buttons[$key] = 'wp_fullscreen';
635 elseif ( ($key = array_search('fullscreen', $mce_buttons_2)) !== false )
636 $mce_buttons_2[$key] = 'wp_fullscreen';
637 elseif ( ($key = array_search('fullscreen', $mce_buttons_3)) !== false )
638 $mce_buttons_3[$key] = 'wp_fullscreen';
639 elseif ( ($key = array_search('fullscreen', $mce_buttons_4)) !== false )
640 $mce_buttons_4[$key] = 'wp_fullscreen';
644 'selector' => "#$editor_id",
645 'resize' => 'vertical',
647 'wpautop' => (bool) $set['wpautop'],
648 'indent' => ! $set['wpautop'],
649 'toolbar1' => implode($mce_buttons, ','),
650 'toolbar2' => implode($mce_buttons_2, ','),
651 'toolbar3' => implode($mce_buttons_3, ','),
652 'toolbar4' => implode($mce_buttons_4, ','),
653 'tabfocus_elements' => $set['tabfocus_elements'],
654 'body_class' => $body_class
658 $mceInit = array_merge( self::$first_init, $mceInit );
660 if ( is_array( $set['tinymce'] ) )
661 $mceInit = array_merge( $mceInit, $set['tinymce'] );
664 * For people who really REALLY know what they're doing with TinyMCE
665 * You can modify $mceInit to add, remove, change elements of the config
666 * before tinyMCE.init. Setting "valid_elements", "invalid_elements"
667 * and "extended_valid_elements" can be done through this filter. Best
668 * is to use the default cleanup by not specifying valid_elements,
669 * as TinyMCE contains full set of XHTML 1.0.
671 if ( $set['teeny'] ) {
674 * Filter the teenyMCE config before init.
678 * @param array $mceInit An array with teenyMCE config.
679 * @param string $editor_id Unique editor identifier, e.g. 'content'.
681 $mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
685 * Filter the TinyMCE config before init.
689 * @param array $mceInit An array with TinyMCE config.
690 * @param string $editor_id Unique editor identifier, e.g. 'content'.
692 $mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );
695 if ( empty( $mceInit['toolbar3'] ) && ! empty( $mceInit['toolbar4'] ) ) {
696 $mceInit['toolbar3'] = $mceInit['toolbar4'];
697 $mceInit['toolbar4'] = '';
700 self::$mce_settings[$editor_id] = $mceInit;
701 } // end if self::$this_tinymce
704 private static function _parse_init($init) {
707 foreach ( $init as $k => $v ) {
709 $val = $v ? 'true' : 'false';
710 $options .= $k . ':' . $val . ',';
712 } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {
713 $options .= $k . ':' . $v . ',';
716 $options .= $k . ':"' . $v . '",';
719 return '{' . trim( $options, ' ,' ) . '}';
722 public static function enqueue_scripts() {
723 wp_enqueue_script('word-count');
725 if ( self::$has_tinymce )
726 wp_enqueue_script('editor');
728 if ( self::$has_quicktags ) {
729 wp_enqueue_script( 'quicktags' );
730 wp_enqueue_style( 'buttons' );
733 if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {
734 wp_enqueue_script('wplink');
737 if ( in_array('wpfullscreen', self::$plugins, true) || in_array('fullscreen', self::$qt_buttons, true) )
738 wp_enqueue_script('wp-fullscreen');
740 if ( self::$has_medialib ) {
742 wp_enqueue_script('media-upload');
746 * Fires when scripts and styles are enqueued for the editor.
750 * @param array $to_load An array containing boolean values whether TinyMCE
751 * and Quicktags are being loaded.
753 do_action( 'wp_enqueue_editor', array(
754 'tinymce' => self::$has_tinymce,
755 'quicktags' => self::$has_quicktags,
760 * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
761 * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
763 * @param string $mce_locale The locale used for the editor.
764 * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
765 * @return string Translation object, JSON encoded.
767 public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
769 $mce_translation = array(
770 // Default TinyMCE strings
771 'New document' => __( 'New document' ),
772 'Formats' => _x( 'Formats', 'TinyMCE' ),
774 'Headings' => _x( 'Headings', 'TinyMCE' ),
775 'Heading 1' => __( 'Heading 1' ),
776 'Heading 2' => __( 'Heading 2' ),
777 'Heading 3' => __( 'Heading 3' ),
778 'Heading 4' => __( 'Heading 4' ),
779 'Heading 5' => __( 'Heading 5' ),
780 'Heading 6' => __( 'Heading 6' ),
782 /* translators: block tags */
783 'Blocks' => _x( 'Blocks', 'TinyMCE' ),
784 'Paragraph' => __( 'Paragraph' ),
785 'Blockquote' => __( 'Blockquote' ),
786 'Div' => _x( 'Div', 'HTML tag' ),
787 'Pre' => _x( 'Pre', 'HTML tag' ),
788 'Address' => _x( 'Address', 'HTML tag' ),
790 'Inline' => _x( 'Inline', 'HTML elements' ),
791 'Underline' => __( 'Underline' ),
792 'Strikethrough' => __( 'Strikethrough' ),
793 'Subscript' => __( 'Subscript' ),
794 'Superscript' => __( 'Superscript' ),
795 'Clear formatting' => __( 'Clear formatting' ),
796 'Bold' => __( 'Bold' ),
797 'Italic' => __( 'Italic' ),
798 'Code' => _x( 'Code', 'editor button' ),
799 'Source code' => __( 'Source code' ),
800 'Font Family' => __( 'Font Family' ),
801 'Font Sizes' => __( 'Font Sizes' ),
803 'Align center' => __( 'Align center' ),
804 'Align right' => __( 'Align right' ),
805 'Align left' => __( 'Align left' ),
806 'Justify' => __( 'Justify' ),
807 'Increase indent' => __( 'Increase indent' ),
808 'Decrease indent' => __( 'Decrease indent' ),
810 'Cut' => __( 'Cut' ),
811 'Copy' => __( 'Copy' ),
812 'Paste' => __( 'Paste' ),
813 'Select all' => __( 'Select all' ),
814 'Undo' => __( 'Undo' ),
815 'Redo' => __( 'Redo' ),
818 'Cancel' => __( 'Cancel' ),
819 'Close' => __( 'Close' ),
820 'Visual aids' => __( 'Visual aids' ),
822 'Bullet list' => __( 'Bulleted list' ),
823 'Numbered list' => __( 'Numbered list' ),
824 'Square' => _x( 'Square', 'list style' ),
825 'Default' => _x( 'Default', 'list style' ),
826 'Circle' => _x( 'Circle', 'list style' ),
827 'Disc' => _x('Disc', 'list style' ),
828 'Lower Greek' => _x( 'Lower Greek', 'list style' ),
829 'Lower Alpha' => _x( 'Lower Alpha', 'list style' ),
830 'Upper Alpha' => _x( 'Upper Alpha', 'list style' ),
831 'Upper Roman' => _x( 'Upper Roman', 'list style' ),
832 'Lower Roman' => _x( 'Lower Roman', 'list style' ),
835 'Name' => _x( 'Name', 'Name of link anchor (TinyMCE)' ),
836 'Anchor' => _x( 'Anchor', 'Link anchor (TinyMCE)' ),
837 'Anchors' => _x( 'Anchors', 'Link anchors (TinyMCE)' ),
840 'Document properties' => __( 'Document properties' ),
841 'Robots' => __( 'Robots' ),
842 'Title' => __( 'Title' ),
843 'Keywords' => __( 'Keywords' ),
844 'Encoding' => __( 'Encoding' ),
845 'Description' => __( 'Description' ),
846 'Author' => __( 'Author' ),
848 // Media, image plugins
849 'Insert/edit image' => __( 'Insert/edit image' ),
850 'General' => __( 'General' ),
851 'Advanced' => __( 'Advanced' ),
852 'Source' => __( 'Source' ),
853 'Border' => __( 'Border' ),
854 'Constrain proportions' => __( 'Constrain proportions' ),
855 'Vertical space' => __( 'Vertical space' ),
856 'Image description' => __( 'Image description' ),
857 'Style' => __( 'Style' ),
858 'Dimensions' => __( 'Dimensions' ),
859 'Insert image' => __( 'Insert image' ),
860 'Insert date/time' => __( 'Insert date/time' ),
861 'Insert/edit video' => __( 'Insert/edit video' ),
862 'Poster' => __( 'Poster' ),
863 'Alternative source' => __( 'Alternative source' ),
864 'Paste your embed code below:' => __( 'Paste your embed code below:' ),
865 'Insert video' => __( 'Insert video' ),
866 'Embed' => __( 'Embed' ),
868 // Each of these have a corresponding plugin
869 'Special character' => __( 'Special character' ),
870 'Right to left' => _x( 'Right to left', 'editor button' ),
871 'Left to right' => _x( 'Left to right', 'editor button' ),
872 'Emoticons' => __( 'Emoticons' ),
873 'Nonbreaking space' => __( 'Nonbreaking space' ),
874 'Page break' => __( 'Page break' ),
875 'Paste as text' => __( 'Paste as text' ),
876 'Preview' => __( 'Preview' ),
877 'Print' => __( 'Print' ),
878 'Save' => __( 'Save' ),
879 'Fullscreen' => __( 'Fullscreen' ),
880 'Horizontal line' => __( 'Horizontal line' ),
881 'Horizontal space' => __( 'Horizontal space' ),
882 'Restore last draft' => __( 'Restore last draft' ),
883 'Insert/edit link' => __( 'Insert/edit link' ),
884 'Remove link' => __( 'Remove link' ),
886 'Color' => __( 'Color' ),
887 'Custom color' => __( 'Custom color' ),
888 'Custom...' => _x( 'Custom...', 'label for custom color' ),
889 'No color' => __( 'No color' ),
891 // Spelling, search/replace plugins
892 'Could not find the specified string.' => __( 'Could not find the specified string.' ),
893 'Replace' => _x( 'Replace', 'find/replace' ),
894 'Next' => _x( 'Next', 'find/replace' ),
895 /* translators: previous */
896 'Prev' => _x( 'Prev', 'find/replace' ),
897 'Whole words' => _x( 'Whole words', 'find/replace' ),
898 'Find and replace' => __( 'Find and replace' ),
899 'Replace with' => _x('Replace with', 'find/replace' ),
900 'Find' => _x( 'Find', 'find/replace' ),
901 'Replace all' => _x( 'Replace all', 'find/replace' ),
902 'Match case' => __( 'Match case' ),
903 'Spellcheck' => __( 'Check Spelling' ),
904 'Finish' => _x( 'Finish', 'spellcheck' ),
905 'Ignore all' => _x( 'Ignore all', 'spellcheck' ),
906 'Ignore' => _x( 'Ignore', 'spellcheck' ),
907 'Add to Dictionary' => __( 'Add to Dictionary' ),
910 'Insert table' => __( 'Insert table' ),
911 'Delete table' => __( 'Delete table' ),
912 'Table properties' => __( 'Table properties' ),
913 'Row properties' => __( 'Table row properties' ),
914 'Cell properties' => __( 'Table cell properties' ),
915 'Border color' => __( 'Border color' ),
917 'Row' => __( 'Row' ),
918 'Rows' => __( 'Rows' ),
919 'Column' => _x( 'Column', 'table column' ),
920 'Cols' => _x( 'Cols', 'table columns' ),
921 'Cell' => _x( 'Cell', 'table cell' ),
922 'Header cell' => __( 'Header cell' ),
923 'Header' => _x( 'Header', 'table header' ),
924 'Body' => _x( 'Body', 'table body' ),
925 'Footer' => _x( 'Footer', 'table footer' ),
927 'Insert row before' => __( 'Insert row before' ),
928 'Insert row after' => __( 'Insert row after' ),
929 'Insert column before' => __( 'Insert column before' ),
930 'Insert column after' => __( 'Insert column after' ),
931 'Paste row before' => __( 'Paste table row before' ),
932 'Paste row after' => __( 'Paste table row after' ),
933 'Delete row' => __( 'Delete row' ),
934 'Delete column' => __( 'Delete column' ),
935 'Cut row' => __( 'Cut table row' ),
936 'Copy row' => __( 'Copy table row' ),
937 'Merge cells' => __( 'Merge table cells' ),
938 'Split cell' => __( 'Split table cell' ),
940 'Height' => __( 'Height' ),
941 'Width' => __( 'Width' ),
942 'Caption' => __( 'Caption' ),
943 'Alignment' => __( 'Alignment' ),
944 'H Align' => _x( 'H Align', 'horizontal table cell alignment' ),
945 'Left' => __( 'Left' ),
946 'Center' => __( 'Center' ),
947 'Right' => __( 'Right' ),
948 'None' => _x( 'None', 'table cell alignment attribute' ),
949 'V Align' => _x( 'V Align', 'vertical table cell alignment' ),
950 'Top' => __( 'Top' ),
951 'Middle' => __( 'Middle' ),
952 'Bottom' => __( 'Bottom' ),
954 'Row group' => __( 'Row group' ),
955 'Column group' => __( 'Column group' ),
956 'Row type' => __( 'Row type' ),
957 'Cell type' => __( 'Cell type' ),
958 'Cell padding' => __( 'Cell padding' ),
959 'Cell spacing' => __( 'Cell spacing' ),
960 'Scope' => _x( 'Scope', 'table cell scope attribute' ),
962 'Insert template' => _x( 'Insert template', 'TinyMCE' ),
963 'Templates' => _x( 'Templates', 'TinyMCE' ),
965 'Background color' => __( 'Background color' ),
966 'Text color' => __( 'Text color' ),
967 'Show blocks' => _x( 'Show blocks', 'editor button' ),
968 'Show invisible characters' => __( 'Show invisible characters' ),
970 /* translators: word count */
971 'Words: {0}' => sprintf( __( 'Words: %s' ), '{0}' ),
972 '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.' ),
973 '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' ),
974 '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.' ),
975 '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.' ),
978 'Insert' => _x( 'Insert', 'TinyMCE menu' ),
979 'File' => _x( 'File', 'TinyMCE menu' ),
980 'Edit' => _x( 'Edit', 'TinyMCE menu' ),
981 'Tools' => _x( 'Tools', 'TinyMCE menu' ),
982 'View' => _x( 'View', 'TinyMCE menu' ),
983 'Table' => _x( 'Table', 'TinyMCE menu' ),
984 'Format' => _x( 'Format', 'TinyMCE menu' ),
987 'Keyboard Shortcuts' => __( 'Keyboard Shortcuts' ),
988 'Toolbar Toggle' => __( 'Toolbar Toggle' ),
989 'Insert Read More tag' => __( 'Insert Read More tag' ),
990 'Read more...' => __( 'Read more...' ), // Title on the placeholder inside the editor
991 'Distraction-free writing mode' => __( 'Distraction-free writing mode' ),
992 'No alignment' => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar
993 'Remove' => __( 'Remove' ), // Tooltip for the 'remove' button in the image toolbar
994 'Edit ' => __( 'Edit' ), // Tooltip for the 'edit' button in the image toolbar
998 * Link plugin (not included):
1003 * The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?
1004 * The URL you entered seems to be an external link. Do you want to add the required http:\/\/ prefix?
1008 if ( ! $mce_locale ) {
1009 $mce_locale = self::$mce_locale;
1013 * Filter translated strings prepared for TinyMCE.
1017 * @param array $mce_translation Key/value pairs of strings.
1018 * @param string $mce_locale Locale.
1020 $mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale );
1022 foreach ( $mce_translation as $key => $value ) {
1023 // Remove strings that are not translated.
1024 if ( $key === $value ) {
1025 unset( $mce_translation[$key] );
1029 if ( false !== strpos( $value, '&' ) ) {
1030 $mce_translation[$key] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
1036 $mce_translation['_dir'] = 'rtl';
1040 return wp_json_encode( $mce_translation );
1043 $baseurl = self::$baseurl ? self::$baseurl : includes_url( 'js/tinymce' );
1045 return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
1046 "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
1049 public static function editor_js() {
1050 global $tinymce_version, $concatenate_scripts, $compress_scripts;
1053 * Filter "tiny_mce_version" is deprecated
1055 * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
1056 * These plugins can be refreshed by appending query string to the URL passed to "mce_external_plugins" filter.
1057 * 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).
1059 $version = 'ver=' . $tinymce_version;
1060 $tmce_on = !empty(self::$mce_settings);
1062 if ( ! isset($concatenate_scripts) )
1063 script_concat_settings();
1065 $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
1066 && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
1068 $mceInit = $qtInit = '';
1070 foreach ( self::$mce_settings as $editor_id => $init ) {
1071 $options = self::_parse_init( $init );
1072 $mceInit .= "'$editor_id':{$options},";
1074 $mceInit = '{' . trim($mceInit, ',') . '}';
1079 if ( !empty(self::$qt_settings) ) {
1080 foreach ( self::$qt_settings as $editor_id => $init ) {
1081 $options = self::_parse_init( $init );
1082 $qtInit .= "'$editor_id':{$options},";
1084 $qtInit = '{' . trim($qtInit, ',') . '}';
1090 'plugins' => implode( ',', self::$plugins ),
1091 'theme' => 'modern',
1092 'language' => self::$mce_locale
1095 $suffix = ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) ? '' : '.min';
1098 * Fires immediately before the TinyMCE settings are printed.
1102 * @param array $mce_settings TinyMCE settings array.
1104 do_action( 'before_wp_tiny_mce', self::$mce_settings );
1107 <script type="text/javascript">
1109 baseURL: "<?php echo self::$baseurl; ?>",
1110 suffix: "<?php echo $suffix; ?>",
1113 if ( self::$drag_drop_upload ) {
1114 echo 'dragDropUpload: true,';
1118 mceInit: <?php echo $mceInit; ?>,
1119 qtInit: <?php echo $qtInit; ?>,
1120 ref: <?php echo self::_parse_init( $ref ); ?>,
1121 load_ext: function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
1126 $baseurl = self::$baseurl;
1127 // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG)
1128 $mce_suffix = false !== strpos( $GLOBALS['wp_version'], '-src' ) ? '' : '.min';
1131 if ( $compressed ) {
1132 echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&$version'></script>\n";
1134 echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n";
1135 echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n";
1138 echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";
1140 if ( self::$ext_plugins ) {
1141 // Load the old-format English strings to prevent unsightly labels in old style popups
1142 echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
1147 * Fires after tinymce.js is loaded, but before any TinyMCE editor
1148 * instances are created.
1152 * @param array $mce_settings TinyMCE settings array.
1154 do_action( 'wp_tiny_mce_init', self::$mce_settings );
1157 <script type="text/javascript">
1160 if ( self::$ext_plugins )
1161 echo self::$ext_plugins . "\n";
1164 echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
1169 var init, edId, qtId, firstInit, wrapper;
1171 if ( typeof tinymce !== 'undefined' ) {
1172 for ( edId in tinyMCEPreInit.mceInit ) {
1174 init = tinyMCEPreInit.mceInit[edId] = tinymce.extend( {}, firstInit, tinyMCEPreInit.mceInit[edId] );
1176 init = firstInit = tinyMCEPreInit.mceInit[edId];
1179 wrapper = tinymce.DOM.select( '#wp-' + edId + '-wrap' )[0];
1181 if ( ( tinymce.DOM.hasClass( wrapper, 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( edId ) ) &&
1182 ! init.wp_skip_init ) {
1185 tinymce.init( init );
1187 if ( ! window.wpActiveEditor ) {
1188 window.wpActiveEditor = edId;
1195 if ( typeof quicktags !== 'undefined' ) {
1196 for ( qtId in tinyMCEPreInit.qtInit ) {
1198 quicktags( tinyMCEPreInit.qtInit[qtId] );
1200 if ( ! window.wpActiveEditor ) {
1201 window.wpActiveEditor = qtId;
1207 if ( typeof jQuery !== 'undefined' ) {
1208 jQuery('.wp-editor-wrap').on( 'click.wp-editor', function() {
1210 window.wpActiveEditor = this.id.slice( 3, -5 );
1214 for ( qtId in tinyMCEPreInit.qtInit ) {
1215 document.getElementById( 'wp-' + qtId + '-wrap' ).onclick = function() {
1216 window.wpActiveEditor = this.id.slice( 3, -5 );
1224 if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) )
1225 self::wp_link_dialog();
1227 if ( in_array( 'wpfullscreen', self::$plugins, true ) || in_array( 'fullscreen', self::$qt_buttons, true ) )
1228 self::wp_fullscreen_html();
1231 * Fires after any core TinyMCE editor instances are created.
1235 * @param array $mce_settings TinyMCE settings array.
1237 do_action( 'after_wp_tiny_mce', self::$mce_settings );
1240 public static function wp_fullscreen_html() {
1241 global $content_width;
1244 $width = isset( $content_width ) && 800 > $content_width ? $content_width : 800;
1245 $width = $width + 22; // compensate for the padding and border
1246 $dfw_width = get_user_setting( 'dfw_width', $width );
1247 $save = $post && $post->post_status == 'publish' ? __('Update') : __('Save');
1250 <div id="wp-fullscreen-body" class="wp-core-ui<?php if ( is_rtl() ) echo ' rtl'; ?>" data-theme-width="<?php echo (int) $width; ?>" data-dfw-width="<?php echo (int) $dfw_width; ?>">
1251 <div id="fullscreen-topbar">
1252 <div id="wp-fullscreen-toolbar">
1253 <div id="wp-fullscreen-close"><a href="#" onclick="wp.editor.fullscreen.off();return false;"><?php _e('Exit fullscreen'); ?></a></div>
1254 <div id="wp-fullscreen-central-toolbar" style="width:<?php echo $width; ?>px;">
1256 <div id="wp-fullscreen-mode-bar">
1257 <div id="wp-fullscreen-modes" class="button-group">
1258 <a class="button wp-fullscreen-mode-tinymce" href="#" onclick="wp.editor.fullscreen.switchmode( 'tinymce' ); return false;"><?php _e( 'Visual' ); ?></a>
1259 <a class="button wp-fullscreen-mode-html" href="#" onclick="wp.editor.fullscreen.switchmode( 'html' ); return false;"><?php _ex( 'Text', 'Name for the Text editor tab (formerly HTML)' ); ?></a>
1263 <div id="wp-fullscreen-button-bar"><div id="wp-fullscreen-buttons" class="mce-toolbar">
1267 // format: title, onclick, show in both editors
1268 'bold' => array( 'title' => __('Bold (Ctrl + B)'), 'both' => false ),
1269 'italic' => array( 'title' => __('Italic (Ctrl + I)'), 'both' => false ),
1270 'bullist' => array( 'title' => __('Unordered list (Alt + Shift + U)'), 'both' => false ),
1271 'numlist' => array( 'title' => __('Ordered list (Alt + Shift + O)'), 'both' => false ),
1272 'blockquote' => array( 'title' => __('Blockquote (Alt + Shift + Q)'), 'both' => false ),
1273 'wp-media-library' => array( 'title' => __('Media library (Alt + Shift + M)'), 'both' => true ),
1274 'link' => array( 'title' => __('Insert/edit link (Alt + Shift + A)'), 'both' => true ),
1275 'unlink' => array( 'title' => __('Unlink (Alt + Shift + S)'), 'both' => false ),
1276 'help' => array( 'title' => __('Help (Alt + Shift + H)'), 'both' => false ),
1280 * Filter the list of TinyMCE buttons for the fullscreen
1281 * 'Distraction-Free Writing' editor.
1285 * @param array $buttons An array of TinyMCE buttons for the DFW editor.
1287 $buttons = apply_filters( 'wp_fullscreen_buttons', $buttons );
1289 foreach ( $buttons as $button => $args ) {
1290 if ( 'separator' == $args ) {
1294 $onclick = ! empty( $args['onclick'] ) ? ' onclick="' . $args['onclick'] . '"' : '';
1295 $title = esc_attr( $args['title'] );
1298 <div class="mce-widget mce-btn<?php if ( $args['both'] ) { ?> wp-fullscreen-both<?php } ?>">
1299 <button type="button" aria-label="<?php echo $title; ?>" title="<?php echo $title; ?>"<?php echo $onclick; ?> id="wp_fs_<?php echo $button; ?>">
1300 <i class="mce-ico mce-i-<?php echo $button; ?>"></i>
1310 <div id="wp-fullscreen-save">
1311 <input type="button" class="button button-primary right" value="<?php echo $save; ?>" onclick="wp.editor.fullscreen.save();" />
1312 <span class="wp-fullscreen-saved-message"><?php if ( $post && $post->post_status == 'publish' ) _e('Updated.'); else _e('Saved.'); ?></span>
1313 <span class="wp-fullscreen-error-message"><?php _e('Save failed.'); ?></span>
1314 <span class="spinner"></span>
1320 <div id="wp-fullscreen-statusbar">
1321 <div id="wp-fullscreen-status">
1322 <div id="wp-fullscreen-count"><?php printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' ); ?></div>
1323 <div id="wp-fullscreen-tagline"><?php _e('Just write.'); ?></div>
1328 <div class="fullscreen-overlay" id="fullscreen-overlay"></div>
1329 <div class="fullscreen-overlay fullscreen-fader fade-300" id="fullscreen-fader"></div>
1334 * Performs post queries for internal linking.
1338 * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
1339 * @return false|array Results.
1341 public static function wp_link_query( $args = array() ) {
1342 $pts = get_post_types( array( 'public' => true ), 'objects' );
1343 $pt_names = array_keys( $pts );
1346 'post_type' => $pt_names,
1347 'suppress_filters' => true,
1348 'update_post_term_cache' => false,
1349 'update_post_meta_cache' => false,
1350 'post_status' => 'publish',
1351 'posts_per_page' => 20,
1354 $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
1356 if ( isset( $args['s'] ) )
1357 $query['s'] = $args['s'];
1359 $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
1362 * Filter the link query arguments.
1364 * Allows modification of the link query arguments before querying.
1366 * @see WP_Query for a full list of arguments
1370 * @param array $query An array of WP_Query arguments.
1372 $query = apply_filters( 'wp_link_query_args', $query );
1375 $get_posts = new WP_Query;
1376 $posts = $get_posts->query( $query );
1377 // Check if any posts were found.
1378 if ( ! $get_posts->post_count )
1383 foreach ( $posts as $post ) {
1384 if ( 'post' == $post->post_type )
1385 $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
1387 $info = $pts[ $post->post_type ]->labels->singular_name;
1391 'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
1392 'permalink' => get_permalink( $post->ID ),
1398 * Filter the link query results.
1400 * Allows modification of the returned link query results.
1404 * @see 'wp_link_query_args' filter
1406 * @param array $results {
1407 * An associative array of query results.
1410 * @type int $ID Post ID.
1411 * @type string $title The trimmed, escaped post title.
1412 * @type string $permalink Post permalink.
1413 * @type string $info A 'Y/m/d'-formatted date for 'post' post type,
1414 * the 'singular_name' post type label otherwise.
1417 * @param array $query An array of WP_Query arguments.
1419 return apply_filters( 'wp_link_query', $results, $query );
1423 * Dialog for internal linking.
1427 public static function wp_link_dialog() {
1428 $search_panel_visible = '1' == get_user_setting( 'wplink', '0' ) ? ' search-panel-visible' : '';
1430 // display: none is required here, see #WP27605
1432 <div id="wp-link-backdrop" style="display: none"></div>
1433 <div id="wp-link-wrap" class="wp-core-ui<?php echo $search_panel_visible; ?>" style="display: none">
1434 <form id="wp-link" tabindex="-1">
1435 <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
1436 <div id="link-modal-title">
1437 <?php _e( 'Insert/edit link' ) ?>
1438 <button type="button" id="wp-link-close"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
1440 <div id="link-selector">
1441 <div id="link-options">
1442 <p class="howto"><?php _e( 'Enter the destination URL' ); ?></p>
1444 <label><span><?php _e( 'URL' ); ?></span><input id="wp-link-url" type="text" /></label>
1446 <div class="wp-link-text-field">
1447 <label><span><?php _e( 'Link Text' ); ?></span><input id="wp-link-text" type="text" /></label>
1449 <div class="link-target">
1450 <label><span> </span><input type="checkbox" id="wp-link-target" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
1453 <p class="howto"><a href="#" id="wp-link-search-toggle"><?php _e( 'Or link to existing content' ); ?></a></p>
1454 <div id="search-panel">
1455 <div class="link-search-wrapper">
1457 <span class="search-label"><?php _e( 'Search' ); ?></span>
1458 <input type="search" id="wp-link-search" class="link-search-field" autocomplete="off" />
1459 <span class="spinner"></span>
1462 <div id="search-results" class="query-results" tabindex="0">
1464 <div class="river-waiting">
1465 <span class="spinner"></span>
1468 <div id="most-recent-results" class="query-results" tabindex="0">
1469 <div class="query-notice" id="query-notice-message">
1470 <em class="query-notice-default"><?php _e( 'No search term specified. Showing recent items.' ); ?></em>
1471 <em class="query-notice-hint screen-reader-text"><?php _e( 'Search or use up and down arrow keys to select an item.' ); ?></em>
1474 <div class="river-waiting">
1475 <span class="spinner"></span>
1480 <div class="submitbox">
1481 <div id="wp-link-cancel">
1482 <a class="submitdelete deletion" href="#"><?php _e( 'Cancel' ); ?></a>
1484 <div id="wp-link-update">
1485 <input type="submit" value="<?php esc_attr_e( 'Add Link' ); ?>" class="button button-primary" id="wp-link-submit" name="wp-link-submit">