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