_WP_Editors

Facilitates adding of the WordPress editor as used on the Write and Edit screens.

Defined (1)

The class is defined in the following location(s).

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