[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

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

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


Generated: Mon Nov 18 01:00:04 2019 Cross-referenced by PHPXref 0.7.1