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


Generated: Wed Dec 2 01:00:04 2020 Cross-referenced by PHPXref 0.7.1