[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/ -> script-loader.php (source)

   1  <?php
   2  /**
   3   * WordPress scripts and styles default loader.
   4   *
   5   * Several constants are used to manage the loading, concatenating and compression of scripts and CSS:
   6   * define('SCRIPT_DEBUG', true); loads the development (non-minified) versions of all scripts and CSS, and disables compression and concatenation,
   7   * define('CONCATENATE_SCRIPTS', false); disables compression and concatenation of scripts and CSS,
   8   * define('COMPRESS_SCRIPTS', false); disables compression of scripts,
   9   * define('COMPRESS_CSS', false); disables compression of CSS,
  10   * define('ENFORCE_GZIP', true); forces gzip for compression (default is deflate).
  11   *
  12   * The globals $concatenate_scripts, $compress_scripts and $compress_css can be set by plugins
  13   * to temporarily override the above settings. Also a compression test is run once and the result is saved
  14   * as option 'can_compress_scripts' (0/1). The test will run again if that option is deleted.
  15   *
  16   * @package WordPress
  17   */
  18  
  19  /** WordPress Dependency Class */
  20  require  ABSPATH . WPINC . '/class-wp-dependency.php';
  21  
  22  /** WordPress Dependencies Class */
  23  require  ABSPATH . WPINC . '/class.wp-dependencies.php';
  24  
  25  /** WordPress Scripts Class */
  26  require  ABSPATH . WPINC . '/class.wp-scripts.php';
  27  
  28  /** WordPress Scripts Functions */
  29  require  ABSPATH . WPINC . '/functions.wp-scripts.php';
  30  
  31  /** WordPress Styles Class */
  32  require  ABSPATH . WPINC . '/class.wp-styles.php';
  33  
  34  /** WordPress Styles Functions */
  35  require  ABSPATH . WPINC . '/functions.wp-styles.php';
  36  
  37  /**
  38   * Registers TinyMCE scripts.
  39   *
  40   * @since 5.0.0
  41   *
  42   * @param WP_Scripts $scripts            WP_Scripts object.
  43   * @param bool       $force_uncompressed Whether to forcibly prevent gzip compression. Default false.
  44   */
  45  function wp_register_tinymce_scripts( $scripts, $force_uncompressed = false ) {
  46      global $tinymce_version, $concatenate_scripts, $compress_scripts;
  47      $suffix     = wp_scripts_get_suffix();
  48      $dev_suffix = wp_scripts_get_suffix( 'dev' );
  49  
  50      script_concat_settings();
  51  
  52      $compressed = $compress_scripts && $concatenate_scripts && isset( $_SERVER['HTTP_ACCEPT_ENCODING'] )
  53          && false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && ! $force_uncompressed;
  54  
  55      // Load tinymce.js when running from /src, otherwise load wp-tinymce.js.gz (in production)
  56      // or tinymce.min.js (when SCRIPT_DEBUG is true).
  57      if ( $compressed ) {
  58          $scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . 'wp-tinymce.js', array(), $tinymce_version );
  59      } else {
  60          $scripts->add( 'wp-tinymce-root', includes_url( 'js/tinymce/' ) . "tinymce$dev_suffix.js", array(), $tinymce_version );
  61          $scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . "plugins/compat3x/plugin$dev_suffix.js", array( 'wp-tinymce-root' ), $tinymce_version );
  62      }
  63  
  64      $scripts->add( 'wp-tinymce-lists', includes_url( "js/tinymce/plugins/lists/plugin$suffix.js" ), array( 'wp-tinymce' ), $tinymce_version );
  65  }
  66  
  67  /**
  68   * Registers all the WordPress vendor scripts that are in the standardized
  69   * `js/dist/vendor/` location.
  70   *
  71   * For the order of `$scripts->add` see `wp_default_scripts`.
  72   *
  73   * @since 5.0.0
  74   *
  75   * @param WP_Scripts $scripts WP_Scripts object.
  76   */
  77  function wp_default_packages_vendor( $scripts ) {
  78      global $wp_locale;
  79  
  80      $suffix = wp_scripts_get_suffix();
  81  
  82      $vendor_scripts = array(
  83          'react'     => array( 'wp-polyfill' ),
  84          'react-dom' => array( 'react' ),
  85          'moment',
  86          'lodash',
  87          'wp-polyfill-fetch',
  88          'wp-polyfill-formdata',
  89          'wp-polyfill-node-contains',
  90          'wp-polyfill-url',
  91          'wp-polyfill-dom-rect',
  92          'wp-polyfill-element-closest',
  93          'wp-polyfill-object-fit',
  94          'wp-polyfill',
  95      );
  96  
  97      $vendor_scripts_versions = array(
  98          'react'                       => '16.13.1',
  99          'react-dom'                   => '16.13.1',
 100          'moment'                      => '2.29.1',
 101          'lodash'                      => '4.17.19',
 102          'wp-polyfill-fetch'           => '3.0.0',
 103          'wp-polyfill-formdata'        => '4.0.0',
 104          'wp-polyfill-node-contains'   => '3.105.0',
 105          'wp-polyfill-url'             => '3.6.4',
 106          'wp-polyfill-dom-rect'        => '3.104.0',
 107          'wp-polyfill-element-closest' => '2.0.2',
 108          'wp-polyfill-object-fit'      => '2.3.5',
 109          'wp-polyfill'                 => '7.4.4',
 110      );
 111  
 112      foreach ( $vendor_scripts as $handle => $dependencies ) {
 113          if ( is_string( $dependencies ) ) {
 114              $handle       = $dependencies;
 115              $dependencies = array();
 116          }
 117  
 118          $path    = "/wp-includes/js/dist/vendor/$handle$suffix.js";
 119          $version = $vendor_scripts_versions[ $handle ];
 120  
 121          $scripts->add( $handle, $path, $dependencies, $version, 1 );
 122      }
 123  
 124      $scripts->add( 'wp-polyfill', null, array( 'wp-polyfill' ) );
 125  
 126      did_action( 'init' ) && $scripts->add_inline_script( 'lodash', 'window.lodash = _.noConflict();' );
 127  
 128      did_action( 'init' ) && $scripts->add_inline_script(
 129          'moment',
 130          sprintf(
 131              "moment.updateLocale( '%s', %s );",
 132              get_user_locale(),
 133              wp_json_encode(
 134                  array(
 135                      'months'         => array_values( $wp_locale->month ),
 136                      'monthsShort'    => array_values( $wp_locale->month_abbrev ),
 137                      'weekdays'       => array_values( $wp_locale->weekday ),
 138                      'weekdaysShort'  => array_values( $wp_locale->weekday_abbrev ),
 139                      'week'           => array(
 140                          'dow' => (int) get_option( 'start_of_week', 0 ),
 141                      ),
 142                      'longDateFormat' => array(
 143                          'LT'   => get_option( 'time_format', __( 'g:i a', 'default' ) ),
 144                          'LTS'  => null,
 145                          'L'    => null,
 146                          'LL'   => get_option( 'date_format', __( 'F j, Y', 'default' ) ),
 147                          'LLL'  => __( 'F j, Y g:i a', 'default' ),
 148                          'LLLL' => null,
 149                      ),
 150                  )
 151              )
 152          ),
 153          'after'
 154      );
 155  }
 156  
 157  /**
 158   * Returns contents of an inline script used in appending polyfill scripts for
 159   * browsers which fail the provided tests. The provided array is a mapping from
 160   * a condition to verify feature support to its polyfill script handle.
 161   *
 162   * @since 5.0.0
 163   *
 164   * @param WP_Scripts $scripts WP_Scripts object.
 165   * @param array      $tests   Features to detect.
 166   * @return string Conditional polyfill inline script.
 167   */
 168  function wp_get_script_polyfill( $scripts, $tests ) {
 169      $polyfill = '';
 170      foreach ( $tests as $test => $handle ) {
 171          if ( ! array_key_exists( $handle, $scripts->registered ) ) {
 172              continue;
 173          }
 174  
 175          $src = $scripts->registered[ $handle ]->src;
 176          $ver = $scripts->registered[ $handle ]->ver;
 177  
 178          if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $scripts->content_url && 0 === strpos( $src, $scripts->content_url ) ) ) {
 179              $src = $scripts->base_url . $src;
 180          }
 181  
 182          if ( ! empty( $ver ) ) {
 183              $src = add_query_arg( 'ver', $ver, $src );
 184          }
 185  
 186          /** This filter is documented in wp-includes/class.wp-scripts.php */
 187          $src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
 188  
 189          if ( ! $src ) {
 190              continue;
 191          }
 192  
 193          $polyfill .= (
 194              // Test presence of feature...
 195              '( ' . $test . ' ) || ' .
 196              /*
 197               * ...appending polyfill on any failures. Cautious viewers may balk
 198               * at the `document.write`. Its caveat of synchronous mid-stream
 199               * blocking write is exactly the behavior we need though.
 200               */
 201              'document.write( \'<script src="' .
 202              $src .
 203              '"></scr\' + \'ipt>\' );'
 204          );
 205      }
 206  
 207      return $polyfill;
 208  }
 209  
 210  /**
 211   * Registers all the WordPress packages scripts that are in the standardized
 212   * `js/dist/` location.
 213   *
 214   * For the order of `$scripts->add` see `wp_default_scripts`.
 215   *
 216   * @since 5.0.0
 217   *
 218   * @param WP_Scripts $scripts WP_Scripts object.
 219   */
 220  function wp_default_packages_scripts( $scripts ) {
 221      $suffix = wp_scripts_get_suffix();
 222  
 223      // Expects multidimensional array like:
 224      //    'a11y.js' => array('dependencies' => array(...), 'version' => '...'),
 225      //    'annotations.js' => array('dependencies' => array(...), 'version' => '...'),
 226      //    'api-fetch.js' => array(...
 227      $assets = include  ABSPATH . WPINC . '/assets/script-loader-packages.php';
 228  
 229      foreach ( $assets as $package_name => $package_data ) {
 230          $basename = basename( $package_name, '.js' );
 231          $handle   = 'wp-' . $basename;
 232          $path     = "/wp-includes/js/dist/{$basename}{$suffix}.js";
 233  
 234          if ( ! empty( $package_data['dependencies'] ) ) {
 235              $dependencies = $package_data['dependencies'];
 236          } else {
 237              $dependencies = array();
 238          }
 239  
 240          // Add dependencies that cannot be detected and generated by build tools.
 241          switch ( $handle ) {
 242              case 'wp-block-library':
 243                  array_push( $dependencies, 'editor' );
 244                  break;
 245              case 'wp-edit-post':
 246                  array_push( $dependencies, 'media-models', 'media-views', 'postbox', 'wp-dom-ready' );
 247                  break;
 248          }
 249  
 250          $scripts->add( $handle, $path, $dependencies, $package_data['version'], 1 );
 251  
 252          if ( in_array( 'wp-i18n', $dependencies, true ) ) {
 253              $scripts->set_translations( $handle );
 254          }
 255  
 256          /*
 257           * Manually set the text direction localization after wp-i18n is printed.
 258           * This ensures that wp.i18n.isRTL() returns true in RTL languages.
 259           * We cannot use $scripts->set_translations( 'wp-i18n' ) to do this
 260           * because WordPress prints a script's translations *before* the script,
 261           * which means, in the case of wp-i18n, that wp.i18n.setLocaleData()
 262           * is called before wp.i18n is defined.
 263           */
 264          if ( 'wp-i18n' === $handle ) {
 265              $ltr    = _x( 'ltr', 'text direction', 'default' );
 266              $script = sprintf( "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ '%s' ] } );", $ltr );
 267              $scripts->add_inline_script( $handle, $script, 'after' );
 268          }
 269      }
 270  }
 271  
 272  /**
 273   * Adds inline scripts required for the WordPress JavaScript packages.
 274   *
 275   * @since 5.0.0
 276   *
 277   * @param WP_Scripts $scripts WP_Scripts object.
 278   */
 279  function wp_default_packages_inline_scripts( $scripts ) {
 280      global $wp_locale;
 281  
 282      if ( isset( $scripts->registered['wp-api-fetch'] ) ) {
 283          $scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
 284      }
 285      $scripts->add_inline_script(
 286          'wp-api-fetch',
 287          sprintf(
 288              'wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );',
 289              esc_url_raw( get_rest_url() )
 290          ),
 291          'after'
 292      );
 293      $scripts->add_inline_script(
 294          'wp-api-fetch',
 295          implode(
 296              "\n",
 297              array(
 298                  sprintf(
 299                      'wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );',
 300                      ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' )
 301                  ),
 302                  'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );',
 303                  'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );',
 304                  sprintf(
 305                      'wp.apiFetch.nonceEndpoint = "%s";',
 306                      admin_url( 'admin-ajax.php?action=rest-nonce' )
 307                  ),
 308              )
 309          ),
 310          'after'
 311      );
 312      $scripts->add_inline_script(
 313          'wp-data',
 314          implode(
 315              "\n",
 316              array(
 317                  '( function() {',
 318                  '    var userId = ' . get_current_user_ID() . ';',
 319                  '    var storageKey = "WP_DATA_USER_" + userId;',
 320                  '    wp.data',
 321                  '        .use( wp.data.plugins.persistence, { storageKey: storageKey } );',
 322                  '    wp.data.plugins.persistence.__unstableMigrate( { storageKey: storageKey } );',
 323                  '} )();',
 324              )
 325          )
 326      );
 327  
 328      // Calculate the timezone abbr (EDT, PST) if possible.
 329      $timezone_string = get_option( 'timezone_string', 'UTC' );
 330      $timezone_abbr   = '';
 331  
 332      if ( ! empty( $timezone_string ) ) {
 333          $timezone_date = new DateTime( null, new DateTimeZone( $timezone_string ) );
 334          $timezone_abbr = $timezone_date->format( 'T' );
 335      }
 336  
 337      $scripts->add_inline_script(
 338          'wp-date',
 339          sprintf(
 340              'wp.date.setSettings( %s );',
 341              wp_json_encode(
 342                  array(
 343                      'l10n'     => array(
 344                          'locale'        => get_user_locale(),
 345                          'months'        => array_values( $wp_locale->month ),
 346                          'monthsShort'   => array_values( $wp_locale->month_abbrev ),
 347                          'weekdays'      => array_values( $wp_locale->weekday ),
 348                          'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ),
 349                          'meridiem'      => (object) $wp_locale->meridiem,
 350                          'relative'      => array(
 351                              /* translators: %s: Duration. */
 352                              'future' => __( '%s from now' ),
 353                              /* translators: %s: Duration. */
 354                              'past'   => __( '%s ago' ),
 355                          ),
 356                      ),
 357                      'formats'  => array(
 358                          /* translators: Time format, see https://www.php.net/manual/datetime.format.php */
 359                          'time'                => get_option( 'time_format', __( 'g:i a' ) ),
 360                          /* translators: Date format, see https://www.php.net/manual/datetime.format.php */
 361                          'date'                => get_option( 'date_format', __( 'F j, Y' ) ),
 362                          /* translators: Date/Time format, see https://www.php.net/manual/datetime.format.php */
 363                          'datetime'            => __( 'F j, Y g:i a' ),
 364                          /* translators: Abbreviated date/time format, see https://www.php.net/manual/datetime.format.php */
 365                          'datetimeAbbreviated' => __( 'M j, Y g:i a' ),
 366                      ),
 367                      'timezone' => array(
 368                          'offset' => get_option( 'gmt_offset', 0 ),
 369                          'string' => $timezone_string,
 370                          'abbr'   => $timezone_abbr,
 371                      ),
 372                  )
 373              )
 374          ),
 375          'after'
 376      );
 377  
 378      // Loading the old editor and its config to ensure the classic block works as expected.
 379      $scripts->add_inline_script(
 380          'editor',
 381          'window.wp.oldEditor = window.wp.editor;',
 382          'after'
 383      );
 384  }
 385  
 386  /**
 387   * Adds inline scripts required for the TinyMCE in the block editor.
 388   *
 389   * These TinyMCE init settings are used to extend and override the default settings
 390   * from `_WP_Editors::default_settings()` for the Classic block.
 391   *
 392   * @since 5.0.0
 393   *
 394   * @global WP_Scripts $wp_scripts
 395   */
 396  function wp_tinymce_inline_scripts() {
 397      global $wp_scripts;
 398  
 399      /** This filter is documented in wp-includes/class-wp-editor.php */
 400      $editor_settings = apply_filters( 'wp_editor_settings', array( 'tinymce' => true ), 'classic-block' );
 401  
 402      $tinymce_plugins = array(
 403          'charmap',
 404          'colorpicker',
 405          'hr',
 406          'lists',
 407          'media',
 408          'paste',
 409          'tabfocus',
 410          'textcolor',
 411          'fullscreen',
 412          'wordpress',
 413          'wpautoresize',
 414          'wpeditimage',
 415          'wpemoji',
 416          'wpgallery',
 417          'wplink',
 418          'wpdialogs',
 419          'wptextpattern',
 420          'wpview',
 421      );
 422  
 423      /** This filter is documented in wp-includes/class-wp-editor.php */
 424      $tinymce_plugins = apply_filters( 'tiny_mce_plugins', $tinymce_plugins, 'classic-block' );
 425      $tinymce_plugins = array_unique( $tinymce_plugins );
 426  
 427      $disable_captions = false;
 428      // Runs after `tiny_mce_plugins` but before `mce_buttons`.
 429      /** This filter is documented in wp-admin/includes/media.php */
 430      if ( apply_filters( 'disable_captions', '' ) ) {
 431          $disable_captions = true;
 432      }
 433  
 434      $toolbar1 = array(
 435          'formatselect',
 436          'bold',
 437          'italic',
 438          'bullist',
 439          'numlist',
 440          'blockquote',
 441          'alignleft',
 442          'aligncenter',
 443          'alignright',
 444          'link',
 445          'unlink',
 446          'wp_more',
 447          'spellchecker',
 448          'wp_add_media',
 449          'wp_adv',
 450      );
 451  
 452      /** This filter is documented in wp-includes/class-wp-editor.php */
 453      $toolbar1 = apply_filters( 'mce_buttons', $toolbar1, 'classic-block' );
 454  
 455      $toolbar2 = array(
 456          'strikethrough',
 457          'hr',
 458          'forecolor',
 459          'pastetext',
 460          'removeformat',
 461          'charmap',
 462          'outdent',
 463          'indent',
 464          'undo',
 465          'redo',
 466          'wp_help',
 467      );
 468  
 469      /** This filter is documented in wp-includes/class-wp-editor.php */
 470      $toolbar2 = apply_filters( 'mce_buttons_2', $toolbar2, 'classic-block' );
 471      /** This filter is documented in wp-includes/class-wp-editor.php */
 472      $toolbar3 = apply_filters( 'mce_buttons_3', array(), 'classic-block' );
 473      /** This filter is documented in wp-includes/class-wp-editor.php */
 474      $toolbar4 = apply_filters( 'mce_buttons_4', array(), 'classic-block' );
 475      /** This filter is documented in wp-includes/class-wp-editor.php */
 476      $external_plugins = apply_filters( 'mce_external_plugins', array(), 'classic-block' );
 477  
 478      $tinymce_settings = array(
 479          'plugins'              => implode( ',', $tinymce_plugins ),
 480          'toolbar1'             => implode( ',', $toolbar1 ),
 481          'toolbar2'             => implode( ',', $toolbar2 ),
 482          'toolbar3'             => implode( ',', $toolbar3 ),
 483          'toolbar4'             => implode( ',', $toolbar4 ),
 484          'external_plugins'     => wp_json_encode( $external_plugins ),
 485          'classic_block_editor' => true,
 486      );
 487  
 488      if ( $disable_captions ) {
 489          $tinymce_settings['wpeditimage_disable_captions'] = true;
 490      }
 491  
 492      if ( ! empty( $editor_settings['tinymce'] ) && is_array( $editor_settings['tinymce'] ) ) {
 493          array_merge( $tinymce_settings, $editor_settings['tinymce'] );
 494      }
 495  
 496      /** This filter is documented in wp-includes/class-wp-editor.php */
 497      $tinymce_settings = apply_filters( 'tiny_mce_before_init', $tinymce_settings, 'classic-block' );
 498  
 499      // Do "by hand" translation from PHP array to js object.
 500      // Prevents breakage in some custom settings.
 501      $init_obj = '';
 502      foreach ( $tinymce_settings as $key => $value ) {
 503          if ( is_bool( $value ) ) {
 504              $val       = $value ? 'true' : 'false';
 505              $init_obj .= $key . ':' . $val . ',';
 506              continue;
 507          } elseif ( ! empty( $value ) && is_string( $value ) && (
 508              ( '{' === $value[0] && '}' === $value[ strlen( $value ) - 1 ] ) ||
 509              ( '[' === $value[0] && ']' === $value[ strlen( $value ) - 1 ] ) ||
 510              preg_match( '/^\(?function ?\(/', $value ) ) ) {
 511              $init_obj .= $key . ':' . $value . ',';
 512              continue;
 513          }
 514          $init_obj .= $key . ':"' . $value . '",';
 515      }
 516  
 517      $init_obj = '{' . trim( $init_obj, ' ,' ) . '}';
 518  
 519      $script = 'window.wpEditorL10n = {
 520          tinymce: {
 521              baseURL: ' . wp_json_encode( includes_url( 'js/tinymce' ) ) . ',
 522              suffix: ' . ( SCRIPT_DEBUG ? '""' : '".min"' ) . ',
 523              settings: ' . $init_obj . ',
 524          }
 525      }';
 526  
 527      $wp_scripts->add_inline_script( 'wp-block-library', $script, 'before' );
 528  }
 529  
 530  /**
 531   * Registers all the WordPress packages scripts.
 532   *
 533   * @since 5.0.0
 534   *
 535   * @param WP_Scripts $scripts WP_Scripts object.
 536   */
 537  function wp_default_packages( $scripts ) {
 538      wp_default_packages_vendor( $scripts );
 539      wp_register_tinymce_scripts( $scripts );
 540      wp_default_packages_scripts( $scripts );
 541  
 542      if ( did_action( 'init' ) ) {
 543          wp_default_packages_inline_scripts( $scripts );
 544      }
 545  }
 546  
 547  /**
 548   * Returns the suffix that can be used for the scripts.
 549   *
 550   * There are two suffix types, the normal one and the dev suffix.
 551   *
 552   * @since 5.0.0
 553   *
 554   * @param string $type The type of suffix to retrieve.
 555   * @return string The script suffix.
 556   */
 557  function wp_scripts_get_suffix( $type = '' ) {
 558      static $suffixes;
 559  
 560      if ( null === $suffixes ) {
 561          // Include an unmodified $wp_version.
 562          require  ABSPATH . WPINC . '/version.php';
 563  
 564          $develop_src = false !== strpos( $wp_version, '-src' );
 565  
 566          if ( ! defined( 'SCRIPT_DEBUG' ) ) {
 567              define( 'SCRIPT_DEBUG', $develop_src );
 568          }
 569          $suffix     = SCRIPT_DEBUG ? '' : '.min';
 570          $dev_suffix = $develop_src ? '' : '.min';
 571  
 572          $suffixes = array(
 573              'suffix'     => $suffix,
 574              'dev_suffix' => $dev_suffix,
 575          );
 576      }
 577  
 578      if ( 'dev' === $type ) {
 579          return $suffixes['dev_suffix'];
 580      }
 581  
 582      return $suffixes['suffix'];
 583  }
 584  
 585  /**
 586   * Register all WordPress scripts.
 587   *
 588   * Localizes some of them.
 589   * args order: `$scripts->add( 'handle', 'url', 'dependencies', 'query-string', 1 );`
 590   * when last arg === 1 queues the script for the footer
 591   *
 592   * @since 2.6.0
 593   *
 594   * @param WP_Scripts $scripts WP_Scripts object.
 595   */
 596  function wp_default_scripts( $scripts ) {
 597      $suffix     = wp_scripts_get_suffix();
 598      $dev_suffix = wp_scripts_get_suffix( 'dev' );
 599      $guessurl   = site_url();
 600  
 601      if ( ! $guessurl ) {
 602          $guessed_url = true;
 603          $guessurl    = wp_guess_url();
 604      }
 605  
 606      $scripts->base_url        = $guessurl;
 607      $scripts->content_url     = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : '';
 608      $scripts->default_version = get_bloginfo( 'version' );
 609      $scripts->default_dirs    = array( '/wp-admin/js/', '/wp-includes/js/' );
 610  
 611      $scripts->add( 'utils', "/wp-includes/js/utils$suffix.js" );
 612      did_action( 'init' ) && $scripts->localize(
 613          'utils',
 614          'userSettings',
 615          array(
 616              'url'    => (string) SITECOOKIEPATH,
 617              'uid'    => (string) get_current_user_id(),
 618              'time'   => (string) time(),
 619              'secure' => (string) ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) ),
 620          )
 621      );
 622  
 623      $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array( 'jquery', 'hoverIntent', 'utils' ), false, 1 );
 624      $scripts->set_translations( 'common' );
 625  
 626      $scripts->add( 'wp-sanitize', "/wp-includes/js/wp-sanitize$suffix.js", array(), false, 1 );
 627  
 628      $scripts->add( 'sack', "/wp-includes/js/tw-sack$suffix.js", array(), '1.6.1', 1 );
 629  
 630      $scripts->add( 'quicktags', "/wp-includes/js/quicktags$suffix.js", array(), false, 1 );
 631      did_action( 'init' ) && $scripts->localize(
 632          'quicktags',
 633          'quicktagsL10n',
 634          array(
 635              'closeAllOpenTags'      => __( 'Close all open tags' ),
 636              'closeTags'             => __( 'close tags' ),
 637              'enterURL'              => __( 'Enter the URL' ),
 638              'enterImageURL'         => __( 'Enter the URL of the image' ),
 639              'enterImageDescription' => __( 'Enter a description of the image' ),
 640              'textdirection'         => __( 'text direction' ),
 641              'toggleTextdirection'   => __( 'Toggle Editor Text Direction' ),
 642              'dfw'                   => __( 'Distraction-free writing mode' ),
 643              'strong'                => __( 'Bold' ),
 644              'strongClose'           => __( 'Close bold tag' ),
 645              'em'                    => __( 'Italic' ),
 646              'emClose'               => __( 'Close italic tag' ),
 647              'link'                  => __( 'Insert link' ),
 648              'blockquote'            => __( 'Blockquote' ),
 649              'blockquoteClose'       => __( 'Close blockquote tag' ),
 650              'del'                   => __( 'Deleted text (strikethrough)' ),
 651              'delClose'              => __( 'Close deleted text tag' ),
 652              'ins'                   => __( 'Inserted text' ),
 653              'insClose'              => __( 'Close inserted text tag' ),
 654              'image'                 => __( 'Insert image' ),
 655              'ul'                    => __( 'Bulleted list' ),
 656              'ulClose'               => __( 'Close bulleted list tag' ),
 657              'ol'                    => __( 'Numbered list' ),
 658              'olClose'               => __( 'Close numbered list tag' ),
 659              'li'                    => __( 'List item' ),
 660              'liClose'               => __( 'Close list item tag' ),
 661              'code'                  => __( 'Code' ),
 662              'codeClose'             => __( 'Close code tag' ),
 663              'more'                  => __( 'Insert Read More tag' ),
 664          )
 665      );
 666  
 667      $scripts->add( 'colorpicker', "/wp-includes/js/colorpicker$suffix.js", array( 'prototype' ), '3517m' );
 668  
 669      $scripts->add( 'editor', "/wp-admin/js/editor$suffix.js", array( 'utils', 'jquery' ), false, 1 );
 670  
 671      $scripts->add( 'clipboard', "/wp-includes/js/clipboard$suffix.js", array(), false, 1 );
 672  
 673      $scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array( 'jquery' ), false, 1 );
 674      did_action( 'init' ) && $scripts->localize(
 675          'wp-ajax-response',
 676          'wpAjax',
 677          array(
 678              'noPerm' => __( 'Sorry, you are not allowed to do that.' ),
 679              'broken' => __( 'Something went wrong.' ),
 680          )
 681      );
 682  
 683      $scripts->add( 'wp-api-request', "/wp-includes/js/api-request$suffix.js", array( 'jquery' ), false, 1 );
 684      // `wpApiSettings` is also used by `wp-api`, which depends on this script.
 685      did_action( 'init' ) && $scripts->localize(
 686          'wp-api-request',
 687          'wpApiSettings',
 688          array(
 689              'root'          => esc_url_raw( get_rest_url() ),
 690              'nonce'         => ( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' ),
 691              'versionString' => 'wp/v2/',
 692          )
 693      );
 694  
 695      $scripts->add( 'wp-pointer', "/wp-includes/js/wp-pointer$suffix.js", array( 'jquery-ui-core' ), false, 1 );
 696      $scripts->set_translations( 'wp-pointer' );
 697  
 698      $scripts->add( 'autosave', "/wp-includes/js/autosave$suffix.js", array( 'heartbeat' ), false, 1 );
 699  
 700      $scripts->add( 'heartbeat', "/wp-includes/js/heartbeat$suffix.js", array( 'jquery', 'wp-hooks' ), false, 1 );
 701      did_action( 'init' ) && $scripts->localize(
 702          'heartbeat',
 703          'heartbeatSettings',
 704          /**
 705           * Filters the Heartbeat settings.
 706           *
 707           * @since 3.6.0
 708           *
 709           * @param array $settings Heartbeat settings array.
 710           */
 711          apply_filters( 'heartbeat_settings', array() )
 712      );
 713  
 714      $scripts->add( 'wp-auth-check', "/wp-includes/js/wp-auth-check$suffix.js", array( 'heartbeat' ), false, 1 );
 715      $scripts->set_translations( 'wp-auth-check' );
 716  
 717      $scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array( 'wp-ajax-response', 'jquery-color' ), false, 1 );
 718  
 719      // WordPress no longer uses or bundles Prototype or script.aculo.us. These are now pulled from an external source.
 720      $scripts->add( 'prototype', 'https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1' );
 721      $scripts->add( 'scriptaculous-root', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js', array( 'prototype' ), '1.9.0' );
 722      $scripts->add( 'scriptaculous-builder', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/builder.js', array( 'scriptaculous-root' ), '1.9.0' );
 723      $scripts->add( 'scriptaculous-dragdrop', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/dragdrop.js', array( 'scriptaculous-builder', 'scriptaculous-effects' ), '1.9.0' );
 724      $scripts->add( 'scriptaculous-effects', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/effects.js', array( 'scriptaculous-root' ), '1.9.0' );
 725      $scripts->add( 'scriptaculous-slider', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/slider.js', array( 'scriptaculous-effects' ), '1.9.0' );
 726      $scripts->add( 'scriptaculous-sound', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/sound.js', array( 'scriptaculous-root' ), '1.9.0' );
 727      $scripts->add( 'scriptaculous-controls', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/controls.js', array( 'scriptaculous-root' ), '1.9.0' );
 728      $scripts->add( 'scriptaculous', false, array( 'scriptaculous-dragdrop', 'scriptaculous-slider', 'scriptaculous-controls' ) );
 729  
 730      // Not used in core, replaced by Jcrop.js.
 731      $scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array( 'scriptaculous-dragdrop' ) );
 732  
 733      // jQuery.
 734      // The unminified jquery.js and jquery-migrate.js are included to facilitate debugging.
 735      $scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '3.5.1' );
 736      $scripts->add( 'jquery-core', "/wp-includes/js/jquery/jquery$suffix.js", array(), '3.5.1' );
 737      $scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '3.3.2' );
 738  
 739      // Full jQuery UI.
 740      // The build process in 1.12.1 has changed significantly.
 741      // In order to keep backwards compatibility, and to keep the optimized loading,
 742      // the source files were flattened and included with some modifications for AMD loading.
 743      // A notable change is that 'jquery-ui-core' now contains 'jquery-ui-position' and 'jquery-ui-widget'.
 744      $scripts->add( 'jquery-ui-core', "/wp-includes/js/jquery/ui/core$suffix.js", array( 'jquery' ), '1.12.1', 1 );
 745      $scripts->add( 'jquery-effects-core', "/wp-includes/js/jquery/ui/effect$suffix.js", array( 'jquery' ), '1.12.1', 1 );
 746  
 747      $scripts->add( 'jquery-effects-blind', "/wp-includes/js/jquery/ui/effect-blind$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 748      $scripts->add( 'jquery-effects-bounce', "/wp-includes/js/jquery/ui/effect-bounce$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 749      $scripts->add( 'jquery-effects-clip', "/wp-includes/js/jquery/ui/effect-clip$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 750      $scripts->add( 'jquery-effects-drop', "/wp-includes/js/jquery/ui/effect-drop$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 751      $scripts->add( 'jquery-effects-explode', "/wp-includes/js/jquery/ui/effect-explode$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 752      $scripts->add( 'jquery-effects-fade', "/wp-includes/js/jquery/ui/effect-fade$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 753      $scripts->add( 'jquery-effects-fold', "/wp-includes/js/jquery/ui/effect-fold$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 754      $scripts->add( 'jquery-effects-highlight', "/wp-includes/js/jquery/ui/effect-highlight$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 755      $scripts->add( 'jquery-effects-puff', "/wp-includes/js/jquery/ui/effect-puff$suffix.js", array( 'jquery-effects-core', 'jquery-effects-scale' ), '1.12.1', 1 );
 756      $scripts->add( 'jquery-effects-pulsate', "/wp-includes/js/jquery/ui/effect-pulsate$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 757      $scripts->add( 'jquery-effects-scale', "/wp-includes/js/jquery/ui/effect-scale$suffix.js", array( 'jquery-effects-core', 'jquery-effects-size' ), '1.12.1', 1 );
 758      $scripts->add( 'jquery-effects-shake', "/wp-includes/js/jquery/ui/effect-shake$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 759      $scripts->add( 'jquery-effects-size', "/wp-includes/js/jquery/ui/effect-size$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 760      $scripts->add( 'jquery-effects-slide', "/wp-includes/js/jquery/ui/effect-slide$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 761      $scripts->add( 'jquery-effects-transfer', "/wp-includes/js/jquery/ui/effect-transfer$suffix.js", array( 'jquery-effects-core' ), '1.12.1', 1 );
 762  
 763      // Widgets
 764      $scripts->add( 'jquery-ui-accordion', "/wp-includes/js/jquery/ui/accordion$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
 765      $scripts->add( 'jquery-ui-autocomplete', "/wp-includes/js/jquery/ui/autocomplete$suffix.js", array( 'jquery-ui-menu', 'wp-a11y' ), '1.12.1', 1 );
 766      $scripts->add( 'jquery-ui-button', "/wp-includes/js/jquery/ui/button$suffix.js", array( 'jquery-ui-core', 'jquery-ui-controlgroup', 'jquery-ui-checkboxradio' ), '1.12.1', 1 );
 767      $scripts->add( 'jquery-ui-datepicker', "/wp-includes/js/jquery/ui/datepicker$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
 768      $scripts->add( 'jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog$suffix.js", array( 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button' ), '1.12.1', 1 );
 769      $scripts->add( 'jquery-ui-menu', "/wp-includes/js/jquery/ui/menu$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
 770      $scripts->add( 'jquery-ui-mouse', "/wp-includes/js/jquery/ui/mouse$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
 771      $scripts->add( 'jquery-ui-progressbar', "/wp-includes/js/jquery/ui/progressbar$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
 772      $scripts->add( 'jquery-ui-selectmenu', "/wp-includes/js/jquery/ui/selectmenu$suffix.js", array( 'jquery-ui-menu' ), '1.12.1', 1 );
 773      $scripts->add( 'jquery-ui-slider', "/wp-includes/js/jquery/ui/slider$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 );
 774      $scripts->add( 'jquery-ui-spinner', "/wp-includes/js/jquery/ui/spinner$suffix.js", array( 'jquery-ui-button' ), '1.12.1', 1 );
 775      $scripts->add( 'jquery-ui-tabs', "/wp-includes/js/jquery/ui/tabs$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
 776      $scripts->add( 'jquery-ui-tooltip', "/wp-includes/js/jquery/ui/tooltip$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
 777  
 778      // New in 1.12.1
 779      $scripts->add( 'jquery-ui-checkboxradio', "/wp-includes/js/jquery/ui/checkboxradio$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
 780      $scripts->add( 'jquery-ui-controlgroup', "/wp-includes/js/jquery/ui/controlgroup$suffix.js", array( 'jquery-ui-core' ), '1.12.1', 1 );
 781  
 782      // Interactions
 783      $scripts->add( 'jquery-ui-draggable', "/wp-includes/js/jquery/ui/draggable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 );
 784      $scripts->add( 'jquery-ui-droppable', "/wp-includes/js/jquery/ui/droppable$suffix.js", array( 'jquery-ui-draggable' ), '1.12.1', 1 );
 785      $scripts->add( 'jquery-ui-resizable', "/wp-includes/js/jquery/ui/resizable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 );
 786      $scripts->add( 'jquery-ui-selectable', "/wp-includes/js/jquery/ui/selectable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 );
 787      $scripts->add( 'jquery-ui-sortable', "/wp-includes/js/jquery/ui/sortable$suffix.js", array( 'jquery-ui-mouse' ), '1.12.1', 1 );
 788  
 789      // As of 1.12.1 `jquery-ui-position` and `jquery-ui-widget` are part of `jquery-ui-core`.
 790      // Listed here for back-compat.
 791      $scripts->add( 'jquery-ui-position', false, array( 'jquery-ui-core' ), '1.12.1', 1 );
 792      $scripts->add( 'jquery-ui-widget', false, array( 'jquery-ui-core' ), '1.12.1', 1 );
 793  
 794      // Strings for 'jquery-ui-autocomplete' live region messages.
 795      did_action( 'init' ) && $scripts->localize(
 796          'jquery-ui-autocomplete',
 797          'uiAutocompleteL10n',
 798          array(
 799              'noResults'    => __( 'No results found.' ),
 800              /* translators: Number of results found when using jQuery UI Autocomplete. */
 801              'oneResult'    => __( '1 result found. Use up and down arrow keys to navigate.' ),
 802              /* translators: %d: Number of results found when using jQuery UI Autocomplete. */
 803              'manyResults'  => __( '%d results found. Use up and down arrow keys to navigate.' ),
 804              'itemSelected' => __( 'Item selected.' ),
 805          )
 806      );
 807  
 808      // Deprecated, not used in core, most functionality is included in jQuery 1.3.
 809      $scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array( 'jquery' ), '4.2.1', 1 );
 810  
 811      // jQuery plugins.
 812      $scripts->add( 'jquery-color', '/wp-includes/js/jquery/jquery.color.min.js', array( 'jquery' ), '2.1.2', 1 );
 813      $scripts->add( 'schedule', '/wp-includes/js/jquery/jquery.schedule.js', array( 'jquery' ), '20m', 1 );
 814      $scripts->add( 'jquery-query', '/wp-includes/js/jquery/jquery.query.js', array( 'jquery' ), '2.1.7', 1 );
 815      $scripts->add( 'jquery-serialize-object', '/wp-includes/js/jquery/jquery.serialize-object.js', array( 'jquery' ), '0.2-wp', 1 );
 816      $scripts->add( 'jquery-hotkeys', "/wp-includes/js/jquery/jquery.hotkeys$suffix.js", array( 'jquery' ), '0.0.2m', 1 );
 817      $scripts->add( 'jquery-table-hotkeys', "/wp-includes/js/jquery/jquery.table-hotkeys$suffix.js", array( 'jquery', 'jquery-hotkeys' ), false, 1 );
 818      $scripts->add( 'jquery-touch-punch', '/wp-includes/js/jquery/jquery.ui.touch-punch.js', array( 'jquery-ui-core', 'jquery-ui-mouse' ), '0.2.2', 1 );
 819  
 820      // Not used any more, registered for backward compatibility.
 821      $scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array( 'jquery' ), '1.1-20110113', 1 );
 822  
 823      // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv.
 824      // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way.
 825      $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '4.1.4', 1 );
 826      $scripts->add( 'masonry', '/wp-includes/js/masonry.min.js', array( 'imagesloaded' ), '4.2.2', 1 );
 827      $scripts->add( 'jquery-masonry', '/wp-includes/js/jquery/jquery.masonry.min.js', array( 'jquery', 'masonry' ), '3.1.2b', 1 );
 828  
 829      $scripts->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.js', array( 'jquery' ), '3.1-20121105', 1 );
 830      did_action( 'init' ) && $scripts->localize(
 831          'thickbox',
 832          'thickboxL10n',
 833          array(
 834              'next'             => __( 'Next &gt;' ),
 835              'prev'             => __( '&lt; Prev' ),
 836              'image'            => __( 'Image' ),
 837              'of'               => __( 'of' ),
 838              'close'            => __( 'Close' ),
 839              'noiframes'        => __( 'This feature requires inline frames. You have iframes disabled or your browser does not support them.' ),
 840              'loadingAnimation' => includes_url( 'js/thickbox/loadingAnimation.gif' ),
 841          )
 842      );
 843  
 844      $scripts->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.min.js', array( 'jquery' ), '0.9.12' );
 845  
 846      $scripts->add( 'swfobject', '/wp-includes/js/swfobject.js', array(), '2.2-20120417' );
 847  
 848      // Error messages for Plupload.
 849      $uploader_l10n = array(
 850          'queue_limit_exceeded'      => __( 'You have attempted to queue too many files.' ),
 851          /* translators: %s: File name. */
 852          'file_exceeds_size_limit'   => __( '%s exceeds the maximum upload size for this site.' ),
 853          'zero_byte_file'            => __( 'This file is empty. Please try another.' ),
 854          'invalid_filetype'          => __( 'Sorry, this file type is not permitted for security reasons.' ),
 855          'not_an_image'              => __( 'This file is not an image. Please try another.' ),
 856          'image_memory_exceeded'     => __( 'Memory exceeded. Please try another smaller file.' ),
 857          'image_dimensions_exceeded' => __( 'This is larger than the maximum size. Please try another.' ),
 858          'default_error'             => __( 'An error occurred in the upload. Please try again later.' ),
 859          'missing_upload_url'        => __( 'There was a configuration error. Please contact the server administrator.' ),
 860          'upload_limit_exceeded'     => __( 'You may only upload 1 file.' ),
 861          'http_error'                => __( 'Unexpected response from the server. The file may have been uploaded successfully. Check in the Media Library or reload the page.' ),
 862          'http_error_image'          => __( 'Post-processing of the image failed likely because the server is busy or does not have enough resources. Uploading a smaller image may help. Suggested maximum size is 2500 pixels.' ),
 863          'upload_failed'             => __( 'Upload failed.' ),
 864          /* translators: 1: Opening link tag, 2: Closing link tag. */
 865          'big_upload_failed'         => __( 'Please try uploading this file with the %1$sbrowser uploader%2$s.' ),
 866          /* translators: %s: File name. */
 867          'big_upload_queued'         => __( '%s exceeds the maximum upload size for the multi-file uploader when used in your browser.' ),
 868          'io_error'                  => __( 'IO error.' ),
 869          'security_error'            => __( 'Security error.' ),
 870          'file_cancelled'            => __( 'File canceled.' ),
 871          'upload_stopped'            => __( 'Upload stopped.' ),
 872          'dismiss'                   => __( 'Dismiss' ),
 873          'crunching'                 => __( 'Crunching&hellip;' ),
 874          'deleted'                   => __( 'moved to the Trash.' ),
 875          /* translators: %s: File name. */
 876          'error_uploading'           => __( '&#8220;%s&#8221; has failed to upload.' ),
 877          'unsupported_image'         => __( 'This image cannot be displayed in a web browser. For best results convert it to JPEG before uploading.' ),
 878          'file_url_copied'           => __( 'The file URL has been copied to your clipboard' ),
 879      );
 880  
 881      $scripts->add( 'moxiejs', "/wp-includes/js/plupload/moxie$suffix.js", array(), '1.3.5' );
 882      $scripts->add( 'plupload', "/wp-includes/js/plupload/plupload$suffix.js", array( 'moxiejs' ), '2.1.9' );
 883      // Back compat handles:
 884      foreach ( array( 'all', 'html5', 'flash', 'silverlight', 'html4' ) as $handle ) {
 885          $scripts->add( "plupload-$handle", false, array( 'plupload' ), '2.1.1' );
 886      }
 887  
 888      $scripts->add( 'plupload-handlers', "/wp-includes/js/plupload/handlers$suffix.js", array( 'clipboard', 'jquery', 'plupload', 'underscore', 'wp-a11y', 'wp-i18n' ) );
 889      did_action( 'init' ) && $scripts->localize( 'plupload-handlers', 'pluploadL10n', $uploader_l10n );
 890  
 891      $scripts->add( 'wp-plupload', "/wp-includes/js/plupload/wp-plupload$suffix.js", array( 'plupload', 'jquery', 'json2', 'media-models' ), false, 1 );
 892      did_action( 'init' ) && $scripts->localize( 'wp-plupload', 'pluploadL10n', $uploader_l10n );
 893  
 894      // Keep 'swfupload' for back-compat.
 895      $scripts->add( 'swfupload', '/wp-includes/js/swfupload/swfupload.js', array(), '2201-20110113' );
 896      $scripts->add( 'swfupload-all', false, array( 'swfupload' ), '2201' );
 897      $scripts->add( 'swfupload-handlers', "/wp-includes/js/swfupload/handlers$suffix.js", array( 'swfupload-all', 'jquery' ), '2201-20110524' );
 898      did_action( 'init' ) && $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', $uploader_l10n );
 899  
 900      $scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", array(), false, 1 );
 901  
 902      $scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", array(), '2015-05-03' );
 903      did_action( 'init' ) && $scripts->add_data( 'json2', 'conditional', 'lt IE 8' );
 904  
 905      $scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.8.3', 1 );
 906      $scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore', 'jquery' ), '1.4.0', 1 );
 907  
 908      $scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array( 'underscore', 'jquery' ), false, 1 );
 909      did_action( 'init' ) && $scripts->localize(
 910          'wp-util',
 911          '_wpUtilSettings',
 912          array(
 913              'ajax' => array(
 914                  'url' => admin_url( 'admin-ajax.php', 'relative' ),
 915              ),
 916          )
 917      );
 918  
 919      $scripts->add( 'wp-backbone', "/wp-includes/js/wp-backbone$suffix.js", array( 'backbone', 'wp-util' ), false, 1 );
 920  
 921      $scripts->add( 'revisions', "/wp-admin/js/revisions$suffix.js", array( 'wp-backbone', 'jquery-ui-slider', 'hoverIntent' ), false, 1 );
 922  
 923      $scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array( 'jquery' ), false, 1 );
 924  
 925      $scripts->add( 'mediaelement', false, array( 'jquery', 'mediaelement-core', 'mediaelement-migrate' ), '4.2.16', 1 );
 926      $scripts->add( 'mediaelement-core', "/wp-includes/js/mediaelement/mediaelement-and-player$suffix.js", array(), '4.2.16', 1 );
 927      $scripts->add( 'mediaelement-migrate', "/wp-includes/js/mediaelement/mediaelement-migrate$suffix.js", array(), false, 1 );
 928  
 929      did_action( 'init' ) && $scripts->add_inline_script(
 930          'mediaelement-core',
 931          sprintf(
 932              'var mejsL10n = %s;',
 933              wp_json_encode(
 934                  array(
 935                      'language' => strtolower( strtok( determine_locale(), '_-' ) ),
 936                      'strings'  => array(
 937                          'mejs.download-file'       => __( 'Download File' ),
 938                          'mejs.install-flash'       => __( 'You are using a browser that does not have Flash player enabled or installed. Please turn on your Flash player plugin or download the latest version from https://get.adobe.com/flashplayer/' ),
 939                          'mejs.fullscreen'          => __( 'Fullscreen' ),
 940                          'mejs.play'                => __( 'Play' ),
 941                          'mejs.pause'               => __( 'Pause' ),
 942                          'mejs.time-slider'         => __( 'Time Slider' ),
 943                          'mejs.time-help-text'      => __( 'Use Left/Right Arrow keys to advance one second, Up/Down arrows to advance ten seconds.' ),
 944                          'mejs.live-broadcast'      => __( 'Live Broadcast' ),
 945                          'mejs.volume-help-text'    => __( 'Use Up/Down Arrow keys to increase or decrease volume.' ),
 946                          'mejs.unmute'              => __( 'Unmute' ),
 947                          'mejs.mute'                => __( 'Mute' ),
 948                          'mejs.volume-slider'       => __( 'Volume Slider' ),
 949                          'mejs.video-player'        => __( 'Video Player' ),
 950                          'mejs.audio-player'        => __( 'Audio Player' ),
 951                          'mejs.captions-subtitles'  => __( 'Captions/Subtitles' ),
 952                          'mejs.captions-chapters'   => __( 'Chapters' ),
 953                          'mejs.none'                => __( 'None' ),
 954                          'mejs.afrikaans'           => __( 'Afrikaans' ),
 955                          'mejs.albanian'            => __( 'Albanian' ),
 956                          'mejs.arabic'              => __( 'Arabic' ),
 957                          'mejs.belarusian'          => __( 'Belarusian' ),
 958                          'mejs.bulgarian'           => __( 'Bulgarian' ),
 959                          'mejs.catalan'             => __( 'Catalan' ),
 960                          'mejs.chinese'             => __( 'Chinese' ),
 961                          'mejs.chinese-simplified'  => __( 'Chinese (Simplified)' ),
 962                          'mejs.chinese-traditional' => __( 'Chinese (Traditional)' ),
 963                          'mejs.croatian'            => __( 'Croatian' ),
 964                          'mejs.czech'               => __( 'Czech' ),
 965                          'mejs.danish'              => __( 'Danish' ),
 966                          'mejs.dutch'               => __( 'Dutch' ),
 967                          'mejs.english'             => __( 'English' ),
 968                          'mejs.estonian'            => __( 'Estonian' ),
 969                          'mejs.filipino'            => __( 'Filipino' ),
 970                          'mejs.finnish'             => __( 'Finnish' ),
 971                          'mejs.french'              => __( 'French' ),
 972                          'mejs.galician'            => __( 'Galician' ),
 973                          'mejs.german'              => __( 'German' ),
 974                          'mejs.greek'               => __( 'Greek' ),
 975                          'mejs.haitian-creole'      => __( 'Haitian Creole' ),
 976                          'mejs.hebrew'              => __( 'Hebrew' ),
 977                          'mejs.hindi'               => __( 'Hindi' ),
 978                          'mejs.hungarian'           => __( 'Hungarian' ),
 979                          'mejs.icelandic'           => __( 'Icelandic' ),
 980                          'mejs.indonesian'          => __( 'Indonesian' ),
 981                          'mejs.irish'               => __( 'Irish' ),
 982                          'mejs.italian'             => __( 'Italian' ),
 983                          'mejs.japanese'            => __( 'Japanese' ),
 984                          'mejs.korean'              => __( 'Korean' ),
 985                          'mejs.latvian'             => __( 'Latvian' ),
 986                          'mejs.lithuanian'          => __( 'Lithuanian' ),
 987                          'mejs.macedonian'          => __( 'Macedonian' ),
 988                          'mejs.malay'               => __( 'Malay' ),
 989                          'mejs.maltese'             => __( 'Maltese' ),
 990                          'mejs.norwegian'           => __( 'Norwegian' ),
 991                          'mejs.persian'             => __( 'Persian' ),
 992                          'mejs.polish'              => __( 'Polish' ),
 993                          'mejs.portuguese'          => __( 'Portuguese' ),
 994                          'mejs.romanian'            => __( 'Romanian' ),
 995                          'mejs.russian'             => __( 'Russian' ),
 996                          'mejs.serbian'             => __( 'Serbian' ),
 997                          'mejs.slovak'              => __( 'Slovak' ),
 998                          'mejs.slovenian'           => __( 'Slovenian' ),
 999                          'mejs.spanish'             => __( 'Spanish' ),
1000                          'mejs.swahili'             => __( 'Swahili' ),
1001                          'mejs.swedish'             => __( 'Swedish' ),
1002                          'mejs.tagalog'             => __( 'Tagalog' ),
1003                          'mejs.thai'                => __( 'Thai' ),
1004                          'mejs.turkish'             => __( 'Turkish' ),
1005                          'mejs.ukrainian'           => __( 'Ukrainian' ),
1006                          'mejs.vietnamese'          => __( 'Vietnamese' ),
1007                          'mejs.welsh'               => __( 'Welsh' ),
1008                          'mejs.yiddish'             => __( 'Yiddish' ),
1009                      ),
1010                  )
1011              )
1012          ),
1013          'before'
1014      );
1015  
1016      $scripts->add( 'mediaelement-vimeo', '/wp-includes/js/mediaelement/renderers/vimeo.min.js', array( 'mediaelement' ), '4.2.16', 1 );
1017      $scripts->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.js", array( 'mediaelement' ), false, 1 );
1018      $mejs_settings = array(
1019          'pluginPath'  => includes_url( 'js/mediaelement/', 'relative' ),
1020          'classPrefix' => 'mejs-',
1021          'stretching'  => 'responsive',
1022      );
1023      did_action( 'init' ) && $scripts->localize(
1024          'mediaelement',
1025          '_wpmejsSettings',
1026          /**
1027           * Filters the MediaElement configuration settings.
1028           *
1029           * @since 4.4.0
1030           *
1031           * @param array $mejs_settings MediaElement settings array.
1032           */
1033          apply_filters( 'mejs_settings', $mejs_settings )
1034      );
1035  
1036      $scripts->add( 'wp-codemirror', '/wp-includes/js/codemirror/codemirror.min.js', array(), '5.29.1-alpha-ee20357' );
1037      $scripts->add( 'csslint', '/wp-includes/js/codemirror/csslint.js', array(), '1.0.5' );
1038      $scripts->add( 'esprima', '/wp-includes/js/codemirror/esprima.js', array(), '4.0.0' );
1039      $scripts->add( 'jshint', '/wp-includes/js/codemirror/fakejshint.js', array( 'esprima' ), '2.9.5' );
1040      $scripts->add( 'jsonlint', '/wp-includes/js/codemirror/jsonlint.js', array(), '1.6.2' );
1041      $scripts->add( 'htmlhint', '/wp-includes/js/codemirror/htmlhint.js', array(), '0.9.14-xwp' );
1042      $scripts->add( 'htmlhint-kses', '/wp-includes/js/codemirror/htmlhint-kses.js', array( 'htmlhint' ) );
1043      $scripts->add( 'code-editor', "/wp-admin/js/code-editor$suffix.js", array( 'jquery', 'wp-codemirror', 'underscore' ) );
1044      $scripts->add( 'wp-theme-plugin-editor', "/wp-admin/js/theme-plugin-editor$suffix.js", array( 'common', 'wp-util', 'wp-sanitize', 'jquery', 'jquery-ui-core', 'wp-a11y', 'underscore' ) );
1045      $scripts->set_translations( 'wp-theme-plugin-editor' );
1046  
1047      $scripts->add( 'wp-playlist', "/wp-includes/js/mediaelement/wp-playlist$suffix.js", array( 'wp-util', 'backbone', 'mediaelement' ), false, 1 );
1048  
1049      $scripts->add( 'zxcvbn-async', "/wp-includes/js/zxcvbn-async$suffix.js", array(), '1.0' );
1050      did_action( 'init' ) && $scripts->localize(
1051          'zxcvbn-async',
1052          '_zxcvbnSettings',
1053          array(
1054              'src' => empty( $guessed_url ) ? includes_url( '/js/zxcvbn.min.js' ) : $scripts->base_url . '/wp-includes/js/zxcvbn.min.js',
1055          )
1056      );
1057  
1058      $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array( 'jquery', 'zxcvbn-async' ), false, 1 );
1059      did_action( 'init' ) && $scripts->localize(
1060          'password-strength-meter',
1061          'pwsL10n',
1062          array(
1063              'unknown'  => _x( 'Password strength unknown', 'password strength' ),
1064              'short'    => _x( 'Very weak', 'password strength' ),
1065              'bad'      => _x( 'Weak', 'password strength' ),
1066              'good'     => _x( 'Medium', 'password strength' ),
1067              'strong'   => _x( 'Strong', 'password strength' ),
1068              'mismatch' => _x( 'Mismatch', 'password mismatch' ),
1069          )
1070      );
1071      $scripts->set_translations( 'password-strength-meter' );
1072  
1073      $scripts->add( 'application-passwords', "/wp-admin/js/application-passwords$suffix.js", array( 'jquery', 'wp-util', 'wp-api-request', 'wp-date', 'wp-i18n', 'wp-hooks' ), false, 1 );
1074      $scripts->set_translations( 'application-passwords' );
1075  
1076      $scripts->add( 'auth-app', "/wp-admin/js/auth-app$suffix.js", array( 'jquery', 'wp-api-request', 'wp-i18n', 'wp-hooks' ), false, 1 );
1077      $scripts->set_translations( 'auth-app' );
1078  
1079      $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util' ), false, 1 );
1080      $scripts->set_translations( 'user-profile' );
1081      $user_id = isset( $_GET['user_id'] ) ? (int) $_GET['user_id'] : 0;
1082      did_action( 'init' ) && $scripts->localize(
1083          'user-profile',
1084          'userProfileL10n',
1085          array(
1086              'user_id' => $user_id,
1087              'nonce'   => wp_create_nonce( 'reset-password-for-' . $user_id ),
1088          )
1089      );
1090  
1091      $scripts->add( 'language-chooser', "/wp-admin/js/language-chooser$suffix.js", array( 'jquery' ), false, 1 );
1092  
1093      $scripts->add( 'user-suggest', "/wp-admin/js/user-suggest$suffix.js", array( 'jquery-ui-autocomplete' ), false, 1 );
1094  
1095      $scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array( 'hoverintent-js' ), false, 1 );
1096  
1097      $scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 );
1098      did_action( 'init' ) && $scripts->localize(
1099          'wplink',
1100          'wpLinkL10n',
1101          array(
1102              'title'          => __( 'Insert/edit link' ),
1103              'update'         => __( 'Update' ),
1104              'save'           => __( 'Add Link' ),
1105              'noTitle'        => __( '(no title)' ),
1106              'noMatchesFound' => __( 'No results found.' ),
1107              'linkSelected'   => __( 'Link selected.' ),
1108              'linkInserted'   => __( 'Link inserted.' ),
1109              /* translators: Minimum input length in characters to start searching posts in the "Insert/edit link" modal. */
1110              'minInputLength' => (int) _x( '3', 'minimum input length for searching post links' ),
1111          )
1112      );
1113  
1114      $scripts->add( 'wpdialogs', "/wp-includes/js/wpdialog$suffix.js", array( 'jquery-ui-dialog' ), false, 1 );
1115  
1116      $scripts->add( 'word-count', "/wp-admin/js/word-count$suffix.js", array(), false, 1 );
1117  
1118      $scripts->add( 'media-upload', "/wp-admin/js/media-upload$suffix.js", array( 'thickbox', 'shortcode' ), false, 1 );
1119  
1120      $scripts->add( 'hoverIntent', "/wp-includes/js/hoverIntent$suffix.js", array( 'jquery' ), '1.8.1', 1 );
1121  
1122      // JS-only version of hoverintent (no dependencies).
1123      $scripts->add( 'hoverintent-js', '/wp-includes/js/hoverintent-js.min.js', array(), '2.2.1', 1 );
1124  
1125      $scripts->add( 'customize-base', "/wp-includes/js/customize-base$suffix.js", array( 'jquery', 'json2', 'underscore' ), false, 1 );
1126      $scripts->add( 'customize-loader', "/wp-includes/js/customize-loader$suffix.js", array( 'customize-base' ), false, 1 );
1127      $scripts->add( 'customize-preview', "/wp-includes/js/customize-preview$suffix.js", array( 'wp-a11y', 'customize-base' ), false, 1 );
1128      $scripts->add( 'customize-models', '/wp-includes/js/customize-models.js', array( 'underscore', 'backbone' ), false, 1 );
1129      $scripts->add( 'customize-views', '/wp-includes/js/customize-views.js', array( 'jquery', 'underscore', 'imgareaselect', 'customize-models', 'media-editor', 'media-views' ), false, 1 );
1130      $scripts->add( 'customize-controls', "/wp-admin/js/customize-controls$suffix.js", array( 'customize-base', 'wp-a11y', 'wp-util', 'jquery-ui-core' ), false, 1 );
1131      did_action( 'init' ) && $scripts->localize(
1132          'customize-controls',
1133          '_wpCustomizeControlsL10n',
1134          array(
1135              'activate'                => __( 'Activate &amp; Publish' ),
1136              'save'                    => __( 'Save &amp; Publish' ), // @todo Remove as not required.
1137              'publish'                 => __( 'Publish' ),
1138              'published'               => __( 'Published' ),
1139              'saveDraft'               => __( 'Save Draft' ),
1140              'draftSaved'              => __( 'Draft Saved' ),
1141              'updating'                => __( 'Updating' ),
1142              'schedule'                => _x( 'Schedule', 'customizer changeset action/button label' ),
1143              'scheduled'               => _x( 'Scheduled', 'customizer changeset status' ),
1144              'invalid'                 => __( 'Invalid' ),
1145              'saveBeforeShare'         => __( 'Please save your changes in order to share the preview.' ),
1146              'futureDateError'         => __( 'You must supply a future date to schedule.' ),
1147              'saveAlert'               => __( 'The changes you made will be lost if you navigate away from this page.' ),
1148              'saved'                   => __( 'Saved' ),
1149              'cancel'                  => __( 'Cancel' ),
1150              'close'                   => __( 'Close' ),
1151              'action'                  => __( 'Action' ),
1152              'discardChanges'          => __( 'Discard changes' ),
1153              'cheatin'                 => __( 'Something went wrong.' ),
1154              'notAllowedHeading'       => __( 'You need a higher level of permission.' ),
1155              'notAllowed'              => __( 'Sorry, you are not allowed to customize this site.' ),
1156              'previewIframeTitle'      => __( 'Site Preview' ),
1157              'loginIframeTitle'        => __( 'Session expired' ),
1158              'collapseSidebar'         => _x( 'Hide Controls', 'label for hide controls button without length constraints' ),
1159              'expandSidebar'           => _x( 'Show Controls', 'label for hide controls button without length constraints' ),
1160              'untitledBlogName'        => __( '(Untitled)' ),
1161              'unknownRequestFail'      => __( 'Looks like something&#8217;s gone wrong. Wait a couple seconds, and then try again.' ),
1162              'themeDownloading'        => __( 'Downloading your new theme&hellip;' ),
1163              'themePreviewWait'        => __( 'Setting up your live preview. This may take a bit.' ),
1164              'revertingChanges'        => __( 'Reverting unpublished changes&hellip;' ),
1165              'trashConfirm'            => __( 'Are you sure you want to discard your unpublished changes?' ),
1166              /* translators: %s: Display name of the user who has taken over the changeset in customizer. */
1167              'takenOverMessage'        => __( '%s has taken over and is currently customizing.' ),
1168              /* translators: %s: URL to the Customizer to load the autosaved version. */
1169              'autosaveNotice'          => __( 'There is a more recent autosave of your changes than the one you are previewing. <a href="%s">Restore the autosave</a>' ),
1170              'videoHeaderNotice'       => __( 'This theme doesn&#8217;t support video headers on this page. Navigate to the front page or another page that supports video headers.' ),
1171              // Used for overriding the file types allowed in Plupload.
1172              'allowedFiles'            => __( 'Allowed Files' ),
1173              'customCssError'          => array(
1174                  /* translators: %d: Error count. */
1175                  'singular' => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 1 ),
1176                  /* translators: %d: Error count. */
1177                  'plural'   => _n( 'There is %d error which must be fixed before you can save.', 'There are %d errors which must be fixed before you can save.', 2 ),
1178                  // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
1179              ),
1180              'pageOnFrontError'        => __( 'Homepage and posts page must be different.' ),
1181              'saveBlockedError'        => array(
1182                  /* translators: %s: Number of invalid settings. */
1183                  'singular' => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 1 ),
1184                  /* translators: %s: Number of invalid settings. */
1185                  'plural'   => _n( 'Unable to save due to %s invalid setting.', 'Unable to save due to %s invalid settings.', 2 ),
1186                  // @todo This is lacking, as some languages have a dedicated dual form. For proper handling of plurals in JS, see #20491.
1187              ),
1188              'scheduleDescription'     => __( 'Schedule your customization changes to publish ("go live") at a future date.' ),
1189              'themePreviewUnavailable' => __( 'Sorry, you can&#8217;t preview new themes when you have changes scheduled or saved as a draft. Please publish your changes, or wait until they publish to preview new themes.' ),
1190              'themeInstallUnavailable' => sprintf(
1191                  /* translators: %s: URL to Add Themes admin screen. */
1192                  __( 'You won&#8217;t be able to install new themes from here yet since your install requires SFTP credentials. For now, please <a href="%s">add themes in the admin</a>.' ),
1193                  esc_url( admin_url( 'theme-install.php' ) )
1194              ),
1195              'publishSettings'         => __( 'Publish Settings' ),
1196              'invalidDate'             => __( 'Invalid date.' ),
1197              'invalidValue'            => __( 'Invalid value.' ),
1198          )
1199      );
1200      $scripts->add( 'customize-selective-refresh', "/wp-includes/js/customize-selective-refresh$suffix.js", array( 'jquery', 'wp-util', 'customize-preview' ), false, 1 );
1201  
1202      $scripts->add( 'customize-widgets', "/wp-admin/js/customize-widgets$suffix.js", array( 'jquery', 'jquery-ui-sortable', 'jquery-ui-droppable', 'wp-backbone', 'customize-controls' ), false, 1 );
1203      $scripts->add( 'customize-preview-widgets', "/wp-includes/js/customize-preview-widgets$suffix.js", array( 'jquery', 'wp-util', 'customize-preview', 'customize-selective-refresh' ), false, 1 );
1204  
1205      $scripts->add( 'customize-nav-menus', "/wp-admin/js/customize-nav-menus$suffix.js", array( 'jquery', 'wp-backbone', 'customize-controls', 'accordion', 'nav-menu', 'wp-sanitize' ), false, 1 );
1206      $scripts->add( 'customize-preview-nav-menus', "/wp-includes/js/customize-preview-nav-menus$suffix.js", array( 'jquery', 'wp-util', 'customize-preview', 'customize-selective-refresh' ), false, 1 );
1207  
1208      $scripts->add( 'wp-custom-header', "/wp-includes/js/wp-custom-header$suffix.js", array( 'wp-a11y' ), false, 1 );
1209  
1210      $scripts->add( 'accordion', "/wp-admin/js/accordion$suffix.js", array( 'jquery' ), false, 1 );
1211  
1212      $scripts->add( 'shortcode', "/wp-includes/js/shortcode$suffix.js", array( 'underscore' ), false, 1 );
1213      $scripts->add( 'media-models', "/wp-includes/js/media-models$suffix.js", array( 'wp-backbone' ), false, 1 );
1214      did_action( 'init' ) && $scripts->localize(
1215          'media-models',
1216          '_wpMediaModelsL10n',
1217          array(
1218              'settings' => array(
1219                  'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
1220                  'post'    => array( 'id' => 0 ),
1221              ),
1222          )
1223      );
1224  
1225      $scripts->add( 'wp-embed', "/wp-includes/js/wp-embed$suffix.js" );
1226  
1227      // To enqueue media-views or media-editor, call wp_enqueue_media().
1228      // Both rely on numerous settings, styles, and templates to operate correctly.
1229      $scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement', 'wp-api-request', 'wp-a11y', 'clipboard' ), false, 1 );
1230      $scripts->set_translations( 'media-views' );
1231  
1232      $scripts->add( 'media-editor', "/wp-includes/js/media-editor$suffix.js", array( 'shortcode', 'media-views' ), false, 1 );
1233      $scripts->set_translations( 'media-editor' );
1234      $scripts->add( 'media-audiovideo', "/wp-includes/js/media-audiovideo$suffix.js", array( 'media-editor' ), false, 1 );
1235      $scripts->add( 'mce-view', "/wp-includes/js/mce-view$suffix.js", array( 'shortcode', 'jquery', 'media-views', 'media-audiovideo' ), false, 1 );
1236  
1237      $scripts->add( 'wp-api', "/wp-includes/js/wp-api$suffix.js", array( 'jquery', 'backbone', 'underscore', 'wp-api-request' ), false, 1 );
1238  
1239      if ( is_admin() ) {
1240          $scripts->add( 'admin-tags', "/wp-admin/js/tags$suffix.js", array( 'jquery', 'wp-ajax-response' ), false, 1 );
1241          $scripts->set_translations( 'admin-tags' );
1242  
1243          $scripts->add( 'admin-comments', "/wp-admin/js/edit-comments$suffix.js", array( 'wp-lists', 'quicktags', 'jquery-query' ), false, 1 );
1244          $scripts->set_translations( 'admin-comments' );
1245          did_action( 'init' ) && $scripts->localize(
1246              'admin-comments',
1247              'adminCommentsSettings',
1248              array(
1249                  'hotkeys_highlight_first' => isset( $_GET['hotkeys_highlight_first'] ),
1250                  'hotkeys_highlight_last'  => isset( $_GET['hotkeys_highlight_last'] ),
1251              )
1252          );
1253  
1254          $scripts->add( 'xfn', "/wp-admin/js/xfn$suffix.js", array( 'jquery' ), false, 1 );
1255  
1256          $scripts->add( 'postbox', "/wp-admin/js/postbox$suffix.js", array( 'jquery-ui-sortable', 'wp-a11y' ), false, 1 );
1257          $scripts->set_translations( 'postbox' );
1258  
1259          $scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'tags-suggest' ), false, 1 );
1260          $scripts->set_translations( 'tags-box' );
1261  
1262          $scripts->add( 'tags-suggest', "/wp-admin/js/tags-suggest$suffix.js", array( 'jquery-ui-autocomplete', 'wp-a11y' ), false, 1 );
1263          $scripts->set_translations( 'tags-suggest' );
1264  
1265          $scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box', 'underscore', 'word-count', 'wp-a11y', 'wp-sanitize', 'clipboard' ), false, 1 );
1266          $scripts->set_translations( 'post' );
1267  
1268          $scripts->add( 'editor-expand', "/wp-admin/js/editor-expand$suffix.js", array( 'jquery', 'underscore' ), false, 1 );
1269  
1270          $scripts->add( 'link', "/wp-admin/js/link$suffix.js", array( 'wp-lists', 'postbox' ), false, 1 );
1271  
1272          $scripts->add( 'comment', "/wp-admin/js/comment$suffix.js", array( 'jquery', 'postbox' ), false, 1 );
1273          $scripts->set_translations( 'comment' );
1274  
1275          $scripts->add( 'admin-gallery', "/wp-admin/js/gallery$suffix.js", array( 'jquery-ui-sortable' ) );
1276  
1277          $scripts->add( 'admin-widgets', "/wp-admin/js/widgets$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-a11y' ), false, 1 );
1278          $scripts->set_translations( 'admin-widgets' );
1279  
1280          $scripts->add( 'media-widgets', "/wp-admin/js/widgets/media-widgets$suffix.js", array( 'jquery', 'media-models', 'media-views', 'wp-api-request' ) );
1281          $scripts->add_inline_script( 'media-widgets', 'wp.mediaWidgets.init();', 'after' );
1282  
1283          $scripts->add( 'media-audio-widget', "/wp-admin/js/widgets/media-audio-widget$suffix.js", array( 'media-widgets', 'media-audiovideo' ) );
1284          $scripts->add( 'media-image-widget', "/wp-admin/js/widgets/media-image-widget$suffix.js", array( 'media-widgets' ) );
1285          $scripts->add( 'media-gallery-widget', "/wp-admin/js/widgets/media-gallery-widget$suffix.js", array( 'media-widgets' ) );
1286          $scripts->add( 'media-video-widget', "/wp-admin/js/widgets/media-video-widget$suffix.js", array( 'media-widgets', 'media-audiovideo', 'wp-api-request' ) );
1287          $scripts->add( 'text-widgets', "/wp-admin/js/widgets/text-widgets$suffix.js", array( 'jquery', 'backbone', 'editor', 'wp-util', 'wp-a11y' ) );
1288          $scripts->add( 'custom-html-widgets', "/wp-admin/js/widgets/custom-html-widgets$suffix.js", array( 'jquery', 'backbone', 'wp-util', 'jquery-ui-core', 'wp-a11y' ) );
1289  
1290          $scripts->add( 'theme', "/wp-admin/js/theme$suffix.js", array( 'wp-backbone', 'wp-a11y', 'customize-base' ), false, 1 );
1291  
1292          $scripts->add( 'inline-edit-post', "/wp-admin/js/inline-edit-post$suffix.js", array( 'jquery', 'tags-suggest', 'wp-a11y' ), false, 1 );
1293          $scripts->set_translations( 'inline-edit-post' );
1294  
1295          $scripts->add( 'inline-edit-tax', "/wp-admin/js/inline-edit-tax$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 );
1296          $scripts->set_translations( 'inline-edit-tax' );
1297  
1298          $scripts->add( 'plugin-install', "/wp-admin/js/plugin-install$suffix.js", array( 'jquery', 'jquery-ui-core', 'thickbox' ), false, 1 );
1299          $scripts->set_translations( 'plugin-install' );
1300  
1301          $scripts->add( 'site-health', "/wp-admin/js/site-health$suffix.js", array( 'clipboard', 'jquery', 'wp-util', 'wp-a11y', 'wp-api-request', 'wp-url', 'wp-i18n', 'wp-hooks' ), false, 1 );
1302          $scripts->set_translations( 'site-health' );
1303  
1304          $scripts->add( 'privacy-tools', "/wp-admin/js/privacy-tools$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 );
1305          $scripts->set_translations( 'privacy-tools' );
1306  
1307          $scripts->add( 'updates', "/wp-admin/js/updates$suffix.js", array( 'common', 'jquery', 'wp-util', 'wp-a11y', 'wp-sanitize' ), false, 1 );
1308          $scripts->set_translations( 'updates' );
1309          did_action( 'init' ) && $scripts->localize(
1310              'updates',
1311              '_wpUpdatesSettings',
1312              array(
1313                  'ajax_nonce' => wp_create_nonce( 'updates' ),
1314              )
1315          );
1316  
1317          $scripts->add( 'farbtastic', '/wp-admin/js/farbtastic.js', array( 'jquery' ), '1.2' );
1318  
1319          $scripts->add( 'iris', '/wp-admin/js/iris.min.js', array( 'jquery-ui-draggable', 'jquery-ui-slider', 'jquery-touch-punch' ), '1.0.7', 1 );
1320          $scripts->add( 'wp-color-picker', "/wp-admin/js/color-picker$suffix.js", array( 'iris' ), false, 1 );
1321          $scripts->set_translations( 'wp-color-picker' );
1322  
1323          $scripts->add( 'dashboard', "/wp-admin/js/dashboard$suffix.js", array( 'jquery', 'admin-comments', 'postbox', 'wp-util', 'wp-a11y', 'wp-date' ), false, 1 );
1324          $scripts->set_translations( 'dashboard' );
1325  
1326          $scripts->add( 'list-revisions', "/wp-includes/js/wp-list-revisions$suffix.js" );
1327  
1328          $scripts->add( 'media-grid', "/wp-includes/js/media-grid$suffix.js", array( 'media-editor' ), false, 1 );
1329          $scripts->add( 'media', "/wp-admin/js/media$suffix.js", array( 'jquery' ), false, 1 );
1330          $scripts->set_translations( 'media' );
1331  
1332          $scripts->add( 'image-edit', "/wp-admin/js/image-edit$suffix.js", array( 'jquery', 'jquery-ui-core', 'json2', 'imgareaselect', 'wp-a11y' ), false, 1 );
1333          $scripts->set_translations( 'image-edit' );
1334  
1335          $scripts->add( 'set-post-thumbnail', "/wp-admin/js/set-post-thumbnail$suffix.js", array( 'jquery' ), false, 1 );
1336          $scripts->set_translations( 'set-post-thumbnail' );
1337  
1338          /*
1339           * Navigation Menus: Adding underscore as a dependency to utilize _.debounce
1340           * see https://core.trac.wordpress.org/ticket/42321
1341           */
1342          $scripts->add( 'nav-menu', "/wp-admin/js/nav-menu$suffix.js", array( 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'wp-lists', 'postbox', 'json2', 'underscore' ) );
1343          $scripts->set_translations( 'nav-menu' );
1344  
1345          $scripts->add( 'custom-header', '/wp-admin/js/custom-header.js', array( 'jquery-masonry' ), false, 1 );
1346          $scripts->add( 'custom-background', "/wp-admin/js/custom-background$suffix.js", array( 'wp-color-picker', 'media-views' ), false, 1 );
1347          $scripts->add( 'media-gallery', "/wp-admin/js/media-gallery$suffix.js", array( 'jquery' ), false, 1 );
1348  
1349          $scripts->add( 'svg-painter', '/wp-admin/js/svg-painter.js', array( 'jquery' ), false, 1 );
1350      }
1351  }
1352  
1353  /**
1354   * Assign default styles to $styles object.
1355   *
1356   * Nothing is returned, because the $styles parameter is passed by reference.
1357   * Meaning that whatever object is passed will be updated without having to
1358   * reassign the variable that was passed back to the same value. This saves
1359   * memory.
1360   *
1361   * Adding default styles is not the only task, it also assigns the base_url
1362   * property, the default version, and text direction for the object.
1363   *
1364   * @since 2.6.0
1365   *
1366   * @param WP_Styles $styles
1367   */
1368  function wp_default_styles( $styles ) {
1369      // Include an unmodified $wp_version.
1370      require  ABSPATH . WPINC . '/version.php';
1371  
1372      if ( ! defined( 'SCRIPT_DEBUG' ) ) {
1373          define( 'SCRIPT_DEBUG', false !== strpos( $wp_version, '-src' ) );
1374      }
1375  
1376      $guessurl = site_url();
1377  
1378      if ( ! $guessurl ) {
1379          $guessurl = wp_guess_url();
1380      }
1381  
1382      $styles->base_url        = $guessurl;
1383      $styles->content_url     = defined( 'WP_CONTENT_URL' ) ? WP_CONTENT_URL : '';
1384      $styles->default_version = get_bloginfo( 'version' );
1385      $styles->text_direction  = function_exists( 'is_rtl' ) && is_rtl() ? 'rtl' : 'ltr';
1386      $styles->default_dirs    = array( '/wp-admin/', '/wp-includes/css/' );
1387  
1388      // Open Sans is no longer used by core, but may be relied upon by themes and plugins.
1389      $open_sans_font_url = '';
1390  
1391      /*
1392       * translators: If there are characters in your language that are not supported
1393       * by Open Sans, translate this to 'off'. Do not translate into your own language.
1394       */
1395      if ( 'off' !== _x( 'on', 'Open Sans font: on or off' ) ) {
1396          $subsets = 'latin,latin-ext';
1397  
1398          /*
1399           * translators: To add an additional Open Sans character subset specific to your language,
1400           * translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language.
1401           */
1402          $subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)' );
1403  
1404          if ( 'cyrillic' === $subset ) {
1405              $subsets .= ',cyrillic,cyrillic-ext';
1406          } elseif ( 'greek' === $subset ) {
1407              $subsets .= ',greek,greek-ext';
1408          } elseif ( 'vietnamese' === $subset ) {
1409              $subsets .= ',vietnamese';
1410          }
1411  
1412          // Hotlink Open Sans, for now.
1413          $open_sans_font_url = "https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600&subset=$subsets&display=fallback";
1414      }
1415  
1416      // Register a stylesheet for the selected admin color scheme.
1417      $styles->add( 'colors', true, array( 'wp-admin', 'buttons' ) );
1418  
1419      $suffix = SCRIPT_DEBUG ? '' : '.min';
1420  
1421      // Admin CSS.
1422      $styles->add( 'common', "/wp-admin/css/common$suffix.css" );
1423      $styles->add( 'forms', "/wp-admin/css/forms$suffix.css" );
1424      $styles->add( 'admin-menu', "/wp-admin/css/admin-menu$suffix.css" );
1425      $styles->add( 'dashboard', "/wp-admin/css/dashboard$suffix.css" );
1426      $styles->add( 'list-tables', "/wp-admin/css/list-tables$suffix.css" );
1427      $styles->add( 'edit', "/wp-admin/css/edit$suffix.css" );
1428      $styles->add( 'revisions', "/wp-admin/css/revisions$suffix.css" );
1429      $styles->add( 'media', "/wp-admin/css/media$suffix.css" );
1430      $styles->add( 'themes', "/wp-admin/css/themes$suffix.css" );
1431      $styles->add( 'about', "/wp-admin/css/about$suffix.css" );
1432      $styles->add( 'nav-menus', "/wp-admin/css/nav-menus$suffix.css" );
1433      $styles->add( 'widgets', "/wp-admin/css/widgets$suffix.css", array( 'wp-pointer' ) );
1434      $styles->add( 'site-icon', "/wp-admin/css/site-icon$suffix.css" );
1435      $styles->add( 'l10n', "/wp-admin/css/l10n$suffix.css" );
1436      $styles->add( 'code-editor', "/wp-admin/css/code-editor$suffix.css", array( 'wp-codemirror' ) );
1437      $styles->add( 'site-health', "/wp-admin/css/site-health$suffix.css" );
1438  
1439      $styles->add( 'wp-admin', false, array( 'dashicons', 'common', 'forms', 'admin-menu', 'dashboard', 'list-tables', 'edit', 'revisions', 'media', 'themes', 'about', 'nav-menus', 'widgets', 'site-icon', 'l10n' ) );
1440  
1441      $styles->add( 'login', "/wp-admin/css/login$suffix.css", array( 'dashicons', 'buttons', 'forms', 'l10n' ) );
1442      $styles->add( 'install', "/wp-admin/css/install$suffix.css", array( 'dashicons', 'buttons', 'forms', 'l10n' ) );
1443      $styles->add( 'wp-color-picker', "/wp-admin/css/color-picker$suffix.css" );
1444      $styles->add( 'customize-controls', "/wp-admin/css/customize-controls$suffix.css", array( 'wp-admin', 'colors', 'imgareaselect' ) );
1445      $styles->add( 'customize-widgets', "/wp-admin/css/customize-widgets$suffix.css", array( 'wp-admin', 'colors' ) );
1446      $styles->add( 'customize-nav-menus', "/wp-admin/css/customize-nav-menus$suffix.css", array( 'wp-admin', 'colors' ) );
1447  
1448      // Common dependencies.
1449      $styles->add( 'buttons', "/wp-includes/css/buttons$suffix.css" );
1450      $styles->add( 'dashicons', "/wp-includes/css/dashicons$suffix.css" );
1451  
1452      // Includes CSS.
1453      $styles->add( 'admin-bar', "/wp-includes/css/admin-bar$suffix.css", array( 'dashicons' ) );
1454      $styles->add( 'wp-auth-check', "/wp-includes/css/wp-auth-check$suffix.css", array( 'dashicons' ) );
1455      $styles->add( 'editor-buttons', "/wp-includes/css/editor$suffix.css", array( 'dashicons' ) );
1456      $styles->add( 'media-views', "/wp-includes/css/media-views$suffix.css", array( 'buttons', 'dashicons', 'wp-mediaelement' ) );
1457      $styles->add( 'wp-pointer', "/wp-includes/css/wp-pointer$suffix.css", array( 'dashicons' ) );
1458      $styles->add( 'customize-preview', "/wp-includes/css/customize-preview$suffix.css", array( 'dashicons' ) );
1459      $styles->add( 'wp-embed-template-ie', "/wp-includes/css/wp-embed-template-ie$suffix.css" );
1460      $styles->add_data( 'wp-embed-template-ie', 'conditional', 'lte IE 8' );
1461  
1462      // External libraries and friends.
1463      $styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.8' );
1464      $styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css", array( 'dashicons' ) );
1465      $styles->add( 'mediaelement', '/wp-includes/js/mediaelement/mediaelementplayer-legacy.min.css', array(), '4.2.16' );
1466      $styles->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.css", array( 'mediaelement' ) );
1467      $styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css', array( 'dashicons' ) );
1468      $styles->add( 'wp-codemirror', '/wp-includes/js/codemirror/codemirror.min.css', array(), '5.29.1-alpha-ee20357' );
1469  
1470      // Deprecated CSS.
1471      $styles->add( 'deprecated-media', "/wp-admin/css/deprecated-media$suffix.css" );
1472      $styles->add( 'farbtastic', "/wp-admin/css/farbtastic$suffix.css", array(), '1.3u1' );
1473      $styles->add( 'jcrop', '/wp-includes/js/jcrop/jquery.Jcrop.min.css', array(), '0.9.12' );
1474      $styles->add( 'colors-fresh', false, array( 'wp-admin', 'buttons' ) ); // Old handle.
1475      $styles->add( 'open-sans', $open_sans_font_url ); // No longer used in core as of 4.6.
1476  
1477      // Noto Serif is no longer used by core, but may be relied upon by themes and plugins.
1478      $fonts_url = '';
1479  
1480      /*
1481       * translators: Use this to specify the proper Google Font name and variants
1482       * to load that is supported by your language. Do not translate.
1483       * Set to 'off' to disable loading.
1484       */
1485      $font_family = _x( 'Noto Serif:400,400i,700,700i', 'Google Font Name and Variants' );
1486      if ( 'off' !== $font_family ) {
1487          $fonts_url = 'https://fonts.googleapis.com/css?family=' . urlencode( $font_family );
1488      }
1489      $styles->add( 'wp-editor-font', $fonts_url ); // No longer used in core as of 5.7.
1490      $block_library_theme_path = WPINC . "/css/dist/block-library/theme$suffix.css";
1491      $styles->add( 'wp-block-library-theme', "/$block_library_theme_path" );
1492      $styles->add_data( 'wp-block-library-theme', 'path', ABSPATH . $block_library_theme_path );
1493  
1494      $styles->add(
1495          'wp-reset-editor-styles',
1496          "/wp-includes/css/dist/block-library/reset$suffix.css",
1497          array( 'common', 'forms' ) // Make sure the reset is loaded after the default WP Admin styles.
1498      );
1499  
1500      $styles->add(
1501          'wp-editor-classic-layout-styles',
1502          "/wp-includes/css/dist/edit-post/classic$suffix.css",
1503          array()
1504      );
1505  
1506      $wp_edit_blocks_dependencies = array(
1507          'wp-components',
1508          'wp-editor',
1509          // This need to be added before the block library styles,
1510          // The block library styles override the "reset" styles.
1511          'wp-reset-editor-styles',
1512          'wp-block-library',
1513          'wp-reusable-blocks',
1514      );
1515  
1516      // Only load the default layout and margin styles for themes without theme.json file.
1517      if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
1518          $wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles';
1519      }
1520  
1521      global $editor_styles;
1522      if ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) {
1523          // Include opinionated block styles if no $editor_styles are declared, so the editor never appears broken.
1524          $wp_edit_blocks_dependencies[] = 'wp-block-library-theme';
1525      }
1526  
1527      $styles->add(
1528          'wp-edit-blocks',
1529          "/wp-includes/css/dist/block-library/editor$suffix.css",
1530          $wp_edit_blocks_dependencies
1531      );
1532  
1533      $package_styles = array(
1534          'block-editor'         => array( 'wp-components' ),
1535          'block-library'        => array(),
1536          'block-directory'      => array(),
1537          'components'           => array(),
1538          'edit-post'            => array(
1539              'wp-components',
1540              'wp-block-editor',
1541              'wp-editor',
1542              'wp-edit-blocks',
1543              'wp-block-library',
1544              'wp-nux',
1545          ),
1546          'editor'               => array(
1547              'wp-components',
1548              'wp-block-editor',
1549              'wp-nux',
1550              'wp-reusable-blocks',
1551          ),
1552          'format-library'       => array(),
1553          'list-reusable-blocks' => array( 'wp-components' ),
1554          'reusable-blocks'      => array( 'wp-components' ),
1555          'nux'                  => array( 'wp-components' ),
1556          'edit-widgets'         => array(
1557              'wp-components',
1558              'wp-block-editor',
1559              'wp-edit-blocks',
1560              'wp-block-library',
1561              'wp-reusable-blocks',
1562          ),
1563          'customize-widgets'    => array(
1564              'wp-components',
1565              'wp-block-editor',
1566              'wp-edit-blocks',
1567              'wp-block-library',
1568              'wp-reusable-blocks',
1569          ),
1570      );
1571  
1572      foreach ( $package_styles as $package => $dependencies ) {
1573          $handle = 'wp-' . $package;
1574          $path   = "/wp-includes/css/dist/$package/style$suffix.css";
1575  
1576          if ( 'block-library' === $package && wp_should_load_separate_core_block_assets() ) {
1577              $path = "/wp-includes/css/dist/$package/common$suffix.css";
1578          }
1579          $styles->add( $handle, $path, $dependencies );
1580          $styles->add_data( $handle, 'path', ABSPATH . $path );
1581      }
1582  
1583      // RTL CSS.
1584      $rtl_styles = array(
1585          // Admin CSS.
1586          'common',
1587          'forms',
1588          'admin-menu',
1589          'dashboard',
1590          'list-tables',
1591          'edit',
1592          'revisions',
1593          'media',
1594          'themes',
1595          'about',
1596          'nav-menus',
1597          'widgets',
1598          'site-icon',
1599          'l10n',
1600          'install',
1601          'wp-color-picker',
1602          'customize-controls',
1603          'customize-widgets',
1604          'customize-nav-menus',
1605          'customize-preview',
1606          'login',
1607          'site-health',
1608          // Includes CSS.
1609          'buttons',
1610          'admin-bar',
1611          'wp-auth-check',
1612          'editor-buttons',
1613          'media-views',
1614          'wp-pointer',
1615          'wp-jquery-ui-dialog',
1616          // Package styles.
1617          'wp-reset-editor-styles',
1618          'wp-editor-classic-layout-styles',
1619          'wp-block-library-theme',
1620          'wp-edit-blocks',
1621          'wp-block-editor',
1622          'wp-block-library',
1623          'wp-block-directory',
1624          'wp-components',
1625          'wp-edit-post',
1626          'wp-editor',
1627          'wp-format-library',
1628          'wp-list-reusable-blocks',
1629          'wp-reusable-blocks',
1630          'wp-nux',
1631          // Deprecated CSS.
1632          'deprecated-media',
1633          'farbtastic',
1634      );
1635  
1636      foreach ( $rtl_styles as $rtl_style ) {
1637          $styles->add_data( $rtl_style, 'rtl', 'replace' );
1638          if ( $suffix ) {
1639              $styles->add_data( $rtl_style, 'suffix', $suffix );
1640          }
1641      }
1642  }
1643  
1644  /**
1645   * Reorder JavaScript scripts array to place prototype before jQuery.
1646   *
1647   * @since 2.3.1
1648   *
1649   * @param array $js_array JavaScript scripts array
1650   * @return array Reordered array, if needed.
1651   */
1652  function wp_prototype_before_jquery( $js_array ) {
1653      $prototype = array_search( 'prototype', $js_array, true );
1654  
1655      if ( false === $prototype ) {
1656          return $js_array;
1657      }
1658  
1659      $jquery = array_search( 'jquery', $js_array, true );
1660  
1661      if ( false === $jquery ) {
1662          return $js_array;
1663      }
1664  
1665      if ( $prototype < $jquery ) {
1666          return $js_array;
1667      }
1668  
1669      unset( $js_array[ $prototype ] );
1670  
1671      array_splice( $js_array, $jquery, 0, 'prototype' );
1672  
1673      return $js_array;
1674  }
1675  
1676  /**
1677   * Load localized data on print rather than initialization.
1678   *
1679   * These localizations require information that may not be loaded even by init.
1680   *
1681   * @since 2.5.0
1682   */
1683  function wp_just_in_time_script_localization() {
1684  
1685      wp_localize_script(
1686          'autosave',
1687          'autosaveL10n',
1688          array(
1689              'autosaveInterval' => AUTOSAVE_INTERVAL,
1690              'blog_id'          => get_current_blog_id(),
1691          )
1692      );
1693  
1694      wp_localize_script(
1695          'mce-view',
1696          'mceViewL10n',
1697          array(
1698              'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array(),
1699          )
1700      );
1701  
1702      wp_localize_script(
1703          'word-count',
1704          'wordCountL10n',
1705          array(
1706              /*
1707               * translators: If your word count is based on single characters (e.g. East Asian characters),
1708               * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
1709               * Do not translate into your own language.
1710               */
1711              'type'       => _x( 'words', 'Word count type. Do not translate!' ),
1712              'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array(),
1713          )
1714      );
1715  }
1716  
1717  /**
1718   * Localizes the jQuery UI datepicker.
1719   *
1720   * @since 4.6.0
1721   *
1722   * @link https://api.jqueryui.com/datepicker/#options
1723   *
1724   * @global WP_Locale $wp_locale WordPress date and time locale object.
1725   */
1726  function wp_localize_jquery_ui_datepicker() {
1727      global $wp_locale;
1728  
1729      if ( ! wp_script_is( 'jquery-ui-datepicker', 'enqueued' ) ) {
1730          return;
1731      }
1732  
1733      // Convert the PHP date format into jQuery UI's format.
1734      $datepicker_date_format = str_replace(
1735          array(
1736              'd',
1737              'j',
1738              'l',
1739              'z', // Day.
1740              'F',
1741              'M',
1742              'n',
1743              'm', // Month.
1744              'Y',
1745              'y', // Year.
1746          ),
1747          array(
1748              'dd',
1749              'd',
1750              'DD',
1751              'o',
1752              'MM',
1753              'M',
1754              'm',
1755              'mm',
1756              'yy',
1757              'y',
1758          ),
1759          get_option( 'date_format' )
1760      );
1761  
1762      $datepicker_defaults = wp_json_encode(
1763          array(
1764              'closeText'       => __( 'Close' ),
1765              'currentText'     => __( 'Today' ),
1766              'monthNames'      => array_values( $wp_locale->month ),
1767              'monthNamesShort' => array_values( $wp_locale->month_abbrev ),
1768              'nextText'        => __( 'Next' ),
1769              'prevText'        => __( 'Previous' ),
1770              'dayNames'        => array_values( $wp_locale->weekday ),
1771              'dayNamesShort'   => array_values( $wp_locale->weekday_abbrev ),
1772              'dayNamesMin'     => array_values( $wp_locale->weekday_initial ),
1773              'dateFormat'      => $datepicker_date_format,
1774              'firstDay'        => absint( get_option( 'start_of_week' ) ),
1775              'isRTL'           => $wp_locale->is_rtl(),
1776          )
1777      );
1778  
1779      wp_add_inline_script( 'jquery-ui-datepicker', "jQuery(document).ready(function(jQuery){jQuery.datepicker.setDefaults({$datepicker_defaults});});" );
1780  }
1781  
1782  /**
1783   * Localizes community events data that needs to be passed to dashboard.js.
1784   *
1785   * @since 4.8.0
1786   */
1787  function wp_localize_community_events() {
1788      if ( ! wp_script_is( 'dashboard' ) ) {
1789          return;
1790      }
1791  
1792      require_once  ABSPATH . 'wp-admin/includes/class-wp-community-events.php';
1793  
1794      $user_id            = get_current_user_id();
1795      $saved_location     = get_user_option( 'community-events-location', $user_id );
1796      $saved_ip_address   = isset( $saved_location['ip'] ) ? $saved_location['ip'] : false;
1797      $current_ip_address = WP_Community_Events::get_unsafe_client_ip();
1798  
1799      /*
1800       * If the user's location is based on their IP address, then update their
1801       * location when their IP address changes. This allows them to see events
1802       * in their current city when travelling. Otherwise, they would always be
1803       * shown events in the city where they were when they first loaded the
1804       * Dashboard, which could have been months or years ago.
1805       */
1806      if ( $saved_ip_address && $current_ip_address && $current_ip_address !== $saved_ip_address ) {
1807          $saved_location['ip'] = $current_ip_address;
1808          update_user_meta( $user_id, 'community-events-location', $saved_location );
1809      }
1810  
1811      $events_client = new WP_Community_Events( $user_id, $saved_location );
1812  
1813      wp_localize_script(
1814          'dashboard',
1815          'communityEventsData',
1816          array(
1817              'nonce'       => wp_create_nonce( 'community_events' ),
1818              'cache'       => $events_client->get_cached_events(),
1819              'time_format' => get_option( 'time_format' ),
1820          )
1821      );
1822  }
1823  
1824  /**
1825   * Administration Screen CSS for changing the styles.
1826   *
1827   * If installing the 'wp-admin/' directory will be replaced with './'.
1828   *
1829   * The $_wp_admin_css_colors global manages the Administration Screens CSS
1830   * stylesheet that is loaded. The option that is set is 'admin_color' and is the
1831   * color and key for the array. The value for the color key is an object with
1832   * a 'url' parameter that has the URL path to the CSS file.
1833   *
1834   * The query from $src parameter will be appended to the URL that is given from
1835   * the $_wp_admin_css_colors array value URL.
1836   *
1837   * @since 2.6.0
1838   *
1839   * @global array $_wp_admin_css_colors
1840   *
1841   * @param string $src    Source URL.
1842   * @param string $handle Either 'colors' or 'colors-rtl'.
1843   * @return string|false URL path to CSS stylesheet for Administration Screens.
1844   */
1845  function wp_style_loader_src( $src, $handle ) {
1846      global $_wp_admin_css_colors;
1847  
1848      if ( wp_installing() ) {
1849          return preg_replace( '#^wp-admin/#', './', $src );
1850      }
1851  
1852      if ( 'colors' === $handle ) {
1853          $color = get_user_option( 'admin_color' );
1854  
1855          if ( empty( $color ) || ! isset( $_wp_admin_css_colors[ $color ] ) ) {
1856              $color = 'fresh';
1857          }
1858  
1859          $color = $_wp_admin_css_colors[ $color ];
1860          $url   = $color->url;
1861  
1862          if ( ! $url ) {
1863              return false;
1864          }
1865  
1866          $parsed = parse_url( $src );
1867          if ( isset( $parsed['query'] ) && $parsed['query'] ) {
1868              wp_parse_str( $parsed['query'], $qv );
1869              $url = add_query_arg( $qv, $url );
1870          }
1871  
1872          return $url;
1873      }
1874  
1875      return $src;
1876  }
1877  
1878  /**
1879   * Prints the script queue in the HTML head on admin pages.
1880   *
1881   * Postpones the scripts that were queued for the footer.
1882   * print_footer_scripts() is called in the footer to print these scripts.
1883   *
1884   * @since 2.8.0
1885   *
1886   * @see wp_print_scripts()
1887   *
1888   * @global bool $concatenate_scripts
1889   *
1890   * @return array
1891   */
1892  function print_head_scripts() {
1893      global $concatenate_scripts;
1894  
1895      if ( ! did_action( 'wp_print_scripts' ) ) {
1896          /** This action is documented in wp-includes/functions.wp-scripts.php */
1897          do_action( 'wp_print_scripts' );
1898      }
1899  
1900      $wp_scripts = wp_scripts();
1901  
1902      script_concat_settings();
1903      $wp_scripts->do_concat = $concatenate_scripts;
1904      $wp_scripts->do_head_items();
1905  
1906      /**
1907       * Filters whether to print the head scripts.
1908       *
1909       * @since 2.8.0
1910       *
1911       * @param bool $print Whether to print the head scripts. Default true.
1912       */
1913      if ( apply_filters( 'print_head_scripts', true ) ) {
1914          _print_scripts();
1915      }
1916  
1917      $wp_scripts->reset();
1918      return $wp_scripts->done;
1919  }
1920  
1921  /**
1922   * Prints the scripts that were queued for the footer or too late for the HTML head.
1923   *
1924   * @since 2.8.0
1925   *
1926   * @global WP_Scripts $wp_scripts
1927   * @global bool       $concatenate_scripts
1928   *
1929   * @return array
1930   */
1931  function print_footer_scripts() {
1932      global $wp_scripts, $concatenate_scripts;
1933  
1934      if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
1935          return array(); // No need to run if not instantiated.
1936      }
1937      script_concat_settings();
1938      $wp_scripts->do_concat = $concatenate_scripts;
1939      $wp_scripts->do_footer_items();
1940  
1941      /**
1942       * Filters whether to print the footer scripts.
1943       *
1944       * @since 2.8.0
1945       *
1946       * @param bool $print Whether to print the footer scripts. Default true.
1947       */
1948      if ( apply_filters( 'print_footer_scripts', true ) ) {
1949          _print_scripts();
1950      }
1951  
1952      $wp_scripts->reset();
1953      return $wp_scripts->done;
1954  }
1955  
1956  /**
1957   * Print scripts (internal use only)
1958   *
1959   * @ignore
1960   *
1961   * @global WP_Scripts $wp_scripts
1962   * @global bool       $compress_scripts
1963   */
1964  function _print_scripts() {
1965      global $wp_scripts, $compress_scripts;
1966  
1967      $zip = $compress_scripts ? 1 : 0;
1968      if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) {
1969          $zip = 'gzip';
1970      }
1971  
1972      $concat    = trim( $wp_scripts->concat, ', ' );
1973      $type_attr = current_theme_supports( 'html5', 'script' ) ? '' : " type='text/javascript'";
1974  
1975      if ( $concat ) {
1976          if ( ! empty( $wp_scripts->print_code ) ) {
1977              echo "\n<script{$type_attr}>\n";
1978              echo "/* <![CDATA[ */\n"; // Not needed in HTML 5.
1979              echo $wp_scripts->print_code;
1980              echo "/* ]]> */\n";
1981              echo "</script>\n";
1982          }
1983  
1984          $concat       = str_split( $concat, 128 );
1985          $concatenated = '';
1986  
1987          foreach ( $concat as $key => $chunk ) {
1988              $concatenated .= "&load%5Bchunk_{$key}%5D={$chunk}";
1989          }
1990  
1991          $src = $wp_scripts->base_url . "/wp-admin/load-scripts.php?c={$zip}" . $concatenated . '&ver=' . $wp_scripts->default_version;
1992          echo "<script{$type_attr} src='" . esc_attr( $src ) . "'></script>\n";
1993      }
1994  
1995      if ( ! empty( $wp_scripts->print_html ) ) {
1996          echo $wp_scripts->print_html;
1997      }
1998  }
1999  
2000  /**
2001   * Prints the script queue in the HTML head on the front end.
2002   *
2003   * Postpones the scripts that were queued for the footer.
2004   * wp_print_footer_scripts() is called in the footer to print these scripts.
2005   *
2006   * @since 2.8.0
2007   *
2008   * @global WP_Scripts $wp_scripts
2009   *
2010   * @return array
2011   */
2012  function wp_print_head_scripts() {
2013      if ( ! did_action( 'wp_print_scripts' ) ) {
2014          /** This action is documented in wp-includes/functions.wp-scripts.php */
2015          do_action( 'wp_print_scripts' );
2016      }
2017  
2018      global $wp_scripts;
2019  
2020      if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
2021          return array(); // No need to run if nothing is queued.
2022      }
2023      return print_head_scripts();
2024  }
2025  
2026  /**
2027   * Private, for use in *_footer_scripts hooks
2028   *
2029   * @since 3.3.0
2030   */
2031  function _wp_footer_scripts() {
2032      print_late_styles();
2033      print_footer_scripts();
2034  }
2035  
2036  /**
2037   * Hooks to print the scripts and styles in the footer.
2038   *
2039   * @since 2.8.0
2040   */
2041  function wp_print_footer_scripts() {
2042      /**
2043       * Fires when footer scripts are printed.
2044       *
2045       * @since 2.8.0
2046       */
2047      do_action( 'wp_print_footer_scripts' );
2048  }
2049  
2050  /**
2051   * Wrapper for do_action( 'wp_enqueue_scripts' ).
2052   *
2053   * Allows plugins to queue scripts for the front end using wp_enqueue_script().
2054   * Runs first in wp_head() where all is_home(), is_page(), etc. functions are available.
2055   *
2056   * @since 2.8.0
2057   */
2058  function wp_enqueue_scripts() {
2059      /**
2060       * Fires when scripts and styles are enqueued.
2061       *
2062       * @since 2.8.0
2063       */
2064      do_action( 'wp_enqueue_scripts' );
2065  }
2066  
2067  /**
2068   * Prints the styles queue in the HTML head on admin pages.
2069   *
2070   * @since 2.8.0
2071   *
2072   * @global bool $concatenate_scripts
2073   *
2074   * @return array
2075   */
2076  function print_admin_styles() {
2077      global $concatenate_scripts;
2078  
2079      $wp_styles = wp_styles();
2080  
2081      script_concat_settings();
2082      $wp_styles->do_concat = $concatenate_scripts;
2083      $wp_styles->do_items( false );
2084  
2085      /**
2086       * Filters whether to print the admin styles.
2087       *
2088       * @since 2.8.0
2089       *
2090       * @param bool $print Whether to print the admin styles. Default true.
2091       */
2092      if ( apply_filters( 'print_admin_styles', true ) ) {
2093          _print_styles();
2094      }
2095  
2096      $wp_styles->reset();
2097      return $wp_styles->done;
2098  }
2099  
2100  /**
2101   * Prints the styles that were queued too late for the HTML head.
2102   *
2103   * @since 3.3.0
2104   *
2105   * @global WP_Styles $wp_styles
2106   * @global bool      $concatenate_scripts
2107   *
2108   * @return array|void
2109   */
2110  function print_late_styles() {
2111      global $wp_styles, $concatenate_scripts;
2112  
2113      if ( ! ( $wp_styles instanceof WP_Styles ) ) {
2114          return;
2115      }
2116  
2117      script_concat_settings();
2118      $wp_styles->do_concat = $concatenate_scripts;
2119      $wp_styles->do_footer_items();
2120  
2121      /**
2122       * Filters whether to print the styles queued too late for the HTML head.
2123       *
2124       * @since 3.3.0
2125       *
2126       * @param bool $print Whether to print the 'late' styles. Default true.
2127       */
2128      if ( apply_filters( 'print_late_styles', true ) ) {
2129          _print_styles();
2130      }
2131  
2132      $wp_styles->reset();
2133      return $wp_styles->done;
2134  }
2135  
2136  /**
2137   * Print styles (internal use only)
2138   *
2139   * @ignore
2140   * @since 3.3.0
2141   *
2142   * @global bool $compress_css
2143   */
2144  function _print_styles() {
2145      global $compress_css;
2146  
2147      $wp_styles = wp_styles();
2148  
2149      $zip = $compress_css ? 1 : 0;
2150      if ( $zip && defined( 'ENFORCE_GZIP' ) && ENFORCE_GZIP ) {
2151          $zip = 'gzip';
2152      }
2153  
2154      $concat    = trim( $wp_styles->concat, ', ' );
2155      $type_attr = current_theme_supports( 'html5', 'style' ) ? '' : ' type="text/css"';
2156  
2157      if ( $concat ) {
2158          $dir = $wp_styles->text_direction;
2159          $ver = $wp_styles->default_version;
2160  
2161          $concat       = str_split( $concat, 128 );
2162          $concatenated = '';
2163  
2164          foreach ( $concat as $key => $chunk ) {
2165              $concatenated .= "&load%5Bchunk_{$key}%5D={$chunk}";
2166          }
2167  
2168          $href = $wp_styles->base_url . "/wp-admin/load-styles.php?c={$zip}&dir={$dir}" . $concatenated . '&ver=' . $ver;
2169          echo "<link rel='stylesheet' href='" . esc_attr( $href ) . "'{$type_attr} media='all' />\n";
2170  
2171          if ( ! empty( $wp_styles->print_code ) ) {
2172              echo "<style{$type_attr}>\n";
2173              echo $wp_styles->print_code;
2174              echo "\n</style>\n";
2175          }
2176      }
2177  
2178      if ( ! empty( $wp_styles->print_html ) ) {
2179          echo $wp_styles->print_html;
2180      }
2181  }
2182  
2183  /**
2184   * Determine the concatenation and compression settings for scripts and styles.
2185   *
2186   * @since 2.8.0
2187   *
2188   * @global bool $concatenate_scripts
2189   * @global bool $compress_scripts
2190   * @global bool $compress_css
2191   */
2192  function script_concat_settings() {
2193      global $concatenate_scripts, $compress_scripts, $compress_css;
2194  
2195      $compressed_output = ( ini_get( 'zlib.output_compression' ) || 'ob_gzhandler' === ini_get( 'output_handler' ) );
2196  
2197      if ( ! isset( $concatenate_scripts ) ) {
2198          $concatenate_scripts = defined( 'CONCATENATE_SCRIPTS' ) ? CONCATENATE_SCRIPTS : true;
2199          if ( ( ! is_admin() && ! did_action( 'login_init' ) ) || ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ) {
2200              $concatenate_scripts = false;
2201          }
2202      }
2203  
2204      if ( ! isset( $compress_scripts ) ) {
2205          $compress_scripts = defined( 'COMPRESS_SCRIPTS' ) ? COMPRESS_SCRIPTS : true;
2206          if ( $compress_scripts && ( ! get_site_option( 'can_compress_scripts' ) || $compressed_output ) ) {
2207              $compress_scripts = false;
2208          }
2209      }
2210  
2211      if ( ! isset( $compress_css ) ) {
2212          $compress_css = defined( 'COMPRESS_CSS' ) ? COMPRESS_CSS : true;
2213          if ( $compress_css && ( ! get_site_option( 'can_compress_scripts' ) || $compressed_output ) ) {
2214              $compress_css = false;
2215          }
2216      }
2217  }
2218  
2219  /**
2220   * Handles the enqueueing of block scripts and styles that are common to both
2221   * the editor and the front-end.
2222   *
2223   * @since 5.0.0
2224   *
2225   * @global WP_Screen $current_screen WordPress current screen object.
2226   */
2227  function wp_common_block_scripts_and_styles() {
2228      if ( is_admin() && ! wp_should_load_block_editor_scripts_and_styles() ) {
2229          return;
2230      }
2231  
2232      wp_enqueue_style( 'wp-block-library' );
2233  
2234      if ( current_theme_supports( 'wp-block-styles' ) ) {
2235          wp_enqueue_style( 'wp-block-library-theme' );
2236      }
2237  
2238      /**
2239       * Fires after enqueuing block assets for both editor and front-end.
2240       *
2241       * Call `add_action` on any hook before 'wp_enqueue_scripts'.
2242       *
2243       * In the function call you supply, simply use `wp_enqueue_script` and
2244       * `wp_enqueue_style` to add your functionality to the Gutenberg editor.
2245       *
2246       * @since 5.0.0
2247       */
2248      do_action( 'enqueue_block_assets' );
2249  }
2250  
2251  /**
2252   * Enqueues the global styles defined via theme.json.
2253   *
2254   * @since 5.8.0
2255   *
2256   * @return void
2257   */
2258  function wp_enqueue_global_styles() {
2259      if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
2260          return;
2261      }
2262  
2263      $can_use_cache = (
2264          ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) &&
2265          ( ! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG ) &&
2266          ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) &&
2267          ! is_admin()
2268      );
2269  
2270      $stylesheet = null;
2271      if ( $can_use_cache ) {
2272          $cache = get_transient( 'global_styles' );
2273          if ( $cache ) {
2274              $stylesheet = $cache;
2275          }
2276      }
2277  
2278      if ( null === $stylesheet ) {
2279          $settings   = get_default_block_editor_settings();
2280          $theme_json = WP_Theme_JSON_Resolver::get_merged_data( $settings );
2281          $stylesheet = $theme_json->get_stylesheet();
2282  
2283          if ( $can_use_cache ) {
2284              set_transient( 'global_styles', $stylesheet, MINUTE_IN_SECONDS );
2285          }
2286      }
2287  
2288      if ( empty( $stylesheet ) ) {
2289          return;
2290      }
2291  
2292      wp_register_style( 'global-styles', false, array(), true, true );
2293      wp_add_inline_style( 'global-styles', $stylesheet );
2294      wp_enqueue_style( 'global-styles' );
2295  }
2296  
2297  /**
2298   * Checks if the editor scripts and styles for all registered block types
2299   * should be enqueued on the current screen.
2300   *
2301   * @since 5.6.0
2302   *
2303   * @return bool Whether scripts and styles should be enqueued.
2304   */
2305  function wp_should_load_block_editor_scripts_and_styles() {
2306      global $current_screen;
2307  
2308      $is_block_editor_screen = ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor();
2309  
2310      /**
2311       * Filters the flag that decides whether or not block editor scripts and styles
2312       * are going to be enqueued on the current screen.
2313       *
2314       * @since 5.6.0
2315       *
2316       * @param bool $is_block_editor_screen Current value of the flag.
2317       */
2318      return apply_filters( 'should_load_block_editor_scripts_and_styles', $is_block_editor_screen );
2319  }
2320  
2321  /**
2322   * Checks whether separate assets should be loaded for core blocks on-render.
2323   *
2324   * @since 5.8.0
2325   *
2326   * @return bool Whether separate assets will be loaded.
2327   */
2328  function wp_should_load_separate_core_block_assets() {
2329      if ( is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
2330          return false;
2331      }
2332  
2333      /**
2334       * Filters the flag that decides whether separate scripts and styles
2335       * will be loaded for core blocks on-render.
2336       *
2337       * @since 5.8.0
2338       *
2339       * @param bool $load_separate_assets Whether separate assets will be loaded.
2340       *                                   Default false.
2341       */
2342      return apply_filters( 'should_load_separate_core_block_assets', false );
2343  }
2344  
2345  /**
2346   * Enqueues registered block scripts and styles, depending on current rendered
2347   * context (only enqueuing editor scripts while in context of the editor).
2348   *
2349   * @since 5.0.0
2350   *
2351   * @global WP_Screen $current_screen WordPress current screen object.
2352   */
2353  function wp_enqueue_registered_block_scripts_and_styles() {
2354      global $current_screen;
2355  
2356      if ( wp_should_load_separate_core_block_assets() ) {
2357          return;
2358      }
2359  
2360      $load_editor_scripts = is_admin() && wp_should_load_block_editor_scripts_and_styles();
2361  
2362      $block_registry = WP_Block_Type_Registry::get_instance();
2363      foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
2364          // Front-end styles.
2365          if ( ! empty( $block_type->style ) ) {
2366              wp_enqueue_style( $block_type->style );
2367          }
2368  
2369          // Front-end script.
2370          if ( ! empty( $block_type->script ) ) {
2371              wp_enqueue_script( $block_type->script );
2372          }
2373  
2374          // Editor styles.
2375          if ( $load_editor_scripts && ! empty( $block_type->editor_style ) ) {
2376              wp_enqueue_style( $block_type->editor_style );
2377          }
2378  
2379          // Editor script.
2380          if ( $load_editor_scripts && ! empty( $block_type->editor_script ) ) {
2381              wp_enqueue_script( $block_type->editor_script );
2382          }
2383      }
2384  }
2385  
2386  /**
2387   * Function responsible for enqueuing the styles required for block styles functionality on the editor and on the frontend.
2388   *
2389   * @since 5.3.0
2390   */
2391  function enqueue_block_styles_assets() {
2392      $block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
2393  
2394      foreach ( $block_styles as $styles ) {
2395          foreach ( $styles as $style_properties ) {
2396              if ( isset( $style_properties['style_handle'] ) ) {
2397                  wp_enqueue_style( $style_properties['style_handle'] );
2398              }
2399              if ( isset( $style_properties['inline_style'] ) ) {
2400                  wp_add_inline_style( 'wp-block-library', $style_properties['inline_style'] );
2401              }
2402          }
2403      }
2404  }
2405  
2406  /**
2407   * Function responsible for enqueuing the assets required for block styles functionality on the editor.
2408   *
2409   * @since 5.3.0
2410   */
2411  function enqueue_editor_block_styles_assets() {
2412      $block_styles = WP_Block_Styles_Registry::get_instance()->get_all_registered();
2413  
2414      $register_script_lines = array( '( function() {' );
2415      foreach ( $block_styles as $block_name => $styles ) {
2416          foreach ( $styles as $style_properties ) {
2417              $block_style = array(
2418                  'name'  => $style_properties['name'],
2419                  'label' => $style_properties['label'],
2420              );
2421              if ( isset( $style_properties['is_default'] ) ) {
2422                  $block_style['isDefault'] = $style_properties['is_default'];
2423              }
2424              $register_script_lines[] = sprintf(
2425                  '    wp.blocks.registerBlockStyle( \'%s\', %s );',
2426                  $block_name,
2427                  wp_json_encode( $block_style )
2428              );
2429          }
2430      }
2431      $register_script_lines[] = '} )();';
2432      $inline_script           = implode( "\n", $register_script_lines );
2433  
2434      wp_register_script( 'wp-block-styles', false, array( 'wp-blocks' ), true, true );
2435      wp_add_inline_script( 'wp-block-styles', $inline_script );
2436      wp_enqueue_script( 'wp-block-styles' );
2437  }
2438  
2439  /**
2440   * Enqueues the assets required for the block directory within the block editor.
2441   *
2442   * @since 5.5.0
2443   */
2444  function wp_enqueue_editor_block_directory_assets() {
2445      wp_enqueue_script( 'wp-block-directory' );
2446      wp_enqueue_style( 'wp-block-directory' );
2447  }
2448  
2449  /**
2450   * Enqueues the assets required for the format library within the block editor.
2451   *
2452   * @since 5.8.0
2453   */
2454  function wp_enqueue_editor_format_library_assets() {
2455      wp_enqueue_script( 'wp-format-library' );
2456      wp_enqueue_style( 'wp-format-library' );
2457  }
2458  
2459  /**
2460   * Sanitizes an attributes array into an attributes string to be placed inside a `<script>` tag.
2461   *
2462   * Automatically injects type attribute if needed.
2463   * Used by {@see wp_get_script_tag()} and {@see wp_get_inline_script_tag()}.
2464   *
2465   * @since 5.7.0
2466   *
2467   * @param array $attributes Key-value pairs representing `<script>` tag attributes.
2468   * @return string String made of sanitized `<script>` tag attributes.
2469   */
2470  function wp_sanitize_script_attributes( $attributes ) {
2471      $html5_script_support = ! is_admin() && ! current_theme_supports( 'html5', 'script' );
2472      $attributes_string    = '';
2473  
2474      // If HTML5 script tag is supported, only the attribute name is added
2475      // to $attributes_string for entries with a boolean value, and that are true.
2476      foreach ( $attributes as $attribute_name => $attribute_value ) {
2477          if ( is_bool( $attribute_value ) ) {
2478              if ( $attribute_value ) {
2479                  $attributes_string .= $html5_script_support ? sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_name ) ) : ' ' . esc_attr( $attribute_name );
2480              }
2481          } else {
2482              $attributes_string .= sprintf( ' %1$s="%2$s"', esc_attr( $attribute_name ), esc_attr( $attribute_value ) );
2483          }
2484      }
2485  
2486      return $attributes_string;
2487  }
2488  
2489  /**
2490   * Formats `<script>` loader tags.
2491   *
2492   * It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
2493   * Automatically injects type attribute if needed.
2494   *
2495   * @since 5.7.0
2496   *
2497   * @param array $attributes Key-value pairs representing `<script>` tag attributes.
2498   * @return string String containing `<script>` opening and closing tags.
2499   */
2500  function wp_get_script_tag( $attributes ) {
2501      if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
2502          $attributes['type'] = 'text/javascript';
2503      }
2504      /**
2505       * Filters attributes to be added to a script tag.
2506       *
2507       * @since 5.7.0
2508       *
2509       * @param array $attributes Key-value pairs representing `<script>` tag attributes.
2510       *                          Only the attribute name is added to the `<script>` tag for
2511       *                          entries with a boolean value, and that are true.
2512       */
2513      $attributes = apply_filters( 'wp_script_attributes', $attributes );
2514  
2515      return sprintf( "<script%s></script>\n", wp_sanitize_script_attributes( $attributes ) );
2516  }
2517  
2518  /**
2519   * Prints formatted `<script>` loader tag.
2520   *
2521   * It is possible to inject attributes in the `<script>` tag via the  {@see 'wp_script_attributes'}  filter.
2522   * Automatically injects type attribute if needed.
2523   *
2524   * @since 5.7.0
2525   *
2526   * @param array $attributes Key-value pairs representing `<script>` tag attributes.
2527   */
2528  function wp_print_script_tag( $attributes ) {
2529      echo wp_get_script_tag( $attributes );
2530  }
2531  
2532  /**
2533   * Wraps inline JavaScript in `<script>` tag.
2534   *
2535   * It is possible to inject attributes in the `<script>` tag via the  {@see 'wp_script_attributes'}  filter.
2536   * Automatically injects type attribute if needed.
2537   *
2538   * @since 5.7.0
2539   *
2540   * @param string $javascript Inline JavaScript code.
2541   * @param array  $attributes  Optional. Key-value pairs representing `<script>` tag attributes.
2542   * @return string String containing inline JavaScript code wrapped around `<script>` tag.
2543   */
2544  function wp_get_inline_script_tag( $javascript, $attributes = array() ) {
2545      if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
2546          $attributes['type'] = 'text/javascript';
2547      }
2548      /**
2549       * Filters attributes to be added to a script tag.
2550       *
2551       * @since 5.7.0
2552       *
2553       * @param array $attributes Key-value pairs representing `<script>` tag attributes.
2554       *                          Only the attribute name is added to the `<script>` tag for
2555       *                          entries with a boolean value, and that are true.
2556       */
2557      $attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $javascript );
2558  
2559      $javascript = "\n" . trim( $javascript, "\n\r " ) . "\n";
2560  
2561      return sprintf( "<script%s>%s</script>\n", wp_sanitize_script_attributes( $attributes ), $javascript );
2562  }
2563  
2564  /**
2565   * Prints inline JavaScript wrapped in `<script>` tag.
2566   *
2567   * It is possible to inject attributes in the `<script>` tag via the  {@see 'wp_script_attributes'}  filter.
2568   * Automatically injects type attribute if needed.
2569   *
2570   * @since 5.7.0
2571   *
2572   * @param string $javascript Inline JavaScript code.
2573   * @param array  $attributes Optional. Key-value pairs representing `<script>` tag attributes.
2574   */
2575  function wp_print_inline_script_tag( $javascript, $attributes = array() ) {
2576      echo wp_get_inline_script_tag( $javascript, $attributes );
2577  }
2578  
2579  /**
2580   * Allows small styles to be inlined.
2581   *
2582   * This improves performance and sustainability, and is opt-in. Stylesheets can opt in
2583   * by adding `path` data using `wp_style_add_data`, and defining the file's absolute path:
2584   *
2585   *     wp_style_add_data( $style_handle, 'path', $file_path );
2586   *
2587   * @since 5.8.0
2588   *
2589   * @global WP_Styles $wp_styles
2590   */
2591  function wp_maybe_inline_styles() {
2592      global $wp_styles;
2593  
2594      $total_inline_limit = 20000;
2595      /**
2596       * The maximum size of inlined styles in bytes.
2597       *
2598       * @since 5.8.0
2599       *
2600       * @param int $total_inline_limit The file-size threshold, in bytes. Defaults to 20000.
2601       */
2602      $total_inline_limit = apply_filters( 'styles_inline_size_limit', $total_inline_limit );
2603  
2604      $styles = array();
2605  
2606      // Build an array of styles that have a path defined.
2607      foreach ( $wp_styles->queue as $handle ) {
2608          if ( wp_styles()->get_data( $handle, 'path' ) && file_exists( $wp_styles->registered[ $handle ]->extra['path'] ) ) {
2609              $styles[] = array(
2610                  'handle' => $handle,
2611                  'path'   => $wp_styles->registered[ $handle ]->extra['path'],
2612                  'size'   => filesize( $wp_styles->registered[ $handle ]->extra['path'] ),
2613              );
2614          }
2615      }
2616  
2617      if ( ! empty( $styles ) ) {
2618          // Reorder styles array based on size.
2619          usort(
2620              $styles,
2621              function( $a, $b ) {
2622                  return ( $a['size'] <= $b['size'] ) ? -1 : 1;
2623              }
2624          );
2625  
2626          /*
2627           * The total inlined size.
2628           *
2629           * On each iteration of the loop, if a style gets added inline the value of this var increases
2630           * to reflect the total size of inlined styles.
2631           */
2632          $total_inline_size = 0;
2633  
2634          // Loop styles.
2635          foreach ( $styles as $style ) {
2636  
2637              // Size check. Since styles are ordered by size, we can break the loop.
2638              if ( $total_inline_size + $style['size'] > $total_inline_limit ) {
2639                  break;
2640              }
2641  
2642              // Get the styles if we don't already have them.
2643              $style['css'] = file_get_contents( $style['path'] );
2644  
2645              // Set `src` to `false` and add styles inline.
2646              $wp_styles->registered[ $style['handle'] ]->src = false;
2647              if ( empty( $wp_styles->registered[ $style['handle'] ]->extra['after'] ) ) {
2648                  $wp_styles->registered[ $style['handle'] ]->extra['after'] = array();
2649              }
2650              array_unshift( $wp_styles->registered[ $style['handle'] ]->extra['after'], $style['css'] );
2651  
2652              // Add the styles size to the $total_inline_size var.
2653              $total_inline_size += (int) $style['size'];
2654          }
2655      }
2656  }
2657  
2658  /**
2659   * Inject the block editor assets that need to be loaded into the editor's iframe as an inline script.
2660   *
2661   * @since 5.8.0
2662   */
2663  function wp_add_iframed_editor_assets_html() {
2664      $script_handles = array();
2665      $style_handles  = array(
2666          'wp-block-editor',
2667          'wp-block-library',
2668          'wp-block-library-theme',
2669          'wp-edit-blocks',
2670      );
2671  
2672      $block_registry = WP_Block_Type_Registry::get_instance();
2673  
2674      foreach ( $block_registry->get_all_registered() as $block_type ) {
2675          if ( ! empty( $block_type->style ) ) {
2676              $style_handles[] = $block_type->style;
2677          }
2678  
2679          if ( ! empty( $block_type->editor_style ) ) {
2680              $style_handles[] = $block_type->editor_style;
2681          }
2682  
2683          if ( ! empty( $block_type->script ) ) {
2684              $script_handles[] = $block_type->script;
2685          }
2686      }
2687  
2688      $style_handles = array_unique( $style_handles );
2689      $done          = wp_styles()->done;
2690  
2691      ob_start();
2692  
2693      wp_styles()->done = array();
2694      wp_styles()->do_items( $style_handles );
2695      wp_styles()->done = $done;
2696  
2697      $styles = ob_get_clean();
2698  
2699      $script_handles = array_unique( $script_handles );
2700      $done           = wp_scripts()->done;
2701  
2702      ob_start();
2703  
2704      wp_scripts()->done = array();
2705      wp_scripts()->do_items( $script_handles );
2706      wp_scripts()->done = $done;
2707  
2708      $scripts = ob_get_clean();
2709  
2710      $editor_assets = wp_json_encode(
2711          array(
2712              'styles'  => $styles,
2713              'scripts' => $scripts,
2714          )
2715      );
2716  
2717      echo "<script>window.__editorAssets = $editor_assets</script>";
2718  }


Generated : Sat Jun 12 08:20:02 2021 Cross-referenced by PHPXref