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


Generated: Tue Sep 17 01:00:03 2019 Cross-referenced by PHPXref 0.7.1