[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

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


Generated: Tue Oct 22 08:20:01 2019 Cross-referenced by PHPXref 0.7