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


Generated : Sun Oct 18 08:20:35 2026 Cross-referenced by PHPXref