[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Mon Jul 15 08:20:02 2024 Cross-referenced by PHPXref