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' );
120 // Upgrade an old TinyMCE cookie if it is still around, and the new one isn't.
121 if ( ! $cookie && isset( $_COOKIE['TinyMCE_content_size'] ) ) {
122 parse_str( $_COOKIE['TinyMCE_content_size'], $cookie );
123 $cookie = $cookie['ch'];
127 $set['editor_height'] = $cookie;
130 if ( $set['editor_height'] < 50 )
131 $set['editor_height'] = 50;
132 elseif ( $set['editor_height'] > 5000 )
133 $set['editor_height'] = 5000;
139 * 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() ) {
147 $set = self::parse_settings( $editor_id, $settings );
148 $editor_class = ' class="' . trim( $set['editor_class'] . ' wp-editor-area' ) . '"';
149 $tabindex = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
150 $switch_class = 'html-active';
151 $toolbar = $buttons = $autocomplete = '';
153 if ( $set['drag_drop_upload'] ) {
154 self::$drag_drop_upload = true;
157 if ( ! empty( $set['editor_height'] ) )
158 $height = ' style="height: ' . $set['editor_height'] . 'px"';
160 $height = ' rows="' . $set['textarea_rows'] . '"';
162 if ( !current_user_can( 'upload_files' ) )
163 $set['media_buttons'] = false;
165 if ( ! self::$this_quicktags && self::$this_tinymce ) {
166 $switch_class = 'tmce-active';
167 $autocomplete = ' autocomplete="off"';
168 } elseif ( self::$this_quicktags && self::$this_tinymce ) {
169 $default_editor = $set['default_editor'] ? $set['default_editor'] : wp_default_editor();
170 $autocomplete = ' autocomplete="off"';
172 // 'html' is used for the "Text" editor tab.
173 if ( 'html' === $default_editor ) {
174 add_filter('the_editor_content', 'wp_htmledit_pre');
175 $switch_class = 'html-active';
177 add_filter('the_editor_content', 'wp_richedit_pre');
178 $switch_class = 'tmce-active';
181 $buttons .= '<button type="button" id="' . $editor_id . '-tmce" class="wp-switch-editor switch-tmce" onclick="switchEditors.switchto(this);">' . __('Visual') . "</button>\n";
182 $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";
185 $wrap_class = 'wp-core-ui wp-editor-wrap ' . $switch_class;
187 if ( $set['_content_editor_dfw'] ) {
188 $wrap_class .= ' has-dfw';
191 echo '<div id="wp-' . $editor_id . '-wrap" class="' . $wrap_class . '">';
193 if ( self::$editor_buttons_css ) {
194 wp_print_styles('editor-buttons');
195 self::$editor_buttons_css = false;
198 if ( !empty($set['editor_css']) )
199 echo $set['editor_css'] . "\n";
201 if ( !empty($buttons) || $set['media_buttons'] ) {
202 echo '<div id="wp-' . $editor_id . '-editor-tools" class="wp-editor-tools hide-if-no-js">';
204 if ( $set['media_buttons'] ) {
205 self::$has_medialib = true;
207 if ( !function_exists('media_buttons') )
208 include(ABSPATH . 'wp-admin/includes/media.php');
210 echo '<div id="wp-' . $editor_id . '-media-buttons" class="wp-media-buttons">';
213 * Fires after the default media button(s) are displayed.
217 * @param string $editor_id Unique editor identifier, e.g. 'content'.
219 do_action( 'media_buttons', $editor_id );
223 echo '<div class="wp-editor-tabs">' . $buttons . "</div>\n";
228 * Filter the HTML markup output that displays the editor.
232 * @param string $output Editor's HTML markup.
234 $the_editor = apply_filters( 'the_editor', '<div id="wp-' . $editor_id . '-editor-container" class="wp-editor-container">' .
235 '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . $set['textarea_name'] . '" ' .
236 'id="' . $editor_id . '">%s</textarea></div>' );
239 * Filter the default editor content.
243 * @param string $content Default editor content.
245 $content = apply_filters( 'the_editor_content', $content );
247 printf( $the_editor, $content );
250 self::editor_settings($editor_id, $set);
254 * @param string $editor_id
257 public static function editor_settings($editor_id, $set) {
260 if ( empty(self::$first_init) ) {
262 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
263 add_action( 'admin_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
265 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
266 add_action( 'wp_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
270 if ( self::$this_quicktags ) {
277 if ( is_array($set['quicktags']) )
278 $qtInit = array_merge($qtInit, $set['quicktags']);
280 if ( empty($qtInit['buttons']) )
281 $qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close';
284 $qtInit['buttons'] .= ',fullscreen';
286 if ( $set['_content_editor_dfw'] ) {
287 $qtInit['buttons'] .= ',dfw';
291 * Filter the Quicktags settings.
295 * @param array $qtInit Quicktags settings.
296 * @param string $editor_id The unique editor ID, e.g. 'content'.
298 $qtInit = apply_filters( 'quicktags_settings', $qtInit, $editor_id );
300 self::$qt_settings[$editor_id] = $qtInit;
302 self::$qt_buttons = array_merge( self::$qt_buttons, explode(',', $qtInit['buttons']) );
305 if ( self::$this_tinymce ) {
307 if ( empty( self::$first_init ) ) {
308 self::$baseurl = includes_url( 'js/tinymce' );
310 $mce_locale = get_locale();
311 self::$mce_locale = $mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1
313 /** This filter is documented in wp-admin/includes/media.php */
314 $no_captions = (bool) apply_filters( 'disable_captions', '' );
318 if ( $set['teeny'] ) {
321 * Filter the list of teenyMCE plugins.
325 * @param array $plugins An array of teenyMCE plugins.
326 * @param string $editor_id Unique editor identifier, e.g. 'content'.
328 self::$plugins = $plugins = apply_filters( 'teeny_mce_plugins', array( 'colorpicker', 'lists', 'fullscreen', 'image', 'wordpress', 'wpeditimage', 'wplink' ), $editor_id );
332 * Filter the list of TinyMCE external plugins.
334 * The filter takes an associative array of external plugins for
335 * TinyMCE in the form 'plugin_name' => 'url'.
337 * The url should be absolute, and should include the js filename
338 * to be loaded. For example:
339 * 'myplugin' => 'http://mysite.com/wp-content/plugins/myfolder/mce_plugin.js'.
341 * If the external plugin adds a button, it should be added with
342 * one of the 'mce_buttons' filters.
346 * @param array $external_plugins An array of external TinyMCE plugins.
348 $mce_external_plugins = apply_filters( 'mce_external_plugins', array() );
369 if ( ! self::$has_medialib ) {
370 $plugins[] = 'image';
374 * Filter the list of default TinyMCE plugins.
376 * The filter specifies which of the default plugins included
377 * in WordPress should be added to the TinyMCE instance.
381 * @param array $plugins An array of default TinyMCE plugins.
383 $plugins = array_unique( apply_filters( 'tiny_mce_plugins', $plugins ) );
385 if ( ( $key = array_search( 'spellchecker', $plugins ) ) !== false ) {
386 // Remove 'spellchecker' from the internal plugins if added with 'tiny_mce_plugins' filter to prevent errors.
387 // It can be added with 'mce_external_plugins'.
388 unset( $plugins[$key] );
391 if ( ! empty( $mce_external_plugins ) ) {
394 * Filter the translations loaded for external TinyMCE 3.x plugins.
396 * The filter takes an associative array ('plugin_name' => 'path')
397 * where 'path' is the include path to the file.
399 * The language file should follow the same format as wp_mce_translation(),
400 * and should define a variable ($strings) that holds all translated strings.
404 * @param array $translations Translations for external TinyMCE plugins.
406 $mce_external_languages = apply_filters( 'mce_external_languages', array() );
408 $loaded_langs = array();
411 if ( ! empty( $mce_external_languages ) ) {
412 foreach ( $mce_external_languages as $name => $path ) {
413 if ( @is_file( $path ) && @is_readable( $path ) ) {
414 include_once( $path );
415 $ext_plugins .= $strings . "\n";
416 $loaded_langs[] = $name;
421 foreach ( $mce_external_plugins as $name => $url ) {
422 if ( in_array( $name, $plugins, true ) ) {
423 unset( $mce_external_plugins[ $name ] );
427 $url = set_url_scheme( $url );
428 $mce_external_plugins[ $name ] = $url;
429 $plugurl = dirname( $url );
432 // Try to load langs/[locale].js and langs/[locale]_dlg.js
433 if ( ! in_array( $name, $loaded_langs, true ) ) {
434 $path = str_replace( content_url(), '', $plugurl );
435 $path = WP_CONTENT_DIR . $path . '/langs/';
437 if ( function_exists('realpath') )
438 $path = trailingslashit( realpath($path) );
440 if ( @is_file( $path . $mce_locale . '.js' ) )
441 $strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n";
443 if ( @is_file( $path . $mce_locale . '_dlg.js' ) )
444 $strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n";
446 if ( 'en' != $mce_locale && empty( $strings ) ) {
447 if ( @is_file( $path . 'en.js' ) ) {
448 $str1 = @file_get_contents( $path . 'en.js' );
449 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
452 if ( @is_file( $path . 'en_dlg.js' ) ) {
453 $str2 = @file_get_contents( $path . 'en_dlg.js' );
454 $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";
458 if ( ! empty( $strings ) )
459 $ext_plugins .= "\n" . $strings . "\n";
462 $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
463 $ext_plugins .= 'tinymce.PluginManager.load("' . $name . '", "' . $url . '");' . "\n";
469 $plugins[] = 'wpfullscreen';
471 self::$plugins = $plugins;
472 self::$ext_plugins = $ext_plugins;
474 self::$first_init = array(
476 'skin' => 'lightgray',
477 'language' => self::$mce_locale,
480 {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles: {textAlign:'left'}},
481 {selector: 'img,table,dl.wp-caption', classes: 'alignleft'}
484 {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles: {textAlign:'center'}},
485 {selector: 'img,table,dl.wp-caption', classes: 'aligncenter'}
488 {selector: 'p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li', styles: {textAlign:'right'}},
489 {selector: 'img,table,dl.wp-caption', classes: 'alignright'}
491 strikethrough: {inline: 'del'}
502 'relative_urls' => false,
503 'remove_script_host' => false,
504 'convert_urls' => false,
505 'browser_spellcheck' => true,
506 'fix_list_elements' => true,
507 'entities' => '38,amp,60,lt,62,gt',
508 'entity_encoding' => 'raw',
509 'keep_styles' => false,
510 'cache_suffix' => 'wp-mce-' . $GLOBALS['tinymce_version'],
512 // Limit the preview styles in the menu/toolbar
513 'preview_styles' => 'font-family font-size font-weight font-style text-decoration text-transform',
515 'wpeditimage_disable_captions' => $no_captions,
516 'wpeditimage_html5_captions' => current_theme_supports( 'html5', 'caption' ),
517 'plugins' => implode( ',', $plugins ),
520 if ( ! empty( $mce_external_plugins ) ) {
521 self::$first_init['external_plugins'] = wp_json_encode( $mce_external_plugins );
524 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
525 $version = 'ver=' . $GLOBALS['wp_version'];
526 $dashicons = includes_url( "css/dashicons$suffix.css?$version" );
528 // WordPress default stylesheet and dashicons
531 self::$baseurl . '/skins/wordpress/wp-content.css?' . $version
534 $editor_styles = get_editor_stylesheets();
535 if ( ! empty( $editor_styles ) ) {
536 foreach ( $editor_styles as $style ) {
542 * Filter the comma-delimited list of stylesheets to load in TinyMCE.
546 * @param array $stylesheets Comma-delimited list of stylesheets.
548 $mce_css = trim( apply_filters( 'mce_css', implode( ',', $mce_css ) ), ' ,' );
550 if ( ! empty($mce_css) )
551 self::$first_init['content_css'] = $mce_css;
554 if ( $set['teeny'] ) {
557 * Filter the list of teenyMCE buttons (Text tab).
561 * @param array $buttons An array of teenyMCE buttons.
562 * @param string $editor_id Unique editor identifier, e.g. 'content'.
564 $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 );
565 $mce_buttons_2 = $mce_buttons_3 = $mce_buttons_4 = array();
567 $mce_buttons = array( 'bold', 'italic', 'strikethrough', 'bullist', 'numlist', 'blockquote', 'hr', 'alignleft', 'aligncenter', 'alignright', 'link', 'unlink', 'wp_more', 'spellchecker' );
569 if ( $set['_content_editor_dfw'] ) {
570 $mce_buttons[] = 'dfw';
572 $mce_buttons[] = 'fullscreen';
575 $mce_buttons[] = 'wp_adv';
578 * Filter the first-row list of TinyMCE buttons (Visual tab).
582 * @param array $buttons First-row list of buttons.
583 * @param string $editor_id Unique editor identifier, e.g. 'content'.
585 $mce_buttons = apply_filters( 'mce_buttons', $mce_buttons, $editor_id );
588 * Filter the second-row list of TinyMCE buttons (Visual tab).
592 * @param array $buttons Second-row list of buttons.
593 * @param string $editor_id Unique editor identifier, e.g. 'content'.
595 $mce_buttons_2 = apply_filters( 'mce_buttons_2', array( 'formatselect', 'underline', 'alignjustify', 'forecolor', 'pastetext', 'removeformat', 'charmap', 'outdent', 'indent', 'undo', 'redo', 'wp_help' ), $editor_id );
598 * Filter the third-row list of TinyMCE buttons (Visual tab).
602 * @param array $buttons Third-row list of buttons.
603 * @param string $editor_id Unique editor identifier, e.g. 'content'.
605 $mce_buttons_3 = apply_filters( 'mce_buttons_3', array(), $editor_id );
608 * Filter the fourth-row list of TinyMCE buttons (Visual tab).
612 * @param array $buttons Fourth-row list of buttons.
613 * @param string $editor_id Unique editor identifier, e.g. 'content'.
615 $mce_buttons_4 = apply_filters( 'mce_buttons_4', array(), $editor_id );
618 $body_class = $editor_id;
620 if ( $post = get_post() ) {
621 $body_class .= ' post-type-' . sanitize_html_class( $post->post_type ) . ' post-status-' . sanitize_html_class( $post->post_status );
622 if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
623 $post_format = get_post_format( $post );
624 if ( $post_format && ! is_wp_error( $post_format ) )
625 $body_class .= ' post-format-' . sanitize_html_class( $post_format );
627 $body_class .= ' post-format-standard';
631 $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_locale() ) ) );
633 if ( !empty($set['tinymce']['body_class']) ) {
634 $body_class .= ' ' . $set['tinymce']['body_class'];
635 unset($set['tinymce']['body_class']);
639 // replace the first 'fullscreen' with 'wp_fullscreen'
640 if ( ($key = array_search('fullscreen', $mce_buttons)) !== false )
641 $mce_buttons[$key] = 'wp_fullscreen';
642 elseif ( ($key = array_search('fullscreen', $mce_buttons_2)) !== false )
643 $mce_buttons_2[$key] = 'wp_fullscreen';
644 elseif ( ($key = array_search('fullscreen', $mce_buttons_3)) !== false )
645 $mce_buttons_3[$key] = 'wp_fullscreen';
646 elseif ( ($key = array_search('fullscreen', $mce_buttons_4)) !== false )
647 $mce_buttons_4[$key] = 'wp_fullscreen';
651 'selector' => "#$editor_id",
652 'resize' => 'vertical',
654 'wpautop' => (bool) $set['wpautop'],
655 'indent' => ! $set['wpautop'],
656 'toolbar1' => implode($mce_buttons, ','),
657 'toolbar2' => implode($mce_buttons_2, ','),
658 'toolbar3' => implode($mce_buttons_3, ','),
659 'toolbar4' => implode($mce_buttons_4, ','),
660 'tabfocus_elements' => $set['tabfocus_elements'],
661 'body_class' => $body_class
665 $mceInit = array_merge( self::$first_init, $mceInit );
667 if ( is_array( $set['tinymce'] ) )
668 $mceInit = array_merge( $mceInit, $set['tinymce'] );
671 * For people who really REALLY know what they're doing with TinyMCE
672 * You can modify $mceInit to add, remove, change elements of the config
673 * before tinyMCE.init. Setting "valid_elements", "invalid_elements"
674 * and "extended_valid_elements" can be done through this filter. Best
675 * is to use the default cleanup by not specifying valid_elements,
676 * as TinyMCE contains full set of XHTML 1.0.
678 if ( $set['teeny'] ) {
681 * Filter the teenyMCE config before init.
685 * @param array $mceInit An array with teenyMCE config.
686 * @param string $editor_id Unique editor identifier, e.g. 'content'.
688 $mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
692 * Filter the TinyMCE config before init.
696 * @param array $mceInit An array with TinyMCE config.
697 * @param string $editor_id Unique editor identifier, e.g. 'content'.
699 $mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );
702 if ( empty( $mceInit['toolbar3'] ) && ! empty( $mceInit['toolbar4'] ) ) {
703 $mceInit['toolbar3'] = $mceInit['toolbar4'];
704 $mceInit['toolbar4'] = '';
707 self::$mce_settings[$editor_id] = $mceInit;
708 } // end if self::$this_tinymce
711 private static function _parse_init($init) {
714 foreach ( $init as $k => $v ) {
716 $val = $v ? 'true' : 'false';
717 $options .= $k . ':' . $val . ',';
719 } elseif ( !empty($v) && is_string($v) && ( ('{' == $v{0} && '}' == $v{strlen($v) - 1}) || ('[' == $v{0} && ']' == $v{strlen($v) - 1}) || preg_match('/^\(?function ?\(/', $v) ) ) {
720 $options .= $k . ':' . $v . ',';
723 $options .= $k . ':"' . $v . '",';
726 return '{' . trim( $options, ' ,' ) . '}';
729 public static function enqueue_scripts() {
730 wp_enqueue_script('word-count');
732 if ( self::$has_tinymce )
733 wp_enqueue_script('editor');
735 if ( self::$has_quicktags ) {
736 wp_enqueue_script( 'quicktags' );
737 wp_enqueue_style( 'buttons' );
740 if ( in_array('wplink', self::$plugins, true) || in_array('link', self::$qt_buttons, true) ) {
741 wp_enqueue_script('wplink');
744 if ( in_array('wpfullscreen', self::$plugins, true) || in_array('fullscreen', self::$qt_buttons, true) )
745 wp_enqueue_script('wp-fullscreen');
747 if ( self::$has_medialib ) {
749 wp_enqueue_script('media-upload');
753 * Fires when scripts and styles are enqueued for the editor.
757 * @param array $to_load An array containing boolean values whether TinyMCE
758 * and Quicktags are being loaded.
760 do_action( 'wp_enqueue_editor', array(
761 'tinymce' => self::$has_tinymce,
762 'quicktags' => self::$has_quicktags,
767 * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n().
768 * Can be used directly (_WP_Editors::wp_mce_translation()) by passing the same locale as set in the TinyMCE init object.
770 * @param string $mce_locale The locale used for the editor.
771 * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
772 * @return string Translation object, JSON encoded.
774 public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
776 $mce_translation = array(
777 // Default TinyMCE strings
778 'New document' => __( 'New document' ),
779 'Formats' => _x( 'Formats', 'TinyMCE' ),
781 'Headings' => _x( 'Headings', 'TinyMCE' ),
782 'Heading 1' => __( 'Heading 1' ),
783 'Heading 2' => __( 'Heading 2' ),
784 'Heading 3' => __( 'Heading 3' ),
785 'Heading 4' => __( 'Heading 4' ),
786 'Heading 5' => __( 'Heading 5' ),
787 'Heading 6' => __( 'Heading 6' ),
789 /* translators: block tags */
790 'Blocks' => _x( 'Blocks', 'TinyMCE' ),
791 'Paragraph' => __( 'Paragraph' ),
792 'Blockquote' => __( 'Blockquote' ),
793 'Div' => _x( 'Div', 'HTML tag' ),
794 'Pre' => _x( 'Pre', 'HTML tag' ),
795 'Address' => _x( 'Address', 'HTML tag' ),
797 'Inline' => _x( 'Inline', 'HTML elements' ),
798 'Underline' => __( 'Underline' ),
799 'Strikethrough' => __( 'Strikethrough' ),
800 'Subscript' => __( 'Subscript' ),
801 'Superscript' => __( 'Superscript' ),
802 'Clear formatting' => __( 'Clear formatting' ),
803 'Bold' => __( 'Bold' ),
804 'Italic' => __( 'Italic' ),
805 'Code' => _x( 'Code', 'editor button' ),
806 'Source code' => __( 'Source code' ),
807 'Font Family' => __( 'Font Family' ),
808 'Font Sizes' => __( 'Font Sizes' ),
810 'Align center' => __( 'Align center' ),
811 'Align right' => __( 'Align right' ),
812 'Align left' => __( 'Align left' ),
813 'Justify' => __( 'Justify' ),
814 'Increase indent' => __( 'Increase indent' ),
815 'Decrease indent' => __( 'Decrease indent' ),
817 'Cut' => __( 'Cut' ),
818 'Copy' => __( 'Copy' ),
819 'Paste' => __( 'Paste' ),
820 'Select all' => __( 'Select all' ),
821 'Undo' => __( 'Undo' ),
822 'Redo' => __( 'Redo' ),
825 'Cancel' => __( 'Cancel' ),
826 'Close' => __( 'Close' ),
827 'Visual aids' => __( 'Visual aids' ),
829 'Bullet list' => __( 'Bulleted list' ),
830 'Numbered list' => __( 'Numbered list' ),
831 'Square' => _x( 'Square', 'list style' ),
832 'Default' => _x( 'Default', 'list style' ),
833 'Circle' => _x( 'Circle', 'list style' ),
834 'Disc' => _x('Disc', 'list style' ),
835 'Lower Greek' => _x( 'Lower Greek', 'list style' ),
836 'Lower Alpha' => _x( 'Lower Alpha', 'list style' ),
837 'Upper Alpha' => _x( 'Upper Alpha', 'list style' ),
838 'Upper Roman' => _x( 'Upper Roman', 'list style' ),
839 'Lower Roman' => _x( 'Lower Roman', 'list style' ),
842 'Name' => _x( 'Name', 'Name of link anchor (TinyMCE)' ),
843 'Anchor' => _x( 'Anchor', 'Link anchor (TinyMCE)' ),
844 'Anchors' => _x( 'Anchors', 'Link anchors (TinyMCE)' ),
847 'Document properties' => __( 'Document properties' ),
848 'Robots' => __( 'Robots' ),
849 'Title' => __( 'Title' ),
850 'Keywords' => __( 'Keywords' ),
851 'Encoding' => __( 'Encoding' ),
852 'Description' => __( 'Description' ),
853 'Author' => __( 'Author' ),
855 // Media, image plugins
856 'Insert/edit image' => __( 'Insert/edit image' ),
857 'General' => __( 'General' ),
858 'Advanced' => __( 'Advanced' ),
859 'Source' => __( 'Source' ),
860 'Border' => __( 'Border' ),
861 'Constrain proportions' => __( 'Constrain proportions' ),
862 'Vertical space' => __( 'Vertical space' ),
863 'Image description' => __( 'Image description' ),
864 'Style' => __( 'Style' ),
865 'Dimensions' => __( 'Dimensions' ),
866 'Insert image' => __( 'Insert image' ),
867 'Insert date/time' => __( 'Insert date/time' ),
868 'Insert/edit video' => __( 'Insert/edit video' ),
869 'Poster' => __( 'Poster' ),
870 'Alternative source' => __( 'Alternative source' ),
871 'Paste your embed code below:' => __( 'Paste your embed code below:' ),
872 'Insert video' => __( 'Insert video' ),
873 'Embed' => __( 'Embed' ),
875 // Each of these have a corresponding plugin
876 'Special character' => __( 'Special character' ),
877 'Right to left' => _x( 'Right to left', 'editor button' ),
878 'Left to right' => _x( 'Left to right', 'editor button' ),
879 'Emoticons' => __( 'Emoticons' ),
880 'Nonbreaking space' => __( 'Nonbreaking space' ),
881 'Page break' => __( 'Page break' ),
882 'Paste as text' => __( 'Paste as text' ),
883 'Preview' => __( 'Preview' ),
884 'Print' => __( 'Print' ),
885 'Save' => __( 'Save' ),
886 'Fullscreen' => __( 'Fullscreen' ),
887 'Horizontal line' => __( 'Horizontal line' ),
888 'Horizontal space' => __( 'Horizontal space' ),
889 'Restore last draft' => __( 'Restore last draft' ),
890 'Insert/edit link' => __( 'Insert/edit link' ),
891 'Remove link' => __( 'Remove link' ),
893 'Color' => __( 'Color' ),
894 'Custom color' => __( 'Custom color' ),
895 'Custom...' => _x( 'Custom...', 'label for custom color' ),
896 'No color' => __( 'No color' ),
898 // Spelling, search/replace plugins
899 'Could not find the specified string.' => __( 'Could not find the specified string.' ),
900 'Replace' => _x( 'Replace', 'find/replace' ),
901 'Next' => _x( 'Next', 'find/replace' ),
902 /* translators: previous */
903 'Prev' => _x( 'Prev', 'find/replace' ),
904 'Whole words' => _x( 'Whole words', 'find/replace' ),
905 'Find and replace' => __( 'Find and replace' ),
906 'Replace with' => _x('Replace with', 'find/replace' ),
907 'Find' => _x( 'Find', 'find/replace' ),
908 'Replace all' => _x( 'Replace all', 'find/replace' ),
909 'Match case' => __( 'Match case' ),
910 'Spellcheck' => __( 'Check Spelling' ),
911 'Finish' => _x( 'Finish', 'spellcheck' ),
912 'Ignore all' => _x( 'Ignore all', 'spellcheck' ),
913 'Ignore' => _x( 'Ignore', 'spellcheck' ),
914 'Add to Dictionary' => __( 'Add to Dictionary' ),
917 'Insert table' => __( 'Insert table' ),
918 'Delete table' => __( 'Delete table' ),
919 'Table properties' => __( 'Table properties' ),
920 'Row properties' => __( 'Table row properties' ),
921 'Cell properties' => __( 'Table cell properties' ),
922 'Border color' => __( 'Border color' ),
924 'Row' => __( 'Row' ),
925 'Rows' => __( 'Rows' ),
926 'Column' => _x( 'Column', 'table column' ),
927 'Cols' => _x( 'Cols', 'table columns' ),
928 'Cell' => _x( 'Cell', 'table cell' ),
929 'Header cell' => __( 'Header cell' ),
930 'Header' => _x( 'Header', 'table header' ),
931 'Body' => _x( 'Body', 'table body' ),
932 'Footer' => _x( 'Footer', 'table footer' ),
934 'Insert row before' => __( 'Insert row before' ),
935 'Insert row after' => __( 'Insert row after' ),
936 'Insert column before' => __( 'Insert column before' ),
937 'Insert column after' => __( 'Insert column after' ),
938 'Paste row before' => __( 'Paste table row before' ),
939 'Paste row after' => __( 'Paste table row after' ),
940 'Delete row' => __( 'Delete row' ),
941 'Delete column' => __( 'Delete column' ),
942 'Cut row' => __( 'Cut table row' ),
943 'Copy row' => __( 'Copy table row' ),
944 'Merge cells' => __( 'Merge table cells' ),
945 'Split cell' => __( 'Split table cell' ),
947 'Height' => __( 'Height' ),
948 'Width' => __( 'Width' ),
949 'Caption' => __( 'Caption' ),
950 'Alignment' => __( 'Alignment' ),
951 'H Align' => _x( 'H Align', 'horizontal table cell alignment' ),
952 'Left' => __( 'Left' ),
953 'Center' => __( 'Center' ),
954 'Right' => __( 'Right' ),
955 'None' => _x( 'None', 'table cell alignment attribute' ),
956 'V Align' => _x( 'V Align', 'vertical table cell alignment' ),
957 'Top' => __( 'Top' ),
958 'Middle' => __( 'Middle' ),
959 'Bottom' => __( 'Bottom' ),
961 'Row group' => __( 'Row group' ),
962 'Column group' => __( 'Column group' ),
963 'Row type' => __( 'Row type' ),
964 'Cell type' => __( 'Cell type' ),
965 'Cell padding' => __( 'Cell padding' ),
966 'Cell spacing' => __( 'Cell spacing' ),
967 'Scope' => _x( 'Scope', 'table cell scope attribute' ),
969 'Insert template' => _x( 'Insert template', 'TinyMCE' ),
970 'Templates' => _x( 'Templates', 'TinyMCE' ),
972 'Background color' => __( 'Background color' ),
973 'Text color' => __( 'Text color' ),
974 'Show blocks' => _x( 'Show blocks', 'editor button' ),
975 'Show invisible characters' => __( 'Show invisible characters' ),
977 /* translators: word count */
978 'Words: {0}' => sprintf( __( 'Words: %s' ), '{0}' ),
979 '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.' ),
980 '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' ),
981 '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.' ),
982 '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.' ),
985 'Insert' => _x( 'Insert', 'TinyMCE menu' ),
986 'File' => _x( 'File', 'TinyMCE menu' ),
987 'Edit' => _x( 'Edit', 'TinyMCE menu' ),
988 'Tools' => _x( 'Tools', 'TinyMCE menu' ),
989 'View' => _x( 'View', 'TinyMCE menu' ),
990 'Table' => _x( 'Table', 'TinyMCE menu' ),
991 'Format' => _x( 'Format', 'TinyMCE menu' ),
994 'Keyboard Shortcuts' => __( 'Keyboard Shortcuts' ),
995 'Toolbar Toggle' => __( 'Toolbar Toggle' ),
996 'Insert Read More tag' => __( 'Insert Read More tag' ),
997 'Read more...' => __( 'Read more...' ), // Title on the placeholder inside the editor
998 'Distraction-free writing mode' => __( 'Distraction-free writing mode' ),
999 'No alignment' => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar
1000 'Remove' => __( 'Remove' ), // Tooltip for the 'remove' button in the image toolbar
1001 'Edit ' => __( 'Edit' ), // Tooltip for the 'edit' button in the image toolbar
1005 * Link plugin (not included):
1010 * The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?
1011 * The URL you entered seems to be an external link. Do you want to add the required http:\/\/ prefix?
1015 if ( ! $mce_locale ) {
1016 $mce_locale = self::$mce_locale;
1020 * Filter translated strings prepared for TinyMCE.
1024 * @param array $mce_translation Key/value pairs of strings.
1025 * @param string $mce_locale Locale.
1027 $mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale );
1029 foreach ( $mce_translation as $key => $value ) {
1030 // Remove strings that are not translated.
1031 if ( $key === $value ) {
1032 unset( $mce_translation[$key] );
1036 if ( false !== strpos( $value, '&' ) ) {
1037 $mce_translation[$key] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
1043 $mce_translation['_dir'] = 'rtl';
1047 return wp_json_encode( $mce_translation );
1050 $baseurl = self::$baseurl ? self::$baseurl : includes_url( 'js/tinymce' );
1052 return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
1053 "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
1056 public static function editor_js() {
1057 global $tinymce_version, $concatenate_scripts, $compress_scripts;
1060 * Filter "tiny_mce_version" is deprecated
1062 * The tiny_mce_version filter is not needed since external plugins are loaded directly by TinyMCE.
1063 * These plugins can be refreshed by appending query string to the URL passed to "mce_external_plugins" filter.
1064 * 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).
1066 $version = 'ver=' . $tinymce_version;
1067 $tmce_on = !empty(self::$mce_settings);
1069 if ( ! isset($concatenate_scripts) )
1070 script_concat_settings();
1072 $compressed = $compress_scripts && $concatenate_scripts && isset($_SERVER['HTTP_ACCEPT_ENCODING'])
1073 && false !== stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip');
1075 $mceInit = $qtInit = '';
1077 foreach ( self::$mce_settings as $editor_id => $init ) {
1078 $options = self::_parse_init( $init );
1079 $mceInit .= "'$editor_id':{$options},";
1081 $mceInit = '{' . trim($mceInit, ',') . '}';
1086 if ( !empty(self::$qt_settings) ) {
1087 foreach ( self::$qt_settings as $editor_id => $init ) {
1088 $options = self::_parse_init( $init );
1089 $qtInit .= "'$editor_id':{$options},";
1091 $qtInit = '{' . trim($qtInit, ',') . '}';
1097 'plugins' => implode( ',', self::$plugins ),
1098 'theme' => 'modern',
1099 'language' => self::$mce_locale
1102 $suffix = ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) ? '' : '.min';
1105 * Fires immediately before the TinyMCE settings are printed.
1109 * @param array $mce_settings TinyMCE settings array.
1111 do_action( 'before_wp_tiny_mce', self::$mce_settings );
1114 <script type="text/javascript">
1116 baseURL: "<?php echo self::$baseurl; ?>",
1117 suffix: "<?php echo $suffix; ?>",
1120 if ( self::$drag_drop_upload ) {
1121 echo 'dragDropUpload: true,';
1125 mceInit: <?php echo $mceInit; ?>,
1126 qtInit: <?php echo $qtInit; ?>,
1127 ref: <?php echo self::_parse_init( $ref ); ?>,
1128 load_ext: function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
1133 $baseurl = self::$baseurl;
1134 // Load tinymce.js when running from /src, else load wp-tinymce.js.gz (production) or tinymce.min.js (SCRIPT_DEBUG)
1135 $mce_suffix = false !== strpos( $GLOBALS['wp_version'], '-src' ) ? '' : '.min';
1138 if ( $compressed ) {
1139 echo "<script type='text/javascript' src='{$baseurl}/wp-tinymce.php?c=1&$version'></script>\n";
1141 echo "<script type='text/javascript' src='{$baseurl}/tinymce{$mce_suffix}.js?$version'></script>\n";
1142 echo "<script type='text/javascript' src='{$baseurl}/plugins/compat3x/plugin{$suffix}.js?$version'></script>\n";
1145 echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";
1147 if ( self::$ext_plugins ) {
1148 // Load the old-format English strings to prevent unsightly labels in old style popups
1149 echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
1154 * Fires after tinymce.js is loaded, but before any TinyMCE editor
1155 * instances are created.
1159 * @param array $mce_settings TinyMCE settings array.
1161 do_action( 'wp_tiny_mce_init', self::$mce_settings );
1164 <script type="text/javascript">
1167 if ( self::$ext_plugins )
1168 echo self::$ext_plugins . "\n";
1171 echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
1176 var init, edId, qtId, firstInit, wrapper;
1178 if ( typeof tinymce !== 'undefined' ) {
1179 for ( edId in tinyMCEPreInit.mceInit ) {
1181 init = tinyMCEPreInit.mceInit[edId] = tinymce.extend( {}, firstInit, tinyMCEPreInit.mceInit[edId] );
1183 init = firstInit = tinyMCEPreInit.mceInit[edId];
1186 wrapper = tinymce.DOM.select( '#wp-' + edId + '-wrap' )[0];
1188 if ( ( tinymce.DOM.hasClass( wrapper, 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( edId ) ) &&
1189 ! init.wp_skip_init ) {
1192 tinymce.init( init );
1194 if ( ! window.wpActiveEditor ) {
1195 window.wpActiveEditor = edId;
1202 if ( typeof quicktags !== 'undefined' ) {
1203 for ( qtId in tinyMCEPreInit.qtInit ) {
1205 quicktags( tinyMCEPreInit.qtInit[qtId] );
1207 if ( ! window.wpActiveEditor ) {
1208 window.wpActiveEditor = qtId;
1214 if ( typeof jQuery !== 'undefined' ) {
1215 jQuery('.wp-editor-wrap').on( 'click.wp-editor', function() {
1217 window.wpActiveEditor = this.id.slice( 3, -5 );
1221 for ( qtId in tinyMCEPreInit.qtInit ) {
1222 document.getElementById( 'wp-' + qtId + '-wrap' ).onclick = function() {
1223 window.wpActiveEditor = this.id.slice( 3, -5 );
1231 if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) )
1232 self::wp_link_dialog();
1234 if ( in_array( 'wpfullscreen', self::$plugins, true ) || in_array( 'fullscreen', self::$qt_buttons, true ) )
1235 self::wp_fullscreen_html();
1238 * Fires after any core TinyMCE editor instances are created.
1242 * @param array $mce_settings TinyMCE settings array.
1244 do_action( 'after_wp_tiny_mce', self::$mce_settings );
1247 public static function wp_fullscreen_html() {
1248 global $content_width;
1251 $width = isset( $content_width ) && 800 > $content_width ? $content_width : 800;
1252 $width = $width + 22; // compensate for the padding and border
1253 $dfw_width = get_user_setting( 'dfw_width', $width );
1254 $save = isset( $post->post_status ) && $post->post_status == 'publish' ? __('Update') : __('Save');
1257 <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; ?>">
1258 <div id="fullscreen-topbar">
1259 <div id="wp-fullscreen-toolbar">
1260 <div id="wp-fullscreen-close"><a href="#" onclick="wp.editor.fullscreen.off();return false;"><?php _e('Exit fullscreen'); ?></a></div>
1261 <div id="wp-fullscreen-central-toolbar" style="width:<?php echo $width; ?>px;">
1263 <div id="wp-fullscreen-mode-bar">
1264 <div id="wp-fullscreen-modes" class="button-group">
1265 <a class="button wp-fullscreen-mode-tinymce" href="#" onclick="wp.editor.fullscreen.switchmode( 'tinymce' ); return false;"><?php _e( 'Visual' ); ?></a>
1266 <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>
1270 <div id="wp-fullscreen-button-bar"><div id="wp-fullscreen-buttons" class="mce-toolbar">
1274 // format: title, onclick, show in both editors
1275 'bold' => array( 'title' => __('Bold (Ctrl + B)'), 'both' => false ),
1276 'italic' => array( 'title' => __('Italic (Ctrl + I)'), 'both' => false ),
1277 'bullist' => array( 'title' => __('Unordered list (Alt + Shift + U)'), 'both' => false ),
1278 'numlist' => array( 'title' => __('Ordered list (Alt + Shift + O)'), 'both' => false ),
1279 'blockquote' => array( 'title' => __('Blockquote (Alt + Shift + Q)'), 'both' => false ),
1280 'wp-media-library' => array( 'title' => __('Media library (Alt + Shift + M)'), 'both' => true ),
1281 'link' => array( 'title' => __('Insert/edit link (Alt + Shift + A)'), 'both' => true ),
1282 'unlink' => array( 'title' => __('Unlink (Alt + Shift + S)'), 'both' => false ),
1283 'help' => array( 'title' => __('Help (Alt + Shift + H)'), 'both' => false ),
1287 * Filter the list of TinyMCE buttons for the fullscreen
1288 * 'Distraction-Free Writing' editor.
1292 * @param array $buttons An array of TinyMCE buttons for the DFW editor.
1294 $buttons = apply_filters( 'wp_fullscreen_buttons', $buttons );
1296 foreach ( $buttons as $button => $args ) {
1297 if ( 'separator' == $args ) {
1301 $onclick = ! empty( $args['onclick'] ) ? ' onclick="' . $args['onclick'] . '"' : '';
1302 $title = esc_attr( $args['title'] );
1305 <div class="mce-widget mce-btn<?php if ( $args['both'] ) { ?> wp-fullscreen-both<?php } ?>">
1306 <button type="button" aria-label="<?php echo $title; ?>" title="<?php echo $title; ?>"<?php echo $onclick; ?> id="wp_fs_<?php echo $button; ?>">
1307 <i class="mce-ico mce-i-<?php echo $button; ?>"></i>
1317 <div id="wp-fullscreen-save">
1318 <input type="button" class="button button-primary right" value="<?php echo $save; ?>" onclick="wp.editor.fullscreen.save();" />
1319 <span class="wp-fullscreen-saved-message"><?php if ( $post->post_status == 'publish' ) _e('Updated.'); else _e('Saved.'); ?></span>
1320 <span class="wp-fullscreen-error-message"><?php _e('Save failed.'); ?></span>
1321 <span class="spinner"></span>
1327 <div id="wp-fullscreen-statusbar">
1328 <div id="wp-fullscreen-status">
1329 <div id="wp-fullscreen-count"><?php printf( __( 'Word count: %s' ), '<span class="word-count">0</span>' ); ?></div>
1330 <div id="wp-fullscreen-tagline"><?php _e('Just write.'); ?></div>
1335 <div class="fullscreen-overlay" id="fullscreen-overlay"></div>
1336 <div class="fullscreen-overlay fullscreen-fader fade-300" id="fullscreen-fader"></div>
1341 * Performs post queries for internal linking.
1345 * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
1346 * @return false|array Results.
1348 public static function wp_link_query( $args = array() ) {
1349 $pts = get_post_types( array( 'public' => true ), 'objects' );
1350 $pt_names = array_keys( $pts );
1353 'post_type' => $pt_names,
1354 'suppress_filters' => true,
1355 'update_post_term_cache' => false,
1356 'update_post_meta_cache' => false,
1357 'post_status' => 'publish',
1358 'posts_per_page' => 20,
1361 $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
1363 if ( isset( $args['s'] ) )
1364 $query['s'] = $args['s'];
1366 $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
1369 * Filter the link query arguments.
1371 * Allows modification of the link query arguments before querying.
1373 * @see WP_Query for a full list of arguments
1377 * @param array $query An array of WP_Query arguments.
1379 $query = apply_filters( 'wp_link_query_args', $query );
1382 $get_posts = new WP_Query;
1383 $posts = $get_posts->query( $query );
1384 // Check if any posts were found.
1385 if ( ! $get_posts->post_count )
1390 foreach ( $posts as $post ) {
1391 if ( 'post' == $post->post_type )
1392 $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
1394 $info = $pts[ $post->post_type ]->labels->singular_name;
1398 'title' => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
1399 'permalink' => get_permalink( $post->ID ),
1405 * Filter the link query results.
1407 * Allows modification of the returned link query results.
1411 * @see 'wp_link_query_args' filter
1413 * @param array $results {
1414 * An associative array of query results.
1417 * @type int $ID Post ID.
1418 * @type string $title The trimmed, escaped post title.
1419 * @type string $permalink Post permalink.
1420 * @type string $info A 'Y/m/d'-formatted date for 'post' post type,
1421 * the 'singular_name' post type label otherwise.
1424 * @param array $query An array of WP_Query arguments.
1426 return apply_filters( 'wp_link_query', $results, $query );
1430 * Dialog for internal linking.
1434 public static function wp_link_dialog() {
1435 $search_panel_visible = '1' == get_user_setting( 'wplink', '0' ) ? ' search-panel-visible' : '';
1437 // display: none is required here, see #WP27605
1439 <div id="wp-link-backdrop" style="display: none"></div>
1440 <div id="wp-link-wrap" class="wp-core-ui<?php echo $search_panel_visible; ?>" style="display: none">
1441 <form id="wp-link" tabindex="-1">
1442 <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
1443 <div id="link-modal-title">
1444 <?php _e( 'Insert/edit link' ) ?>
1445 <button type="button" id="wp-link-close"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
1447 <div id="link-selector">
1448 <div id="link-options">
1449 <p class="howto"><?php _e( 'Enter the destination URL' ); ?></p>
1451 <label><span><?php _e( 'URL' ); ?></span><input id="url-field" type="text" name="href" /></label>
1454 <label><span><?php _e( 'Title' ); ?></span><input id="link-title-field" type="text" name="linktitle" /></label>
1456 <div class="link-target">
1457 <label><span> </span><input type="checkbox" id="link-target-checkbox" /> <?php _e( 'Open link in a new window/tab' ); ?></label>
1460 <p class="howto"><a href="#" id="wp-link-search-toggle"><?php _e( 'Or link to existing content' ); ?></a></p>
1461 <div id="search-panel">
1462 <div class="link-search-wrapper">
1464 <span class="search-label"><?php _e( 'Search' ); ?></span>
1465 <input type="search" id="search-field" class="link-search-field" autocomplete="off" />
1466 <span class="spinner"></span>
1469 <div id="search-results" class="query-results" tabindex="0">
1471 <div class="river-waiting">
1472 <span class="spinner"></span>
1475 <div id="most-recent-results" class="query-results" tabindex="0">
1476 <div class="query-notice" id="query-notice-message">
1477 <em class="query-notice-default"><?php _e( 'No search term specified. Showing recent items.' ); ?></em>
1478 <em class="query-notice-hint screen-reader-text"><?php _e( 'Search or use up and down arrow keys to select an item.' ); ?></em>
1481 <div class="river-waiting">
1482 <span class="spinner"></span>
1487 <div class="submitbox">
1488 <div id="wp-link-cancel">
1489 <a class="submitdelete deletion" href="#"><?php _e( 'Cancel' ); ?></a>
1491 <div id="wp-link-update">
1492 <input type="submit" value="<?php esc_attr_e( 'Add Link' ); ?>" class="button button-primary" id="wp-link-submit" name="wp-link-submit">