Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

1502 righe
53 KiB

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