[ Index ]

PHP Cross Reference of WordPress

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


Generated: Wed Jan 29 01:00:05 2020 Cross-referenced by PHPXref 0.7.1