[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-includes/ -> class-wp-editor.php (source)

   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  
  11  final class _WP_Editors {
  12      public static $mce_locale;
  13  
  14      private static $mce_settings = array();
  15      private static $qt_settings  = array();
  16      private static $plugins      = array();
  17      private static $qt_buttons   = array();
  18      private static $ext_plugins;
  19      private static $baseurl;
  20      private static $first_init;
  21      private static $this_tinymce       = false;
  22      private static $this_quicktags     = false;
  23      private static $has_tinymce        = false;
  24      private static $has_quicktags      = false;
  25      private static $has_medialib       = false;
  26      private static $editor_buttons_css = true;
  27      private static $drag_drop_upload   = false;
  28      private static $translation;
  29      private static $tinymce_scripts_printed = false;
  30      private static $link_dialog_printed     = false;
  31  
  32  	private function __construct() {}
  33  
  34      /**
  35       * Parse default arguments for the editor instance.
  36       *
  37       * @since 3.3.0
  38       *
  39       * @param string $editor_id HTML ID for the textarea and TinyMCE and Quicktags instances.
  40       *                          Should not contain square brackets.
  41       * @param array  $settings {
  42       *     Array of editor arguments.
  43       *
  44       *     @type bool       $wpautop           Whether to use wpautop(). Default true.
  45       *     @type bool       $media_buttons     Whether to show the Add Media/other media buttons.
  46       *     @type string     $default_editor    When both TinyMCE and Quicktags are used, set which
  47       *                                         editor is shown on page load. Default empty.
  48       *     @type bool       $drag_drop_upload  Whether to enable drag & drop on the editor uploading. Default false.
  49       *                                         Requires the media modal.
  50       *     @type string     $textarea_name     Give the textarea a unique name here. Square brackets
  51       *                                         can be used here. Default $editor_id.
  52       *     @type int        $textarea_rows     Number rows in the editor textarea. Default 20.
  53       *     @type string|int $tabindex          Tabindex value to use. Default empty.
  54       *     @type string     $tabfocus_elements The previous and next element ID to move the focus to
  55       *                                         when pressing the Tab key in TinyMCE. Default ':prev,:next'.
  56       *     @type string     $editor_css        Intended for extra styles for both Visual and Text editors.
  57       *                                         Should include `<style>` tags, and can use "scoped". Default empty.
  58       *     @type string     $editor_class      Extra classes to add to the editor textarea element. Default empty.
  59       *     @type bool       $teeny             Whether to output the minimal editor config. Examples include
  60       *                                         Press This and the Comment editor. Default false.
  61       *     @type bool       $dfw               Deprecated in 4.1. Unused.
  62       *     @type bool|array $tinymce           Whether to load TinyMCE. Can be used to pass settings directly to
  63       *                                         TinyMCE using an array. Default true.
  64       *     @type bool|array $quicktags         Whether to load Quicktags. Can be used to pass settings directly to
  65       *                                         Quicktags using an array. Default true.
  66       * }
  67       * @return array Parsed arguments array.
  68       */
  69  	public static function parse_settings( $editor_id, $settings ) {
  70  
  71          /**
  72           * Filters the wp_editor() settings.
  73           *
  74           * @since 4.0.0
  75           *
  76           * @see _WP_Editors::parse_settings()
  77           *
  78           * @param array  $settings  Array of editor arguments.
  79           * @param string $editor_id Unique editor identifier, e.g. 'content'. Accepts 'classic-block'
  80           *                          when called from block editor's Classic block.
  81           */
  82          $settings = apply_filters( 'wp_editor_settings', $settings, $editor_id );
  83  
  84          $set = wp_parse_args(
  85              $settings,
  86              array(
  87                  // Disable autop if the current post has blocks in it.
  88                  'wpautop'             => ! has_blocks(),
  89                  'media_buttons'       => true,
  90                  'default_editor'      => '',
  91                  'drag_drop_upload'    => false,
  92                  'textarea_name'       => $editor_id,
  93                  'textarea_rows'       => 20,
  94                  'tabindex'            => '',
  95                  'tabfocus_elements'   => ':prev,:next',
  96                  'editor_css'          => '',
  97                  'editor_class'        => '',
  98                  'teeny'               => false,
  99                  '_content_editor_dfw' => false,
 100                  'tinymce'             => true,
 101                  'quicktags'           => true,
 102              )
 103          );
 104  
 105          self::$this_tinymce = ( $set['tinymce'] && user_can_richedit() );
 106  
 107          if ( self::$this_tinymce ) {
 108              if ( false !== strpos( $editor_id, '[' ) ) {
 109                  self::$this_tinymce = false;
 110                  _deprecated_argument( 'wp_editor()', '3.9.0', 'TinyMCE editor IDs cannot have brackets.' );
 111              }
 112          }
 113  
 114          self::$this_quicktags = (bool) $set['quicktags'];
 115  
 116          if ( self::$this_tinymce ) {
 117              self::$has_tinymce = true;
 118          }
 119  
 120          if ( self::$this_quicktags ) {
 121              self::$has_quicktags = true;
 122          }
 123  
 124          if ( empty( $set['editor_height'] ) ) {
 125              return $set;
 126          }
 127  
 128          if ( 'content' === $editor_id && empty( $set['tinymce']['wp_autoresize_on'] ) ) {
 129              // A cookie (set when a user resizes the editor) overrides the height.
 130              $cookie = (int) get_user_setting( 'ed_size' );
 131  
 132              if ( $cookie ) {
 133                  $set['editor_height'] = $cookie;
 134              }
 135          }
 136  
 137          if ( $set['editor_height'] < 50 ) {
 138              $set['editor_height'] = 50;
 139          } elseif ( $set['editor_height'] > 5000 ) {
 140              $set['editor_height'] = 5000;
 141          }
 142  
 143          return $set;
 144      }
 145  
 146      /**
 147       * Outputs the HTML for a single instance of the editor.
 148       *
 149       * @since 3.3.0
 150       *
 151       * @param string $content   Initial content for the editor.
 152       * @param string $editor_id HTML ID for the textarea and TinyMCE and Quicktags instances.
 153       *                          Should not contain square brackets.
 154       * @param array  $settings  See _WP_Editors::parse_settings() for description.
 155       */
 156  	public static function editor( $content, $editor_id, $settings = array() ) {
 157          $set            = self::parse_settings( $editor_id, $settings );
 158          $editor_class   = ' class="' . trim( esc_attr( $set['editor_class'] ) . ' wp-editor-area' ) . '"';
 159          $tabindex       = $set['tabindex'] ? ' tabindex="' . (int) $set['tabindex'] . '"' : '';
 160          $default_editor = 'html';
 161          $buttons        = '';
 162          $autocomplete   = '';
 163          $editor_id_attr = esc_attr( $editor_id );
 164  
 165          if ( $set['drag_drop_upload'] ) {
 166              self::$drag_drop_upload = true;
 167          }
 168  
 169          if ( ! empty( $set['editor_height'] ) ) {
 170              $height = ' style="height: ' . (int) $set['editor_height'] . 'px"';
 171          } else {
 172              $height = ' rows="' . (int) $set['textarea_rows'] . '"';
 173          }
 174  
 175          if ( ! current_user_can( 'upload_files' ) ) {
 176              $set['media_buttons'] = false;
 177          }
 178  
 179          if ( self::$this_tinymce ) {
 180              $autocomplete = ' autocomplete="off"';
 181  
 182              if ( self::$this_quicktags ) {
 183                  $default_editor = $set['default_editor'] ? $set['default_editor'] : wp_default_editor();
 184                  // 'html' is used for the "Text" editor tab.
 185                  if ( 'html' !== $default_editor ) {
 186                      $default_editor = 'tinymce';
 187                  }
 188  
 189                  $buttons .= '<button type="button" id="' . $editor_id_attr . '-tmce" class="wp-switch-editor switch-tmce"' .
 190                      ' data-wp-editor-id="' . $editor_id_attr . '">' . _x( 'Visual', 'Name for the Visual editor tab' ) . "</button>\n";
 191                  $buttons .= '<button type="button" id="' . $editor_id_attr . '-html" class="wp-switch-editor switch-html"' .
 192                      ' data-wp-editor-id="' . $editor_id_attr . '">' . _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ) . "</button>\n";
 193              } else {
 194                  $default_editor = 'tinymce';
 195              }
 196          }
 197  
 198          $switch_class = 'html' === $default_editor ? 'html-active' : 'tmce-active';
 199          $wrap_class   = 'wp-core-ui wp-editor-wrap ' . $switch_class;
 200  
 201          if ( $set['_content_editor_dfw'] ) {
 202              $wrap_class .= ' has-dfw';
 203          }
 204  
 205          echo '<div id="wp-' . $editor_id_attr . '-wrap" class="' . $wrap_class . '">';
 206  
 207          if ( self::$editor_buttons_css ) {
 208              wp_print_styles( 'editor-buttons' );
 209              self::$editor_buttons_css = false;
 210          }
 211  
 212          if ( ! empty( $set['editor_css'] ) ) {
 213              echo $set['editor_css'] . "\n";
 214          }
 215  
 216          if ( ! empty( $buttons ) || $set['media_buttons'] ) {
 217              echo '<div id="wp-' . $editor_id_attr . '-editor-tools" class="wp-editor-tools hide-if-no-js">';
 218  
 219              if ( $set['media_buttons'] ) {
 220                  self::$has_medialib = true;
 221  
 222                  if ( ! function_exists( 'media_buttons' ) ) {
 223                      require ABSPATH . 'wp-admin/includes/media.php';
 224                  }
 225  
 226                  echo '<div id="wp-' . $editor_id_attr . '-media-buttons" class="wp-media-buttons">';
 227  
 228                  /**
 229                   * Fires after the default media button(s) are displayed.
 230                   *
 231                   * @since 2.5.0
 232                   *
 233                   * @param string $editor_id Unique editor identifier, e.g. 'content'.
 234                   */
 235                  do_action( 'media_buttons', $editor_id );
 236                  echo "</div>\n";
 237              }
 238  
 239              echo '<div class="wp-editor-tabs">' . $buttons . "</div>\n";
 240              echo "</div>\n";
 241          }
 242  
 243          $quicktags_toolbar = '';
 244  
 245          if ( self::$this_quicktags ) {
 246              if ( 'content' === $editor_id && ! empty( $GLOBALS['current_screen'] ) && 'post' === $GLOBALS['current_screen']->base ) {
 247                  $toolbar_id = 'ed_toolbar';
 248              } else {
 249                  $toolbar_id = 'qt_' . $editor_id_attr . '_toolbar';
 250              }
 251  
 252              $quicktags_toolbar = '<div id="' . $toolbar_id . '" class="quicktags-toolbar"></div>';
 253          }
 254  
 255          /**
 256           * Filters the HTML markup output that displays the editor.
 257           *
 258           * @since 2.1.0
 259           *
 260           * @param string $output Editor's HTML markup.
 261           */
 262          $the_editor = apply_filters(
 263              'the_editor',
 264              '<div id="wp-' . $editor_id_attr . '-editor-container" class="wp-editor-container">' .
 265              $quicktags_toolbar .
 266              '<textarea' . $editor_class . $height . $tabindex . $autocomplete . ' cols="40" name="' . esc_attr( $set['textarea_name'] ) . '" ' .
 267              'id="' . $editor_id_attr . '">%s</textarea></div>'
 268          );
 269  
 270          // Prepare the content for the Visual or Text editor, only when TinyMCE is used (back-compat).
 271          if ( self::$this_tinymce ) {
 272              add_filter( 'the_editor_content', 'format_for_editor', 10, 2 );
 273          }
 274  
 275          /**
 276           * Filters the default editor content.
 277           *
 278           * @since 2.1.0
 279           *
 280           * @param string $content        Default editor content.
 281           * @param string $default_editor The default editor for the current user.
 282           *                               Either 'html' or 'tinymce'.
 283           */
 284          $content = apply_filters( 'the_editor_content', $content, $default_editor );
 285  
 286          // Remove the filter as the next editor on the same page may not need it.
 287          if ( self::$this_tinymce ) {
 288              remove_filter( 'the_editor_content', 'format_for_editor' );
 289          }
 290  
 291          // Back-compat for the `htmledit_pre` and `richedit_pre` filters.
 292          if ( 'html' === $default_editor && has_filter( 'htmledit_pre' ) ) {
 293              /** This filter is documented in wp-includes/deprecated.php */
 294              $content = apply_filters_deprecated( 'htmledit_pre', array( $content ), '4.3.0', 'format_for_editor' );
 295          } elseif ( 'tinymce' === $default_editor && has_filter( 'richedit_pre' ) ) {
 296              /** This filter is documented in wp-includes/deprecated.php */
 297              $content = apply_filters_deprecated( 'richedit_pre', array( $content ), '4.3.0', 'format_for_editor' );
 298          }
 299  
 300          if ( false !== stripos( $content, 'textarea' ) ) {
 301              $content = preg_replace( '%</textarea%i', '&lt;/textarea', $content );
 302          }
 303  
 304          printf( $the_editor, $content );
 305          echo "\n</div>\n\n";
 306  
 307          self::editor_settings( $editor_id, $set );
 308      }
 309  
 310      /**
 311       * @since 3.3.0
 312       *
 313       * @global string $tinymce_version
 314       *
 315       * @param string $editor_id Unique editor identifier, e.g. 'content'.
 316       * @param array  $set       Array of editor arguments.
 317       */
 318  	public static function editor_settings( $editor_id, $set ) {
 319          global $tinymce_version;
 320  
 321          if ( empty( self::$first_init ) ) {
 322              if ( is_admin() ) {
 323                  add_action( 'admin_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
 324                  add_action( 'admin_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
 325                  add_action( 'admin_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
 326              } else {
 327                  add_action( 'wp_print_footer_scripts', array( __CLASS__, 'editor_js' ), 50 );
 328                  add_action( 'wp_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
 329                  add_action( 'wp_print_footer_scripts', array( __CLASS__, 'enqueue_scripts' ), 1 );
 330              }
 331          }
 332  
 333          if ( self::$this_quicktags ) {
 334  
 335              $qtInit = array(
 336                  'id'      => $editor_id,
 337                  'buttons' => '',
 338              );
 339  
 340              if ( is_array( $set['quicktags'] ) ) {
 341                  $qtInit = array_merge( $qtInit, $set['quicktags'] );
 342              }
 343  
 344              if ( empty( $qtInit['buttons'] ) ) {
 345                  $qtInit['buttons'] = 'strong,em,link,block,del,ins,img,ul,ol,li,code,more,close';
 346              }
 347  
 348              if ( $set['_content_editor_dfw'] ) {
 349                  $qtInit['buttons'] .= ',dfw';
 350              }
 351  
 352              /**
 353               * Filters the Quicktags settings.
 354               *
 355               * @since 3.3.0
 356               *
 357               * @param array  $qtInit    Quicktags settings.
 358               * @param string $editor_id Unique editor identifier, e.g. 'content'.
 359               */
 360              $qtInit = apply_filters( 'quicktags_settings', $qtInit, $editor_id );
 361  
 362              self::$qt_settings[ $editor_id ] = $qtInit;
 363  
 364              self::$qt_buttons = array_merge( self::$qt_buttons, explode( ',', $qtInit['buttons'] ) );
 365          }
 366  
 367          if ( self::$this_tinymce ) {
 368  
 369              if ( empty( self::$first_init ) ) {
 370                  $baseurl     = self::get_baseurl();
 371                  $mce_locale  = self::get_mce_locale();
 372                  $ext_plugins = '';
 373  
 374                  if ( $set['teeny'] ) {
 375  
 376                      /**
 377                       * Filters the list of teenyMCE plugins.
 378                       *
 379                       * @since 2.7.0
 380                       * @since 3.3.0 The `$editor_id` parameter was added.
 381                       *
 382                       * @param array  $plugins   An array of teenyMCE plugins.
 383                       * @param string $editor_id Unique editor identifier, e.g. 'content'.
 384                       */
 385                      $plugins = apply_filters(
 386                          'teeny_mce_plugins',
 387                          array(
 388                              'colorpicker',
 389                              'lists',
 390                              'fullscreen',
 391                              'image',
 392                              'wordpress',
 393                              'wpeditimage',
 394                              'wplink',
 395                          ),
 396                          $editor_id
 397                      );
 398                  } else {
 399  
 400                      /**
 401                       * Filters the list of TinyMCE external plugins.
 402                       *
 403                       * The filter takes an associative array of external plugins for
 404                       * TinyMCE in the form 'plugin_name' => 'url'.
 405                       *
 406                       * The url should be absolute, and should include the js filename
 407                       * to be loaded. For example:
 408                       * 'myplugin' => 'http://mysite.com/wp-content/plugins/myfolder/mce_plugin.js'.
 409                       *
 410                       * If the external plugin adds a button, it should be added with
 411                       * one of the 'mce_buttons' filters.
 412                       *
 413                       * @since 2.5.0
 414                       * @since 5.3.0 The `$editor_id` parameter was added.
 415                       *
 416                       * @param array  $external_plugins An array of external TinyMCE plugins.
 417                       * @param string $editor_id        Unique editor identifier, e.g. 'content'. Accepts 'classic-block'
 418                       *                                 when called from block editor's Classic block.
 419                       */
 420                      $mce_external_plugins = apply_filters( 'mce_external_plugins', array(), $editor_id );
 421  
 422                      $plugins = array(
 423                          'charmap',
 424                          'colorpicker',
 425                          'hr',
 426                          'lists',
 427                          'media',
 428                          'paste',
 429                          'tabfocus',
 430                          'textcolor',
 431                          'fullscreen',
 432                          'wordpress',
 433                          'wpautoresize',
 434                          'wpeditimage',
 435                          'wpemoji',
 436                          'wpgallery',
 437                          'wplink',
 438                          'wpdialogs',
 439                          'wptextpattern',
 440                          'wpview',
 441                      );
 442  
 443                      if ( ! self::$has_medialib ) {
 444                          $plugins[] = 'image';
 445                      }
 446  
 447                      /**
 448                       * Filters the list of default TinyMCE plugins.
 449                       *
 450                       * The filter specifies which of the default plugins included
 451                       * in WordPress should be added to the TinyMCE instance.
 452                       *
 453                       * @since 3.3.0
 454                       * @since 5.3.0 The `$editor_id` parameter was added.
 455                       *
 456                       * @param array  $plugins   An array of default TinyMCE plugins.
 457                       * @param string $editor_id Unique editor identifier, e.g. 'content'. Accepts 'classic-block'
 458                       *                          when called from block editor's Classic block.
 459                       */
 460                      $plugins = array_unique( apply_filters( 'tiny_mce_plugins', $plugins, $editor_id ) );
 461  
 462                      $key = array_search( 'spellchecker', $plugins );
 463                      if ( false !== $key ) {
 464                          // Remove 'spellchecker' from the internal plugins if added with 'tiny_mce_plugins' filter to prevent errors.
 465                          // It can be added with 'mce_external_plugins'.
 466                          unset( $plugins[ $key ] );
 467                      }
 468  
 469                      if ( ! empty( $mce_external_plugins ) ) {
 470  
 471                          /**
 472                           * Filters the translations loaded for external TinyMCE 3.x plugins.
 473                           *
 474                           * The filter takes an associative array ('plugin_name' => 'path')
 475                           * where 'path' is the include path to the file.
 476                           *
 477                           * The language file should follow the same format as wp_mce_translation(),
 478                           * and should define a variable ($strings) that holds all translated strings.
 479                           *
 480                           * @since 2.5.0
 481                           * @since 5.3.0 The `$editor_id` parameter was added.
 482                           *
 483                           * @param array  $translations Translations for external TinyMCE plugins.
 484                           * @param string $editor_id    Unique editor identifier, e.g. 'content'.
 485                           */
 486                          $mce_external_languages = apply_filters( 'mce_external_languages', array(), $editor_id );
 487  
 488                          $loaded_langs = array();
 489                          $strings      = '';
 490  
 491                          if ( ! empty( $mce_external_languages ) ) {
 492                              foreach ( $mce_external_languages as $name => $path ) {
 493                                  if ( @is_file( $path ) && @is_readable( $path ) ) {
 494                                      include_once $path;
 495                                      $ext_plugins   .= $strings . "\n";
 496                                      $loaded_langs[] = $name;
 497                                  }
 498                              }
 499                          }
 500  
 501                          foreach ( $mce_external_plugins as $name => $url ) {
 502                              if ( in_array( $name, $plugins, true ) ) {
 503                                  unset( $mce_external_plugins[ $name ] );
 504                                  continue;
 505                              }
 506  
 507                              $url                           = set_url_scheme( $url );
 508                              $mce_external_plugins[ $name ] = $url;
 509                              $plugurl                       = dirname( $url );
 510                              $strings                       = '';
 511  
 512                              // Try to load langs/[locale].js and langs/[locale]_dlg.js.
 513                              if ( ! in_array( $name, $loaded_langs, true ) ) {
 514                                  $path = str_replace( content_url(), '', $plugurl );
 515                                  $path = WP_CONTENT_DIR . $path . '/langs/';
 516  
 517                                  $path = trailingslashit( realpath( $path ) );
 518  
 519                                  if ( @is_file( $path . $mce_locale . '.js' ) ) {
 520                                      $strings .= @file_get_contents( $path . $mce_locale . '.js' ) . "\n";
 521                                  }
 522  
 523                                  if ( @is_file( $path . $mce_locale . '_dlg.js' ) ) {
 524                                      $strings .= @file_get_contents( $path . $mce_locale . '_dlg.js' ) . "\n";
 525                                  }
 526  
 527                                  if ( 'en' != $mce_locale && empty( $strings ) ) {
 528                                      if ( @is_file( $path . 'en.js' ) ) {
 529                                          $str1     = @file_get_contents( $path . 'en.js' );
 530                                          $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str1, 1 ) . "\n";
 531                                      }
 532  
 533                                      if ( @is_file( $path . 'en_dlg.js' ) ) {
 534                                          $str2     = @file_get_contents( $path . 'en_dlg.js' );
 535                                          $strings .= preg_replace( '/([\'"])en\./', '$1' . $mce_locale . '.', $str2, 1 ) . "\n";
 536                                      }
 537                                  }
 538  
 539                                  if ( ! empty( $strings ) ) {
 540                                      $ext_plugins .= "\n" . $strings . "\n";
 541                                  }
 542                              }
 543  
 544                              $ext_plugins .= 'tinyMCEPreInit.load_ext("' . $plugurl . '", "' . $mce_locale . '");' . "\n";
 545                          }
 546                      }
 547                  }
 548  
 549                  self::$plugins     = $plugins;
 550                  self::$ext_plugins = $ext_plugins;
 551  
 552                  $settings            = self::default_settings();
 553                  $settings['plugins'] = implode( ',', $plugins );
 554  
 555                  if ( ! empty( $mce_external_plugins ) ) {
 556                      $settings['external_plugins'] = wp_json_encode( $mce_external_plugins );
 557                  }
 558  
 559                  /** This filter is documented in wp-admin/includes/media.php */
 560                  if ( apply_filters( 'disable_captions', '' ) ) {
 561                      $settings['wpeditimage_disable_captions'] = true;
 562                  }
 563  
 564                  $mce_css = $settings['content_css'];
 565  
 566                  /*
 567                   * The `editor-style.css` added by the theme is generally intended for the editor instance on the Edit Post screen.
 568                   * Plugins that use wp_editor() on the front-end can decide whether to add the theme stylesheet
 569                   * by using `get_editor_stylesheets()` and the `mce_css` or `tiny_mce_before_init` filters, see below.
 570                   */
 571                  if ( is_admin() ) {
 572                      $editor_styles = get_editor_stylesheets();
 573  
 574                      if ( ! empty( $editor_styles ) ) {
 575                          // Force urlencoding of commas.
 576                          foreach ( $editor_styles as $key => $url ) {
 577                              if ( strpos( $url, ',' ) !== false ) {
 578                                  $editor_styles[ $key ] = str_replace( ',', '%2C', $url );
 579                              }
 580                          }
 581  
 582                          $mce_css .= ',' . implode( ',', $editor_styles );
 583                      }
 584                  }
 585  
 586                  /**
 587                   * Filters the comma-delimited list of stylesheets to load in TinyMCE.
 588                   *
 589                   * @since 2.1.0
 590                   *
 591                   * @param string $stylesheets Comma-delimited list of stylesheets.
 592                   */
 593                  $mce_css = trim( apply_filters( 'mce_css', $mce_css ), ' ,' );
 594  
 595                  if ( ! empty( $mce_css ) ) {
 596                      $settings['content_css'] = $mce_css;
 597                  } else {
 598                      unset( $settings['content_css'] );
 599                  }
 600  
 601                  self::$first_init = $settings;
 602              }
 603  
 604              if ( $set['teeny'] ) {
 605                  $mce_buttons = array(
 606                      'bold',
 607                      'italic',
 608                      'underline',
 609                      'blockquote',
 610                      'strikethrough',
 611                      'bullist',
 612                      'numlist',
 613                      'alignleft',
 614                      'aligncenter',
 615                      'alignright',
 616                      'undo',
 617                      'redo',
 618                      'link',
 619                      'fullscreen',
 620                  );
 621  
 622                  /**
 623                   * Filters the list of teenyMCE buttons (Text tab).
 624                   *
 625                   * @since 2.7.0
 626                   * @since 3.3.0 The `$editor_id` parameter was added.
 627                   *
 628                   * @param array  $mce_buttons An array of teenyMCE buttons.
 629                   * @param string $editor_id   Unique editor identifier, e.g. 'content'.
 630                   */
 631                  $mce_buttons   = apply_filters( 'teeny_mce_buttons', $mce_buttons, $editor_id );
 632                  $mce_buttons_2 = array();
 633                  $mce_buttons_3 = array();
 634                  $mce_buttons_4 = array();
 635              } else {
 636                  $mce_buttons = array(
 637                      'formatselect',
 638                      'bold',
 639                      'italic',
 640                      'bullist',
 641                      'numlist',
 642                      'blockquote',
 643                      'alignleft',
 644                      'aligncenter',
 645                      'alignright',
 646                      'link',
 647                      'wp_more',
 648                      'spellchecker',
 649                  );
 650  
 651                  if ( ! wp_is_mobile() ) {
 652                      if ( $set['_content_editor_dfw'] ) {
 653                          $mce_buttons[] = 'wp_adv';
 654                          $mce_buttons[] = 'dfw';
 655                      } else {
 656                          $mce_buttons[] = 'fullscreen';
 657                          $mce_buttons[] = 'wp_adv';
 658                      }
 659                  } else {
 660                      $mce_buttons[] = 'wp_adv';
 661                  }
 662  
 663                  /**
 664                   * Filters the first-row list of TinyMCE buttons (Visual tab).
 665                   *
 666                   * @since 2.0.0
 667                   * @since 3.3.0 The `$editor_id` parameter was added.
 668                   *
 669                   * @param array  $mce_buttons First-row list of buttons.
 670                   * @param string $editor_id   Unique editor identifier, e.g. 'content'. Accepts 'classic-block'
 671                   *                            when called from block editor's Classic block.
 672                   */
 673                  $mce_buttons = apply_filters( 'mce_buttons', $mce_buttons, $editor_id );
 674  
 675                  $mce_buttons_2 = array(
 676                      'strikethrough',
 677                      'hr',
 678                      'forecolor',
 679                      'pastetext',
 680                      'removeformat',
 681                      'charmap',
 682                      'outdent',
 683                      'indent',
 684                      'undo',
 685                      'redo',
 686                  );
 687  
 688                  if ( ! wp_is_mobile() ) {
 689                      $mce_buttons_2[] = 'wp_help';
 690                  }
 691  
 692                  /**
 693                   * Filters the second-row list of TinyMCE buttons (Visual tab).
 694                   *
 695                   * @since 2.0.0
 696                   * @since 3.3.0 The `$editor_id` parameter was added.
 697                   *
 698                   * @param array  $mce_buttons_2 Second-row list of buttons.
 699                   * @param string $editor_id     Unique editor identifier, e.g. 'content'. Accepts 'classic-block'
 700                   *                              when called from block editor's Classic block.
 701                   */
 702                  $mce_buttons_2 = apply_filters( 'mce_buttons_2', $mce_buttons_2, $editor_id );
 703  
 704                  /**
 705                   * Filters the third-row list of TinyMCE buttons (Visual tab).
 706                   *
 707                   * @since 2.0.0
 708                   * @since 3.3.0 The `$editor_id` parameter was added.
 709                   *
 710                   * @param array  $mce_buttons_3 Third-row list of buttons.
 711                   * @param string $editor_id     Unique editor identifier, e.g. 'content'. Accepts 'classic-block'
 712                   *                              when called from block editor's Classic block.
 713                   */
 714                  $mce_buttons_3 = apply_filters( 'mce_buttons_3', array(), $editor_id );
 715  
 716                  /**
 717                   * Filters the fourth-row list of TinyMCE buttons (Visual tab).
 718                   *
 719                   * @since 2.5.0
 720                   * @since 3.3.0 The `$editor_id` parameter was added.
 721                   *
 722                   * @param array  $mce_buttons_4 Fourth-row list of buttons.
 723                   * @param string $editor_id     Unique editor identifier, e.g. 'content'. Accepts 'classic-block'
 724                   *                              when called from block editor's Classic block.
 725                   */
 726                  $mce_buttons_4 = apply_filters( 'mce_buttons_4', array(), $editor_id );
 727              }
 728  
 729              $body_class = $editor_id;
 730  
 731              $post = get_post();
 732              if ( $post ) {
 733                  $body_class .= ' post-type-' . sanitize_html_class( $post->post_type ) . ' post-status-' . sanitize_html_class( $post->post_status );
 734  
 735                  if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
 736                      $post_format = get_post_format( $post );
 737                      if ( $post_format && ! is_wp_error( $post_format ) ) {
 738                          $body_class .= ' post-format-' . sanitize_html_class( $post_format );
 739                      } else {
 740                          $body_class .= ' post-format-standard';
 741                      }
 742                  }
 743  
 744                  $page_template = get_page_template_slug( $post );
 745  
 746                  if ( false !== $page_template ) {
 747                      $page_template = empty( $page_template ) ? 'default' : str_replace( '.', '-', basename( $page_template, '.php' ) );
 748                      $body_class   .= ' page-template-' . sanitize_html_class( $page_template );
 749                  }
 750              }
 751  
 752              $body_class .= ' locale-' . sanitize_html_class( strtolower( str_replace( '_', '-', get_user_locale() ) ) );
 753  
 754              if ( ! empty( $set['tinymce']['body_class'] ) ) {
 755                  $body_class .= ' ' . $set['tinymce']['body_class'];
 756                  unset( $set['tinymce']['body_class'] );
 757              }
 758  
 759              $mceInit = array(
 760                  'selector'          => "#$editor_id",
 761                  'wpautop'           => (bool) $set['wpautop'],
 762                  'indent'            => ! $set['wpautop'],
 763                  'toolbar1'          => implode( ',', $mce_buttons ),
 764                  'toolbar2'          => implode( ',', $mce_buttons_2 ),
 765                  'toolbar3'          => implode( ',', $mce_buttons_3 ),
 766                  'toolbar4'          => implode( ',', $mce_buttons_4 ),
 767                  'tabfocus_elements' => $set['tabfocus_elements'],
 768                  'body_class'        => $body_class,
 769              );
 770  
 771              // Merge with the first part of the init array.
 772              $mceInit = array_merge( self::$first_init, $mceInit );
 773  
 774              if ( is_array( $set['tinymce'] ) ) {
 775                  $mceInit = array_merge( $mceInit, $set['tinymce'] );
 776              }
 777  
 778              /*
 779               * For people who really REALLY know what they're doing with TinyMCE
 780               * You can modify $mceInit to add, remove, change elements of the config
 781               * before tinyMCE.init. Setting "valid_elements", "invalid_elements"
 782               * and "extended_valid_elements" can be done through this filter. Best
 783               * is to use the default cleanup by not specifying valid_elements,
 784               * as TinyMCE checks against the full set of HTML 5.0 elements and attributes.
 785               */
 786              if ( $set['teeny'] ) {
 787  
 788                  /**
 789                   * Filters the teenyMCE config before init.
 790                   *
 791                   * @since 2.7.0
 792                   * @since 3.3.0 The `$editor_id` parameter was added.
 793                   *
 794                   * @param array  $mceInit   An array with teenyMCE config.
 795                   * @param string $editor_id Unique editor identifier, e.g. 'content'.
 796                   */
 797                  $mceInit = apply_filters( 'teeny_mce_before_init', $mceInit, $editor_id );
 798              } else {
 799  
 800                  /**
 801                   * Filters the TinyMCE config before init.
 802                   *
 803                   * @since 2.5.0
 804                   * @since 3.3.0 The `$editor_id` parameter was added.
 805                   *
 806                   * @param array  $mceInit   An array with TinyMCE config.
 807                   * @param string $editor_id Unique editor identifier, e.g. 'content'. Accepts 'classic-block'
 808                   *                          when called from block editor's Classic block.
 809                   */
 810                  $mceInit = apply_filters( 'tiny_mce_before_init', $mceInit, $editor_id );
 811              }
 812  
 813              if ( empty( $mceInit['toolbar3'] ) && ! empty( $mceInit['toolbar4'] ) ) {
 814                  $mceInit['toolbar3'] = $mceInit['toolbar4'];
 815                  $mceInit['toolbar4'] = '';
 816              }
 817  
 818              self::$mce_settings[ $editor_id ] = $mceInit;
 819          } // End if self::$this_tinymce.
 820      }
 821  
 822      /**
 823       * @since 3.3.0
 824       *
 825       * @param array $init
 826       * @return string
 827       */
 828  	private static function _parse_init( $init ) {
 829          $options = '';
 830  
 831          foreach ( $init as $key => $value ) {
 832              if ( is_bool( $value ) ) {
 833                  $val      = $value ? 'true' : 'false';
 834                  $options .= $key . ':' . $val . ',';
 835                  continue;
 836              } elseif ( ! empty( $value ) && is_string( $value ) && (
 837                  ( '{' == $value[0] && '}' == $value[ strlen( $value ) - 1 ] ) ||
 838                  ( '[' == $value[0] && ']' == $value[ strlen( $value ) - 1 ] ) ||
 839                  preg_match( '/^\(?function ?\(/', $value ) ) ) {
 840  
 841                  $options .= $key . ':' . $value . ',';
 842                  continue;
 843              }
 844              $options .= $key . ':"' . $value . '",';
 845          }
 846  
 847          return '{' . trim( $options, ' ,' ) . '}';
 848      }
 849  
 850      /**
 851       * @since 3.3.0
 852       *
 853       * @param bool $default_scripts Optional. Whether default scripts should be enqueued. Default false.
 854       */
 855  	public static function enqueue_scripts( $default_scripts = false ) {
 856          if ( $default_scripts || self::$has_tinymce ) {
 857              wp_enqueue_script( 'editor' );
 858          }
 859  
 860          if ( $default_scripts || self::$has_quicktags ) {
 861              wp_enqueue_script( 'quicktags' );
 862              wp_enqueue_style( 'buttons' );
 863          }
 864  
 865          if ( $default_scripts || in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) ) {
 866              wp_enqueue_script( 'wplink' );
 867              wp_enqueue_script( 'jquery-ui-autocomplete' );
 868          }
 869  
 870          if ( self::$has_medialib ) {
 871              add_thickbox();
 872              wp_enqueue_script( 'media-upload' );
 873              wp_enqueue_script( 'wp-embed' );
 874          } elseif ( $default_scripts ) {
 875              wp_enqueue_script( 'media-upload' );
 876          }
 877  
 878          /**
 879           * Fires when scripts and styles are enqueued for the editor.
 880           *
 881           * @since 3.9.0
 882           *
 883           * @param array $to_load An array containing boolean values whether TinyMCE
 884           *                       and Quicktags are being loaded.
 885           */
 886          do_action(
 887              'wp_enqueue_editor',
 888              array(
 889                  'tinymce'   => ( $default_scripts || self::$has_tinymce ),
 890                  'quicktags' => ( $default_scripts || self::$has_quicktags ),
 891              )
 892          );
 893      }
 894  
 895      /**
 896       * Enqueue all editor scripts.
 897       * For use when the editor is going to be initialized after page load.
 898       *
 899       * @since 4.8.0
 900       */
 901  	public static function enqueue_default_editor() {
 902          // We are past the point where scripts can be enqueued properly.
 903          if ( did_action( 'wp_enqueue_editor' ) ) {
 904              return;
 905          }
 906  
 907          self::enqueue_scripts( true );
 908  
 909          // Also add wp-includes/css/editor.css.
 910          wp_enqueue_style( 'editor-buttons' );
 911  
 912          if ( is_admin() ) {
 913              add_action( 'admin_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
 914              add_action( 'admin_print_footer_scripts', array( __CLASS__, 'print_default_editor_scripts' ), 45 );
 915          } else {
 916              add_action( 'wp_print_footer_scripts', array( __CLASS__, 'force_uncompressed_tinymce' ), 1 );
 917              add_action( 'wp_print_footer_scripts', array( __CLASS__, 'print_default_editor_scripts' ), 45 );
 918          }
 919      }
 920  
 921      /**
 922       * Print (output) all editor scripts and default settings.
 923       * For use when the editor is going to be initialized after page load.
 924       *
 925       * @since 4.8.0
 926       */
 927  	public static function print_default_editor_scripts() {
 928          $user_can_richedit = user_can_richedit();
 929  
 930          if ( $user_can_richedit ) {
 931              $settings = self::default_settings();
 932  
 933              $settings['toolbar1']    = 'bold,italic,bullist,numlist,link';
 934              $settings['wpautop']     = false;
 935              $settings['indent']      = true;
 936              $settings['elementpath'] = false;
 937  
 938              if ( is_rtl() ) {
 939                  $settings['directionality'] = 'rtl';
 940              }
 941  
 942              /*
 943               * In production all plugins are loaded (they are in wp-editor.js.gz).
 944               * The 'wpview', 'wpdialogs', and 'media' TinyMCE plugins are not initialized by default.
 945               * Can be added from js by using the 'wp-before-tinymce-init' event.
 946               */
 947              $settings['plugins'] = implode(
 948                  ',',
 949                  array(
 950                      'charmap',
 951                      'colorpicker',
 952                      'hr',
 953                      'lists',
 954                      'paste',
 955                      'tabfocus',
 956                      'textcolor',
 957                      'fullscreen',
 958                      'wordpress',
 959                      'wpautoresize',
 960                      'wpeditimage',
 961                      'wpemoji',
 962                      'wpgallery',
 963                      'wplink',
 964                      'wptextpattern',
 965                  )
 966              );
 967  
 968              $settings = self::_parse_init( $settings );
 969          } else {
 970              $settings = '{}';
 971          }
 972  
 973          ?>
 974          <script type="text/javascript">
 975          window.wp = window.wp || {};
 976          window.wp.editor = window.wp.editor || {};
 977          window.wp.editor.getDefaultSettings = function() {
 978              return {
 979                  tinymce: <?php echo $settings; ?>,
 980                  quicktags: {
 981                      buttons: 'strong,em,link,ul,ol,li,code'
 982                  }
 983              };
 984          };
 985  
 986          <?php
 987  
 988          if ( $user_can_richedit ) {
 989              $suffix  = SCRIPT_DEBUG ? '' : '.min';
 990              $baseurl = self::get_baseurl();
 991  
 992              ?>
 993              var tinyMCEPreInit = {
 994                  baseURL: "<?php echo $baseurl; ?>",
 995                  suffix: "<?php echo $suffix; ?>",
 996                  mceInit: {},
 997                  qtInit: {},
 998                  load_ext: function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
 999              };
1000              <?php
1001          }
1002          ?>
1003          </script>
1004          <?php
1005  
1006          if ( $user_can_richedit ) {
1007              self::print_tinymce_scripts();
1008          }
1009  
1010          /**
1011           * Fires when the editor scripts are loaded for later initialization,
1012           * after all scripts and settings are printed.
1013           *
1014           * @since 4.8.0
1015           */
1016          do_action( 'print_default_editor_scripts' );
1017  
1018          self::wp_link_dialog();
1019      }
1020  
1021      /**
1022       * Returns the TinyMCE locale.
1023       *
1024       * @since 4.8.0
1025       *
1026       * @return string
1027       */
1028  	public static function get_mce_locale() {
1029          if ( empty( self::$mce_locale ) ) {
1030              $mce_locale       = get_user_locale();
1031              self::$mce_locale = empty( $mce_locale ) ? 'en' : strtolower( substr( $mce_locale, 0, 2 ) ); // ISO 639-1.
1032          }
1033  
1034          return self::$mce_locale;
1035      }
1036  
1037      /**
1038       * Returns the TinyMCE base URL.
1039       *
1040       * @since 4.8.0
1041       *
1042       * @return string
1043       */
1044  	public static function get_baseurl() {
1045          if ( empty( self::$baseurl ) ) {
1046              self::$baseurl = includes_url( 'js/tinymce' );
1047          }
1048  
1049          return self::$baseurl;
1050      }
1051  
1052      /**
1053       * Returns the default TinyMCE settings.
1054       * Doesn't include plugins, buttons, editor selector.
1055       *
1056       * @since 4.8.0
1057       *
1058       * @global string $tinymce_version
1059       *
1060       * @return array
1061       */
1062  	private static function default_settings() {
1063          global $tinymce_version;
1064  
1065          $shortcut_labels = array();
1066  
1067          foreach ( self::get_translation() as $name => $value ) {
1068              if ( is_array( $value ) ) {
1069                  $shortcut_labels[ $name ] = $value[1];
1070              }
1071          }
1072  
1073          $settings = array(
1074              'theme'                        => 'modern',
1075              'skin'                         => 'lightgray',
1076              'language'                     => self::get_mce_locale(),
1077              'formats'                      => '{' .
1078                  'alignleft: [' .
1079                      '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"left"}},' .
1080                      '{selector: "img,table,dl.wp-caption", classes: "alignleft"}' .
1081                  '],' .
1082                  'aligncenter: [' .
1083                      '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"center"}},' .
1084                      '{selector: "img,table,dl.wp-caption", classes: "aligncenter"}' .
1085                  '],' .
1086                  'alignright: [' .
1087                      '{selector: "p,h1,h2,h3,h4,h5,h6,td,th,div,ul,ol,li", styles: {textAlign:"right"}},' .
1088                      '{selector: "img,table,dl.wp-caption", classes: "alignright"}' .
1089                  '],' .
1090                  'strikethrough: {inline: "del"}' .
1091              '}',
1092              'relative_urls'                => false,
1093              'remove_script_host'           => false,
1094              'convert_urls'                 => false,
1095              'browser_spellcheck'           => true,
1096              'fix_list_elements'            => true,
1097              'entities'                     => '38,amp,60,lt,62,gt',
1098              'entity_encoding'              => 'raw',
1099              'keep_styles'                  => false,
1100              'cache_suffix'                 => 'wp-mce-' . $tinymce_version,
1101              'resize'                       => 'vertical',
1102              'menubar'                      => false,
1103              'branding'                     => false,
1104  
1105              // Limit the preview styles in the menu/toolbar.
1106              'preview_styles'               => 'font-family font-size font-weight font-style text-decoration text-transform',
1107  
1108              'end_container_on_empty_block' => true,
1109              'wpeditimage_html5_captions'   => true,
1110              'wp_lang_attr'                 => get_bloginfo( 'language' ),
1111              'wp_keep_scroll_position'      => false,
1112              'wp_shortcut_labels'           => wp_json_encode( $shortcut_labels ),
1113          );
1114  
1115          $suffix  = SCRIPT_DEBUG ? '' : '.min';
1116          $version = 'ver=' . get_bloginfo( 'version' );
1117  
1118          // Default stylesheets.
1119          $settings['content_css'] = includes_url( "css/dashicons$suffix.css?$version" ) . ',' .
1120              includes_url( "js/tinymce/skins/wordpress/wp-content.css?$version" );
1121  
1122          return $settings;
1123      }
1124  
1125      /**
1126       * @since 4.7.0
1127       *
1128       * @return array
1129       */
1130  	private static function get_translation() {
1131          if ( empty( self::$translation ) ) {
1132              self::$translation = array(
1133                  // Default TinyMCE strings.
1134                  'New document'                         => __( 'New document' ),
1135                  'Formats'                              => _x( 'Formats', 'TinyMCE' ),
1136  
1137                  'Headings'                             => _x( 'Headings', 'TinyMCE' ),
1138                  'Heading 1'                            => array( __( 'Heading 1' ), 'access1' ),
1139                  'Heading 2'                            => array( __( 'Heading 2' ), 'access2' ),
1140                  'Heading 3'                            => array( __( 'Heading 3' ), 'access3' ),
1141                  'Heading 4'                            => array( __( 'Heading 4' ), 'access4' ),
1142                  'Heading 5'                            => array( __( 'Heading 5' ), 'access5' ),
1143                  'Heading 6'                            => array( __( 'Heading 6' ), 'access6' ),
1144  
1145                  /* translators: Block tags. */
1146                  'Blocks'                               => _x( 'Blocks', 'TinyMCE' ),
1147                  'Paragraph'                            => array( __( 'Paragraph' ), 'access7' ),
1148                  'Blockquote'                           => array( __( 'Blockquote' ), 'accessQ' ),
1149                  'Div'                                  => _x( 'Div', 'HTML tag' ),
1150                  'Pre'                                  => _x( 'Pre', 'HTML tag' ),
1151                  'Preformatted'                         => _x( 'Preformatted', 'HTML tag' ),
1152                  'Address'                              => _x( 'Address', 'HTML tag' ),
1153  
1154                  'Inline'                               => _x( 'Inline', 'HTML elements' ),
1155                  'Underline'                            => array( __( 'Underline' ), 'metaU' ),
1156                  'Strikethrough'                        => array( __( 'Strikethrough' ), 'accessD' ),
1157                  'Subscript'                            => __( 'Subscript' ),
1158                  'Superscript'                          => __( 'Superscript' ),
1159                  'Clear formatting'                     => __( 'Clear formatting' ),
1160                  'Bold'                                 => array( __( 'Bold' ), 'metaB' ),
1161                  'Italic'                               => array( __( 'Italic' ), 'metaI' ),
1162                  'Code'                                 => array( __( 'Code' ), 'accessX' ),
1163                  'Source code'                          => __( 'Source code' ),
1164                  'Font Family'                          => __( 'Font Family' ),
1165                  'Font Sizes'                           => __( 'Font Sizes' ),
1166  
1167                  'Align center'                         => array( __( 'Align center' ), 'accessC' ),
1168                  'Align right'                          => array( __( 'Align right' ), 'accessR' ),
1169                  'Align left'                           => array( __( 'Align left' ), 'accessL' ),
1170                  'Justify'                              => array( __( 'Justify' ), 'accessJ' ),
1171                  'Increase indent'                      => __( 'Increase indent' ),
1172                  'Decrease indent'                      => __( 'Decrease indent' ),
1173  
1174                  'Cut'                                  => array( __( 'Cut' ), 'metaX' ),
1175                  'Copy'                                 => array( __( 'Copy' ), 'metaC' ),
1176                  'Paste'                                => array( __( 'Paste' ), 'metaV' ),
1177                  'Select all'                           => array( __( 'Select all' ), 'metaA' ),
1178                  'Undo'                                 => array( __( 'Undo' ), 'metaZ' ),
1179                  'Redo'                                 => array( __( 'Redo' ), 'metaY' ),
1180  
1181                  'Ok'                                   => __( 'OK' ),
1182                  'Cancel'                               => __( 'Cancel' ),
1183                  'Close'                                => __( 'Close' ),
1184                  'Visual aids'                          => __( 'Visual aids' ),
1185  
1186                  'Bullet list'                          => array( __( 'Bulleted list' ), 'accessU' ),
1187                  'Numbered list'                        => array( __( 'Numbered list' ), 'accessO' ),
1188                  'Square'                               => _x( 'Square', 'list style' ),
1189                  'Default'                              => _x( 'Default', 'list style' ),
1190                  'Circle'                               => _x( 'Circle', 'list style' ),
1191                  'Disc'                                 => _x( 'Disc', 'list style' ),
1192                  'Lower Greek'                          => _x( 'Lower Greek', 'list style' ),
1193                  'Lower Alpha'                          => _x( 'Lower Alpha', 'list style' ),
1194                  'Upper Alpha'                          => _x( 'Upper Alpha', 'list style' ),
1195                  'Upper Roman'                          => _x( 'Upper Roman', 'list style' ),
1196                  'Lower Roman'                          => _x( 'Lower Roman', 'list style' ),
1197  
1198                  // Anchor plugin.
1199                  'Name'                                 => _x( 'Name', 'Name of link anchor (TinyMCE)' ),
1200                  'Anchor'                               => _x( 'Anchor', 'Link anchor (TinyMCE)' ),
1201                  'Anchors'                              => _x( 'Anchors', 'Link anchors (TinyMCE)' ),
1202                  'Id should start with a letter, followed only by letters, numbers, dashes, dots, colons or underscores.' =>
1203                      __( 'Id should start with a letter, followed only by letters, numbers, dashes, dots, colons or underscores.' ),
1204                  'Id'                                   => _x( 'Id', 'Id for link anchor (TinyMCE)' ),
1205  
1206                  // Fullpage plugin.
1207                  'Document properties'                  => __( 'Document properties' ),
1208                  'Robots'                               => __( 'Robots' ),
1209                  'Title'                                => __( 'Title' ),
1210                  'Keywords'                             => __( 'Keywords' ),
1211                  'Encoding'                             => __( 'Encoding' ),
1212                  'Description'                          => __( 'Description' ),
1213                  'Author'                               => __( 'Author' ),
1214  
1215                  // Media, image plugins.
1216                  'Image'                                => __( 'Image' ),
1217                  'Insert/edit image'                    => array( __( 'Insert/edit image' ), 'accessM' ),
1218                  'General'                              => __( 'General' ),
1219                  'Advanced'                             => __( 'Advanced' ),
1220                  'Source'                               => __( 'Source' ),
1221                  'Border'                               => __( 'Border' ),
1222                  'Constrain proportions'                => __( 'Constrain proportions' ),
1223                  'Vertical space'                       => __( 'Vertical space' ),
1224                  'Image description'                    => __( 'Image description' ),
1225                  'Style'                                => __( 'Style' ),
1226                  'Dimensions'                           => __( 'Dimensions' ),
1227                  'Insert image'                         => __( 'Insert image' ),
1228                  'Date/time'                            => __( 'Date/time' ),
1229                  'Insert date/time'                     => __( 'Insert date/time' ),
1230                  'Table of Contents'                    => __( 'Table of Contents' ),
1231                  'Insert/Edit code sample'              => __( 'Insert/edit code sample' ),
1232                  'Language'                             => __( 'Language' ),
1233                  'Media'                                => __( 'Media' ),
1234                  'Insert/edit media'                    => __( 'Insert/edit media' ),
1235                  'Poster'                               => __( 'Poster' ),
1236                  'Alternative source'                   => __( 'Alternative source' ),
1237                  'Paste your embed code below:'         => __( 'Paste your embed code below:' ),
1238                  'Insert video'                         => __( 'Insert video' ),
1239                  'Embed'                                => __( 'Embed' ),
1240  
1241                  // Each of these have a corresponding plugin.
1242                  'Special character'                    => __( 'Special character' ),
1243                  'Right to left'                        => _x( 'Right to left', 'editor button' ),
1244                  'Left to right'                        => _x( 'Left to right', 'editor button' ),
1245                  'Emoticons'                            => __( 'Emoticons' ),
1246                  'Nonbreaking space'                    => __( 'Nonbreaking space' ),
1247                  'Page break'                           => __( 'Page break' ),
1248                  'Paste as text'                        => __( 'Paste as text' ),
1249                  'Preview'                              => __( 'Preview' ),
1250                  'Print'                                => __( 'Print' ),
1251                  'Save'                                 => __( 'Save' ),
1252                  'Fullscreen'                           => __( 'Fullscreen' ),
1253                  'Horizontal line'                      => __( 'Horizontal line' ),
1254                  'Horizontal space'                     => __( 'Horizontal space' ),
1255                  'Restore last draft'                   => __( 'Restore last draft' ),
1256                  'Insert/edit link'                     => array( __( 'Insert/edit link' ), 'metaK' ),
1257                  'Remove link'                          => array( __( 'Remove link' ), 'accessS' ),
1258  
1259                  // Link plugin.
1260                  'Link'                                 => __( 'Link' ),
1261                  'Insert link'                          => __( 'Insert link' ),
1262                  'Target'                               => __( 'Target' ),
1263                  'New window'                           => __( 'New window' ),
1264                  'Text to display'                      => __( 'Text to display' ),
1265                  'Url'                                  => __( 'URL' ),
1266                  'The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?' =>
1267                      __( 'The URL you entered seems to be an email address. Do you want to add the required mailto: prefix?' ),
1268                  'The URL you entered seems to be an external link. Do you want to add the required http:// prefix?' =>
1269                      __( 'The URL you entered seems to be an external link. Do you want to add the required http:// prefix?' ),
1270  
1271                  'Color'                                => __( 'Color' ),
1272                  'Custom color'                         => __( 'Custom color' ),
1273                  'Custom...'                            => _x( 'Custom...', 'label for custom color' ), // No ellipsis.
1274                  'No color'                             => __( 'No color' ),
1275                  'R'                                    => _x( 'R', 'Short for red in RGB' ),
1276                  'G'                                    => _x( 'G', 'Short for green in RGB' ),
1277                  'B'                                    => _x( 'B', 'Short for blue in RGB' ),
1278  
1279                  // Spelling, search/replace plugins.
1280                  'Could not find the specified string.' => __( 'Could not find the specified string.' ),
1281                  'Replace'                              => _x( 'Replace', 'find/replace' ),
1282                  'Next'                                 => _x( 'Next', 'find/replace' ),
1283                  /* translators: Previous. */
1284                  'Prev'                                 => _x( 'Prev', 'find/replace' ),
1285                  'Whole words'                          => _x( 'Whole words', 'find/replace' ),
1286                  'Find and replace'                     => __( 'Find and replace' ),
1287                  'Replace with'                         => _x( 'Replace with', 'find/replace' ),
1288                  'Find'                                 => _x( 'Find', 'find/replace' ),
1289                  'Replace all'                          => _x( 'Replace all', 'find/replace' ),
1290                  'Match case'                           => __( 'Match case' ),
1291                  'Spellcheck'                           => __( 'Check Spelling' ),
1292                  'Finish'                               => _x( 'Finish', 'spellcheck' ),
1293                  'Ignore all'                           => _x( 'Ignore all', 'spellcheck' ),
1294                  'Ignore'                               => _x( 'Ignore', 'spellcheck' ),
1295                  'Add to Dictionary'                    => __( 'Add to Dictionary' ),
1296  
1297                  // TinyMCE tables.
1298                  'Insert table'                         => __( 'Insert table' ),
1299                  'Delete table'                         => __( 'Delete table' ),
1300                  'Table properties'                     => __( 'Table properties' ),
1301                  'Row properties'                       => __( 'Table row properties' ),
1302                  'Cell properties'                      => __( 'Table cell properties' ),
1303                  'Border color'                         => __( 'Border color' ),
1304  
1305                  'Row'                                  => __( 'Row' ),
1306                  'Rows'                                 => __( 'Rows' ),
1307                  'Column'                               => _x( 'Column', 'table column' ),
1308                  'Cols'                                 => _x( 'Cols', 'table columns' ),
1309                  'Cell'                                 => _x( 'Cell', 'table cell' ),
1310                  'Header cell'                          => __( 'Header cell' ),
1311                  'Header'                               => _x( 'Header', 'table header' ),
1312                  'Body'                                 => _x( 'Body', 'table body' ),
1313                  'Footer'                               => _x( 'Footer', 'table footer' ),
1314  
1315                  'Insert row before'                    => __( 'Insert row before' ),
1316                  'Insert row after'                     => __( 'Insert row after' ),
1317                  'Insert column before'                 => __( 'Insert column before' ),
1318                  'Insert column after'                  => __( 'Insert column after' ),
1319                  'Paste row before'                     => __( 'Paste table row before' ),
1320                  'Paste row after'                      => __( 'Paste table row after' ),
1321                  'Delete row'                           => __( 'Delete row' ),
1322                  'Delete column'                        => __( 'Delete column' ),
1323                  'Cut row'                              => __( 'Cut table row' ),
1324                  'Copy row'                             => __( 'Copy table row' ),
1325                  'Merge cells'                          => __( 'Merge table cells' ),
1326                  'Split cell'                           => __( 'Split table cell' ),
1327  
1328                  'Height'                               => __( 'Height' ),
1329                  'Width'                                => __( 'Width' ),
1330                  'Caption'                              => __( 'Caption' ),
1331                  'Alignment'                            => __( 'Alignment' ),
1332                  'H Align'                              => _x( 'H Align', 'horizontal table cell alignment' ),
1333                  'Left'                                 => __( 'Left' ),
1334                  'Center'                               => __( 'Center' ),
1335                  'Right'                                => __( 'Right' ),
1336                  'None'                                 => _x( 'None', 'table cell alignment attribute' ),
1337                  'V Align'                              => _x( 'V Align', 'vertical table cell alignment' ),
1338                  'Top'                                  => __( 'Top' ),
1339                  'Middle'                               => __( 'Middle' ),
1340                  'Bottom'                               => __( 'Bottom' ),
1341  
1342                  'Row group'                            => __( 'Row group' ),
1343                  'Column group'                         => __( 'Column group' ),
1344                  'Row type'                             => __( 'Row type' ),
1345                  'Cell type'                            => __( 'Cell type' ),
1346                  'Cell padding'                         => __( 'Cell padding' ),
1347                  'Cell spacing'                         => __( 'Cell spacing' ),
1348                  'Scope'                                => _x( 'Scope', 'table cell scope attribute' ),
1349  
1350                  'Insert template'                      => _x( 'Insert template', 'TinyMCE' ),
1351                  'Templates'                            => _x( 'Templates', 'TinyMCE' ),
1352  
1353                  'Background color'                     => __( 'Background color' ),
1354                  'Text color'                           => __( 'Text color' ),
1355                  'Show blocks'                          => _x( 'Show blocks', 'editor button' ),
1356                  'Show invisible characters'            => __( 'Show invisible characters' ),
1357  
1358                  /* translators: Word count. */
1359                  'Words: {0}'                           => sprintf( __( 'Words: %s' ), '{0}' ),
1360                  'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' =>
1361                      __( 'Paste is now in plain text mode. Contents will now be pasted as plain text until you toggle this option off.' ) . "\n\n" .
1362                      __( '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.' ),
1363                  'Rich Text Area. Press ALT-F9 for menu. Press ALT-F10 for toolbar. Press ALT-0 for help' =>
1364                      __( 'Rich Text Area. Press Alt-Shift-H for help.' ),
1365                  'Rich Text Area. Press Control-Option-H for help.' => __( 'Rich Text Area. Press Control-Option-H for help.' ),
1366                  'You have unsaved changes are you sure you want to navigate away?' =>
1367                      __( 'The changes you made will be lost if you navigate away from this page.' ),
1368                  'Your browser doesn\'t support direct access to the clipboard. Please use the Ctrl+X/C/V keyboard shortcuts instead.' =>
1369                      __( 'Your browser does not support direct access to the clipboard. Please use keyboard shortcuts or your browser&#8217;s edit menu instead.' ),
1370  
1371                  // TinyMCE menus.
1372                  'Insert'                               => _x( 'Insert', 'TinyMCE menu' ),
1373                  'File'                                 => _x( 'File', 'TinyMCE menu' ),
1374                  'Edit'                                 => _x( 'Edit', 'TinyMCE menu' ),
1375                  'Tools'                                => _x( 'Tools', 'TinyMCE menu' ),
1376                  'View'                                 => _x( 'View', 'TinyMCE menu' ),
1377                  'Table'                                => _x( 'Table', 'TinyMCE menu' ),
1378                  'Format'                               => _x( 'Format', 'TinyMCE menu' ),
1379  
1380                  // WordPress strings.
1381                  'Toolbar Toggle'                       => array( __( 'Toolbar Toggle' ), 'accessZ' ),
1382                  'Insert Read More tag'                 => array( __( 'Insert Read More tag' ), 'accessT' ),
1383                  'Insert Page Break tag'                => array( __( 'Insert Page Break tag' ), 'accessP' ),
1384                  'Read more...'                         => __( 'Read more...' ), // Title on the placeholder inside the editor (no ellipsis).
1385                  'Distraction-free writing mode'        => array( __( 'Distraction-free writing mode' ), 'accessW' ),
1386                  'No alignment'                         => __( 'No alignment' ), // Tooltip for the 'alignnone' button in the image toolbar.
1387                  'Remove'                               => __( 'Remove' ),       // Tooltip for the 'remove' button in the image toolbar.
1388                  'Edit|button'                          => __( 'Edit' ),         // Tooltip for the 'edit' button in the image toolbar.
1389                  'Paste URL or type to search'          => __( 'Paste URL or type to search' ), // Placeholder for the inline link dialog.
1390                  'Apply'                                => __( 'Apply' ),        // Tooltip for the 'apply' button in the inline link dialog.
1391                  'Link options'                         => __( 'Link options' ), // Tooltip for the 'link options' button in the inline link dialog.
1392                  'Visual'                               => _x( 'Visual', 'Name for the Visual editor tab' ),             // Editor switch tab label.
1393                  'Text'                                 => _x( 'Text', 'Name for the Text editor tab (formerly HTML)' ), // Editor switch tab label.
1394                  'Add Media'                            => array( __( 'Add Media' ), 'accessM' ), // Tooltip for the 'Add Media' button in the block editor Classic block.
1395  
1396                  // Shortcuts help modal.
1397                  'Keyboard Shortcuts'                   => array( __( 'Keyboard Shortcuts' ), 'accessH' ),
1398                  'Classic Block Keyboard Shortcuts'     => __( 'Classic Block Keyboard Shortcuts' ),
1399                  'Default shortcuts,'                   => __( 'Default shortcuts,' ),
1400                  'Additional shortcuts,'                => __( 'Additional shortcuts,' ),
1401                  'Focus shortcuts:'                     => __( 'Focus shortcuts:' ),
1402                  'Inline toolbar (when an image, link or preview is selected)' => __( 'Inline toolbar (when an image, link or preview is selected)' ),
1403                  'Editor menu (when enabled)'           => __( 'Editor menu (when enabled)' ),
1404                  'Editor toolbar'                       => __( 'Editor toolbar' ),
1405                  'Elements path'                        => __( 'Elements path' ),
1406                  'Ctrl + Alt + letter:'                 => __( 'Ctrl + Alt + letter:' ),
1407                  'Shift + Alt + letter:'                => __( 'Shift + Alt + letter:' ),
1408                  'Cmd + letter:'                        => __( 'Cmd + letter:' ),
1409                  'Ctrl + letter:'                       => __( 'Ctrl + letter:' ),
1410                  'Letter'                               => __( 'Letter' ),
1411                  'Action'                               => __( 'Action' ),
1412                  '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.' ),
1413                  '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.' =>
1414                      __( '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.' ),
1415                  '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.' =>
1416                      __( '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.' ),
1417                  'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' =>
1418                      __( 'The following formatting shortcuts are replaced when pressing Enter. Press Escape or the Undo button to undo.' ),
1419                  '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.' =>
1420                      __( '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.' ),
1421              );
1422          }
1423  
1424          /*
1425          Imagetools plugin (not included):
1426              'Edit image' => __( 'Edit image' ),
1427              'Image options' => __( 'Image options' ),
1428              'Back' => __( 'Back' ),
1429              'Invert' => __( 'Invert' ),
1430              'Flip horizontally' => __( 'Flip horizontal' ),
1431              'Flip vertically' => __( 'Flip vertical' ),
1432              'Crop' => __( 'Crop' ),
1433              'Orientation' => __( 'Orientation' ),
1434              'Resize' => __( 'Resize' ),
1435              'Rotate clockwise' => __( 'Rotate right' ),
1436              'Rotate counterclockwise' => __( 'Rotate left' ),
1437              'Sharpen' => __( 'Sharpen' ),
1438              'Brightness' => __( 'Brightness' ),
1439              'Color levels' => __( 'Color levels' ),
1440              'Contrast' => __( 'Contrast' ),
1441              'Gamma' => __( 'Gamma' ),
1442              'Zoom in' => __( 'Zoom in' ),
1443              'Zoom out' => __( 'Zoom out' ),
1444          */
1445  
1446          return self::$translation;
1447      }
1448  
1449      /**
1450       * Translates the default TinyMCE strings and returns them as JSON encoded object ready to be loaded with tinymce.addI18n(),
1451       * or as JS snippet that should run after tinymce.js is loaded.
1452       *
1453       * @since 3.9.0
1454       *
1455       * @param string $mce_locale The locale used for the editor.
1456       * @param bool $json_only optional Whether to include the JavaScript calls to tinymce.addI18n() and tinymce.ScriptLoader.markDone().
1457       * @return string Translation object, JSON encoded.
1458       */
1459  	public static function wp_mce_translation( $mce_locale = '', $json_only = false ) {
1460          if ( ! $mce_locale ) {
1461              $mce_locale = self::get_mce_locale();
1462          }
1463  
1464          $mce_translation = self::get_translation();
1465  
1466          foreach ( $mce_translation as $name => $value ) {
1467              if ( is_array( $value ) ) {
1468                  $mce_translation[ $name ] = $value[0];
1469              }
1470          }
1471  
1472          /**
1473           * Filters translated strings prepared for TinyMCE.
1474           *
1475           * @since 3.9.0
1476           *
1477           * @param array  $mce_translation Key/value pairs of strings.
1478           * @param string $mce_locale      Locale.
1479           */
1480          $mce_translation = apply_filters( 'wp_mce_translation', $mce_translation, $mce_locale );
1481  
1482          foreach ( $mce_translation as $key => $value ) {
1483              // Remove strings that are not translated.
1484              if ( $key === $value ) {
1485                  unset( $mce_translation[ $key ] );
1486                  continue;
1487              }
1488  
1489              if ( false !== strpos( $value, '&' ) ) {
1490                  $mce_translation[ $key ] = html_entity_decode( $value, ENT_QUOTES, 'UTF-8' );
1491              }
1492          }
1493  
1494          // Set direction.
1495          if ( is_rtl() ) {
1496              $mce_translation['_dir'] = 'rtl';
1497          }
1498  
1499          if ( $json_only ) {
1500              return wp_json_encode( $mce_translation );
1501          }
1502  
1503          $baseurl = self::get_baseurl();
1504  
1505          return "tinymce.addI18n( '$mce_locale', " . wp_json_encode( $mce_translation ) . ");\n" .
1506              "tinymce.ScriptLoader.markDone( '$baseurl/langs/$mce_locale.js' );\n";
1507      }
1508  
1509      /**
1510       * Force uncompressed TinyMCE when a custom theme has been defined.
1511       *
1512       * The compressed TinyMCE file cannot deal with custom themes, so this makes
1513       * sure that we use the uncompressed TinyMCE file if a theme is defined.
1514       * Even if we are on a production environment.
1515       *
1516       * @since 5.0.0
1517       */
1518  	public static function force_uncompressed_tinymce() {
1519          $has_custom_theme = false;
1520          foreach ( self::$mce_settings as $init ) {
1521              if ( ! empty( $init['theme_url'] ) ) {
1522                  $has_custom_theme = true;
1523                  break;
1524              }
1525          }
1526  
1527          if ( ! $has_custom_theme ) {
1528              return;
1529          }
1530  
1531          $wp_scripts = wp_scripts();
1532  
1533          $wp_scripts->remove( 'wp-tinymce' );
1534          wp_register_tinymce_scripts( $wp_scripts, true );
1535      }
1536  
1537      /**
1538       * Print (output) the main TinyMCE scripts.
1539       *
1540       * @since 4.8.0
1541       *
1542       * @global string $tinymce_version
1543       * @global bool   $concatenate_scripts
1544       * @global bool   $compress_scripts
1545       */
1546  	public static function print_tinymce_scripts() {
1547          global $concatenate_scripts;
1548  
1549          if ( self::$tinymce_scripts_printed ) {
1550              return;
1551          }
1552  
1553          self::$tinymce_scripts_printed = true;
1554  
1555          if ( ! isset( $concatenate_scripts ) ) {
1556              script_concat_settings();
1557          }
1558  
1559          wp_print_scripts( array( 'wp-tinymce' ) );
1560  
1561          echo "<script type='text/javascript'>\n" . self::wp_mce_translation() . "</script>\n";
1562      }
1563  
1564      /**
1565       * Print (output) the TinyMCE configuration and initialization scripts.
1566       *
1567       * @since 3.3.0
1568       *
1569       * @global string $tinymce_version
1570       */
1571  	public static function editor_js() {
1572          global $tinymce_version;
1573  
1574          $tmce_on = ! empty( self::$mce_settings );
1575          $mceInit = '';
1576          $qtInit  = '';
1577  
1578          if ( $tmce_on ) {
1579              foreach ( self::$mce_settings as $editor_id => $init ) {
1580                  $options  = self::_parse_init( $init );
1581                  $mceInit .= "'$editor_id':{$options},";
1582              }
1583              $mceInit = '{' . trim( $mceInit, ',' ) . '}';
1584          } else {
1585              $mceInit = '{}';
1586          }
1587  
1588          if ( ! empty( self::$qt_settings ) ) {
1589              foreach ( self::$qt_settings as $editor_id => $init ) {
1590                  $options = self::_parse_init( $init );
1591                  $qtInit .= "'$editor_id':{$options},";
1592              }
1593              $qtInit = '{' . trim( $qtInit, ',' ) . '}';
1594          } else {
1595              $qtInit = '{}';
1596          }
1597  
1598          $ref = array(
1599              'plugins'  => implode( ',', self::$plugins ),
1600              'theme'    => 'modern',
1601              'language' => self::$mce_locale,
1602          );
1603  
1604          $suffix  = SCRIPT_DEBUG ? '' : '.min';
1605          $baseurl = self::get_baseurl();
1606          $version = 'ver=' . $tinymce_version;
1607  
1608          /**
1609           * Fires immediately before the TinyMCE settings are printed.
1610           *
1611           * @since 3.2.0
1612           *
1613           * @param array $mce_settings TinyMCE settings array.
1614           */
1615          do_action( 'before_wp_tiny_mce', self::$mce_settings );
1616          ?>
1617  
1618          <script type="text/javascript">
1619          tinyMCEPreInit = {
1620              baseURL: "<?php echo $baseurl; ?>",
1621              suffix: "<?php echo $suffix; ?>",
1622              <?php
1623  
1624              if ( self::$drag_drop_upload ) {
1625                  echo 'dragDropUpload: true,';
1626              }
1627  
1628              ?>
1629              mceInit: <?php echo $mceInit; ?>,
1630              qtInit: <?php echo $qtInit; ?>,
1631              ref: <?php echo self::_parse_init( $ref ); ?>,
1632              load_ext: function(url,lang){var sl=tinymce.ScriptLoader;sl.markDone(url+'/langs/'+lang+'.js');sl.markDone(url+'/langs/'+lang+'_dlg.js');}
1633          };
1634          </script>
1635          <?php
1636  
1637          if ( $tmce_on ) {
1638              self::print_tinymce_scripts();
1639  
1640              if ( self::$ext_plugins ) {
1641                  // Load the old-format English strings to prevent unsightly labels in old style popups.
1642                  echo "<script type='text/javascript' src='{$baseurl}/langs/wp-langs-en.js?$version'></script>\n";
1643              }
1644          }
1645  
1646          /**
1647           * Fires after tinymce.js is loaded, but before any TinyMCE editor
1648           * instances are created.
1649           *
1650           * @since 3.9.0
1651           *
1652           * @param array $mce_settings TinyMCE settings array.
1653           */
1654          do_action( 'wp_tiny_mce_init', self::$mce_settings );
1655  
1656          ?>
1657          <script type="text/javascript">
1658          <?php
1659  
1660          if ( self::$ext_plugins ) {
1661              echo self::$ext_plugins . "\n";
1662          }
1663  
1664          if ( ! is_admin() ) {
1665              echo 'var ajaxurl = "' . admin_url( 'admin-ajax.php', 'relative' ) . '";';
1666          }
1667  
1668          ?>
1669  
1670          ( function() {
1671              var init, id, $wrap;
1672  
1673              if ( typeof tinymce !== 'undefined' ) {
1674                  if ( tinymce.Env.ie && tinymce.Env.ie < 11 ) {
1675                      tinymce.$( '.wp-editor-wrap ' ).removeClass( 'tmce-active' ).addClass( 'html-active' );
1676                      return;
1677                  }
1678  
1679                  for ( id in tinyMCEPreInit.mceInit ) {
1680                      init = tinyMCEPreInit.mceInit[id];
1681                      $wrap = tinymce.$( '#wp-' + id + '-wrap' );
1682  
1683                      if ( ( $wrap.hasClass( 'tmce-active' ) || ! tinyMCEPreInit.qtInit.hasOwnProperty( id ) ) && ! init.wp_skip_init ) {
1684                          tinymce.init( init );
1685  
1686                          if ( ! window.wpActiveEditor ) {
1687                              window.wpActiveEditor = id;
1688                          }
1689                      }
1690                  }
1691              }
1692  
1693              if ( typeof quicktags !== 'undefined' ) {
1694                  for ( id in tinyMCEPreInit.qtInit ) {
1695                      quicktags( tinyMCEPreInit.qtInit[id] );
1696  
1697                      if ( ! window.wpActiveEditor ) {
1698                          window.wpActiveEditor = id;
1699                      }
1700                  }
1701              }
1702          }());
1703          </script>
1704          <?php
1705  
1706          if ( in_array( 'wplink', self::$plugins, true ) || in_array( 'link', self::$qt_buttons, true ) ) {
1707              self::wp_link_dialog();
1708          }
1709  
1710          /**
1711           * Fires after any core TinyMCE editor instances are created.
1712           *
1713           * @since 3.2.0
1714           *
1715           * @param array $mce_settings TinyMCE settings array.
1716           */
1717          do_action( 'after_wp_tiny_mce', self::$mce_settings );
1718      }
1719  
1720      /**
1721       * Outputs the HTML for distraction-free writing mode.
1722       *
1723       * @since 3.2.0
1724       * @deprecated 4.3.0
1725       */
1726  	public static function wp_fullscreen_html() {
1727          _deprecated_function( __FUNCTION__, '4.3.0' );
1728      }
1729  
1730      /**
1731       * Performs post queries for internal linking.
1732       *
1733       * @since 3.1.0
1734       *
1735       * @param array $args Optional. Accepts 'pagenum' and 's' (search) arguments.
1736       * @return array|false Results.
1737       */
1738  	public static function wp_link_query( $args = array() ) {
1739          $pts      = get_post_types( array( 'public' => true ), 'objects' );
1740          $pt_names = array_keys( $pts );
1741  
1742          $query = array(
1743              'post_type'              => $pt_names,
1744              'suppress_filters'       => true,
1745              'update_post_term_cache' => false,
1746              'update_post_meta_cache' => false,
1747              'post_status'            => 'publish',
1748              'posts_per_page'         => 20,
1749          );
1750  
1751          $args['pagenum'] = isset( $args['pagenum'] ) ? absint( $args['pagenum'] ) : 1;
1752  
1753          if ( isset( $args['s'] ) ) {
1754              $query['s'] = $args['s'];
1755          }
1756  
1757          $query['offset'] = $args['pagenum'] > 1 ? $query['posts_per_page'] * ( $args['pagenum'] - 1 ) : 0;
1758  
1759          /**
1760           * Filters the link query arguments.
1761           *
1762           * Allows modification of the link query arguments before querying.
1763           *
1764           * @see WP_Query for a full list of arguments
1765           *
1766           * @since 3.7.0
1767           *
1768           * @param array $query An array of WP_Query arguments.
1769           */
1770          $query = apply_filters( 'wp_link_query_args', $query );
1771  
1772          // Do main query.
1773          $get_posts = new WP_Query;
1774          $posts     = $get_posts->query( $query );
1775  
1776          // Build results.
1777          $results = array();
1778          foreach ( $posts as $post ) {
1779              if ( 'post' == $post->post_type ) {
1780                  $info = mysql2date( __( 'Y/m/d' ), $post->post_date );
1781              } else {
1782                  $info = $pts[ $post->post_type ]->labels->singular_name;
1783              }
1784  
1785              $results[] = array(
1786                  'ID'        => $post->ID,
1787                  'title'     => trim( esc_html( strip_tags( get_the_title( $post ) ) ) ),
1788                  'permalink' => get_permalink( $post->ID ),
1789                  'info'      => $info,
1790              );
1791          }
1792  
1793          /**
1794           * Filters the link query results.
1795           *
1796           * Allows modification of the returned link query results.
1797           *
1798           * @since 3.7.0
1799           *
1800           * @see 'wp_link_query_args' filter
1801           *
1802           * @param array $results {
1803           *     An associative array of query results.
1804           *
1805           *     @type array {
1806           *         @type int    $ID        Post ID.
1807           *         @type string $title     The trimmed, escaped post title.
1808           *         @type string $permalink Post permalink.
1809           *         @type string $info      A 'Y/m/d'-formatted date for 'post' post type,
1810           *                                 the 'singular_name' post type label otherwise.
1811           *     }
1812           * }
1813           * @param array $query  An array of WP_Query arguments.
1814           */
1815          $results = apply_filters( 'wp_link_query', $results, $query );
1816  
1817          return ! empty( $results ) ? $results : false;
1818      }
1819  
1820      /**
1821       * Dialog for internal linking.
1822       *
1823       * @since 3.1.0
1824       */
1825  	public static function wp_link_dialog() {
1826          // Run once.
1827          if ( self::$link_dialog_printed ) {
1828              return;
1829          }
1830  
1831          self::$link_dialog_printed = true;
1832  
1833          // `display: none` is required here, see #WP27605.
1834          ?>
1835          <div id="wp-link-backdrop" style="display: none"></div>
1836          <div id="wp-link-wrap" class="wp-core-ui" style="display: none" role="dialog" aria-labelledby="link-modal-title">
1837          <form id="wp-link" tabindex="-1">
1838          <?php wp_nonce_field( 'internal-linking', '_ajax_linking_nonce', false ); ?>
1839          <h1 id="link-modal-title"><?php _e( 'Insert/edit link' ); ?></h1>
1840          <button type="button" id="wp-link-close"><span class="screen-reader-text"><?php _e( 'Close' ); ?></span></button>
1841          <div id="link-selector">
1842              <div id="link-options">
1843                  <p class="howto" id="wplink-enter-url"><?php _e( 'Enter the destination URL' ); ?></p>
1844                  <div>
1845                      <label><span><?php _e( 'URL' ); ?></span>
1846                      <input id="wp-link-url" type="text" aria-describedby="wplink-enter-url" /></label>
1847                  </div>
1848                  <div class="wp-link-text-field">
1849                      <label><span><?php _e( 'Link Text' ); ?></span>
1850                      <input id="wp-link-text" type="text" /></label>
1851                  </div>
1852                  <div class="link-target">
1853                      <label><span></span>
1854                      <input type="checkbox" id="wp-link-target" /> <?php _e( 'Open link in a new tab' ); ?></label>
1855                  </div>
1856              </div>
1857              <p class="howto" id="wplink-link-existing-content"><?php _e( 'Or link to existing content' ); ?></p>
1858              <div id="search-panel">
1859                  <div class="link-search-wrapper">
1860                      <label>
1861                          <span class="search-label"><?php _e( 'Search' ); ?></span>
1862                          <input type="search" id="wp-link-search" class="link-search-field" autocomplete="off" aria-describedby="wplink-link-existing-content" />
1863                          <span class="spinner"></span>
1864                      </label>
1865                  </div>
1866                  <div id="search-results" class="query-results" tabindex="0">
1867                      <ul></ul>
1868                      <div class="river-waiting">
1869                          <span class="spinner"></span>
1870                      </div>
1871                  </div>
1872                  <div id="most-recent-results" class="query-results" tabindex="0">
1873                      <div class="query-notice" id="query-notice-message">
1874                          <em class="query-notice-default"><?php _e( 'No search term specified. Showing recent items.' ); ?></em>
1875                          <em class="query-notice-hint screen-reader-text"><?php _e( 'Search or use up and down arrow keys to select an item.' ); ?></em>
1876                      </div>
1877                      <ul></ul>
1878                      <div class="river-waiting">
1879                          <span class="spinner"></span>
1880                      </div>
1881                  </div>
1882              </div>
1883          </div>
1884          <div class="submitbox">
1885              <div id="wp-link-cancel">
1886                  <button type="button" class="button"><?php _e( 'Cancel' ); ?></button>
1887              </div>
1888              <div id="wp-link-update">
1889                  <input type="submit" value="<?php esc_attr_e( 'Add Link' ); ?>" class="button button-primary" id="wp-link-submit" name="wp-link-submit">
1890              </div>
1891          </div>
1892          </form>
1893          </div>
1894          <?php
1895      }
1896  }


Generated: Sun Apr 5 01:00:03 2020 Cross-referenced by PHPXref 0.7.1