* WordPress scripts and styles default loader.
* Several constants are used to manage the loading, concatenating and compression of scripts and CSS:
* define('SCRIPT_DEBUG', true); loads the development (non-minified) versions of all scripts and CSS, and disables compression and concatenation,
* define('CONCATENATE_SCRIPTS', false); disables compression and concatenation of scripts and CSS,
* define('COMPRESS_SCRIPTS', false); disables compression of scripts,
* define('COMPRESS_CSS', false); disables compression of CSS,
* define('ENFORCE_GZIP', true); forces gzip for compression (default is deflate).
* The globals $concatenate_scripts, $compress_scripts and $compress_css can be set by plugins
* to temporarily override the above settings. Also a compression test is run once and the result is saved
* as option 'can_compress_scripts' (0/1). The test will run again if that option is deleted.
/** WordPress Dependency Class */
require ABSPATH . WPINC . '/class-wp-dependency.php';
/** WordPress Dependencies Class */
require ABSPATH . WPINC . '/class.wp-dependencies.php';
/** WordPress Scripts Class */
require ABSPATH . WPINC . '/class.wp-scripts.php';
/** WordPress Scripts Functions */
require ABSPATH . WPINC . '/functions.wp-scripts.php';
/** WordPress Styles Class */
require ABSPATH . WPINC . '/class.wp-styles.php';
/** WordPress Styles Functions */
require ABSPATH . WPINC . '/functions.wp-styles.php';
* Registers TinyMCE scripts.
* @param WP_Scripts $scripts WP_Scripts object.
* @param bool $force_uncompressed Whether to forcibly prevent gzip compression. Default false.
function wp_register_tinymce_scripts( $scripts, $force_uncompressed = false ) {
global $tinymce_version, $concatenate_scripts, $compress_scripts;
$suffix = wp_scripts_get_suffix();
$dev_suffix = wp_scripts_get_suffix( 'dev' );
script_concat_settings();
$compressed = $compress_scripts && $concatenate_scripts && isset( $_SERVER['HTTP_ACCEPT_ENCODING'] )
&& false !== stripos( $_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip' ) && ! $force_uncompressed;
// Load tinymce.js when running from /src, otherwise load wp-tinymce.js.gz (in production)
// or tinymce.min.js (when SCRIPT_DEBUG is true).
$scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . 'wp-tinymce.js', array(), $tinymce_version );
$scripts->add( 'wp-tinymce-root', includes_url( 'js/tinymce/' ) . "tinymce$dev_suffix.js", array(), $tinymce_version );
$scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . "plugins/compat3x/plugin$dev_suffix.js", array( 'wp-tinymce-root' ), $tinymce_version );
$scripts->add( 'wp-tinymce-lists', includes_url( "js/tinymce/plugins/lists/plugin$suffix.js" ), array( 'wp-tinymce' ), $tinymce_version );
* Registers all the WordPress vendor scripts that are in the standardized
* `js/dist/vendor/` location.
* For the order of `$scripts->add` see `wp_default_scripts`.
* @param WP_Scripts $scripts WP_Scripts object.
function wp_default_packages_vendor( $scripts ) {
$suffix = wp_scripts_get_suffix();
'react' => array( 'wp-polyfill' ),
'react-dom' => array( 'react' ),
'wp-polyfill-node-contains',
'wp-polyfill-element-closest',
'wp-polyfill-object-fit',
$vendor_scripts_versions = array(
'react-dom' => '16.13.1',
'wp-polyfill-fetch' => '3.0.0',
'wp-polyfill-formdata' => '3.0.12',
'wp-polyfill-node-contains' => '3.42.0',
'wp-polyfill-url' => '3.6.4',
'wp-polyfill-dom-rect' => '3.42.0',
'wp-polyfill-element-closest' => '2.0.2',
'wp-polyfill-object-fit' => '2.3.4',
'wp-polyfill' => '7.4.4',
foreach ( $vendor_scripts as $handle => $dependencies ) {
if ( is_string( $dependencies ) ) {
$path = "/wp-includes/js/dist/vendor/$handle$suffix.js";
$version = $vendor_scripts_versions[ $handle ];
$scripts->add( $handle, $path, $dependencies, $version, 1 );
$scripts->add( 'wp-polyfill', null, array( 'wp-polyfill' ) );
did_action( 'init' ) && $scripts->add_inline_script(
'\'fetch\' in window' => 'wp-polyfill-fetch',
'document.contains' => 'wp-polyfill-node-contains',
'window.DOMRect' => 'wp-polyfill-dom-rect',
'window.URL && window.URL.prototype && window.URLSearchParams' => 'wp-polyfill-url',
'window.FormData && window.FormData.prototype.keys' => 'wp-polyfill-formdata',
'Element.prototype.matches && Element.prototype.closest' => 'wp-polyfill-element-closest',
'\'objectFit\' in document.documentElement.style' => 'wp-polyfill-object-fit',
did_action( 'init' ) && $scripts->add_inline_script( 'lodash', 'window.lodash = _.noConflict();' );
did_action( 'init' ) && $scripts->add_inline_script(
"moment.updateLocale( '%s', %s );",
'months' => array_values( $wp_locale->month ),
'monthsShort' => array_values( $wp_locale->month_abbrev ),
'weekdays' => array_values( $wp_locale->weekday ),
'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ),
'dow' => (int) get_option( 'start_of_week', 0 ),
'longDateFormat' => array(
'LT' => get_option( 'time_format', __( 'g:i a', 'default' ) ),
'LL' => get_option( 'date_format', __( 'F j, Y', 'default' ) ),
'LLL' => __( 'F j, Y g:i a', 'default' ),
* Returns contents of an inline script used in appending polyfill scripts for
* browsers which fail the provided tests. The provided array is a mapping from
* a condition to verify feature support to its polyfill script handle.
* @param WP_Scripts $scripts WP_Scripts object.
* @param array $tests Features to detect.
* @return string Conditional polyfill inline script.
function wp_get_script_polyfill( $scripts, $tests ) {
foreach ( $tests as $test => $handle ) {
if ( ! array_key_exists( $handle, $scripts->registered ) ) {
$src = $scripts->registered[ $handle ]->src;
$ver = $scripts->registered[ $handle ]->ver;
if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $scripts->content_url && 0 === strpos( $src, $scripts->content_url ) ) ) {
$src = $scripts->base_url . $src;
$src = add_query_arg( 'ver', $ver, $src );
/** This filter is documented in wp-includes/class.wp-scripts.php */
$src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
// Test presence of feature...
'( ' . $test . ' ) || ' .
* ...appending polyfill on any failures. Cautious viewers may balk
* at the `document.write`. Its caveat of synchronous mid-stream
* blocking write is exactly the behavior we need though.
'document.write( \'<script src="' .
'"></scr\' + \'ipt>\' );'
* Registers all the WordPress packages scripts that are in the standardized
* For the order of `$scripts->add` see `wp_default_scripts`.
* @param WP_Scripts $scripts WP_Scripts object.
function wp_default_packages_scripts( $scripts ) {
$suffix = wp_scripts_get_suffix();
// Expects multidimensional array like:
// 'a11y.js' => array('dependencies' => array(...), 'version' => '...'),
// 'annotations.js' => array('dependencies' => array(...), 'version' => '...'),
// 'api-fetch.js' => array(...
$assets = include ABSPATH . WPINC . '/assets/script-loader-packages.php';
foreach ( $assets as $package_name => $package_data ) {
$basename = basename( $package_name, '.js' );
$handle = 'wp-' . $basename;
$path = "/wp-includes/js/dist/{$basename}{$suffix}.js";
if ( ! empty( $package_data['dependencies'] ) ) {
$dependencies = $package_data['dependencies'];
// Add dependencies that cannot be detected and generated by build tools.
array_push( $dependencies, 'editor' );
array_push( $dependencies, 'media-models', 'media-views', 'postbox', 'wp-dom-ready' );
$scripts->add( $handle, $path, $dependencies, $package_data['version'], 1 );
if ( in_array( 'wp-i18n', $dependencies, true ) ) {
$scripts->set_translations( $handle );
* Manually set the text direction localization after wp-i18n is printed.
* This ensures that wp.i18n.isRTL() returns true in RTL languages.
* We cannot use $scripts->set_translations( 'wp-i18n' ) to do this
* because WordPress prints a script's translations *before* the script,
* which means, in the case of wp-i18n, that wp.i18n.setLocaleData()
* is called before wp.i18n is defined.
if ( 'wp-i18n' === $handle ) {
$ltr = _x( 'ltr', 'text direction', 'default' );
$script = sprintf( "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ '%s' ] } );", $ltr );
$scripts->add_inline_script( $handle, $script, 'after' );
* Adds inline scripts required for the WordPress JavaScript packages.
* @param WP_Scripts $scripts WP_Scripts object.
function wp_default_packages_inline_scripts( $scripts ) {
if ( isset( $scripts->registered['wp-api-fetch'] ) ) {
$scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
$scripts->add_inline_script(
'wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );',
esc_url_raw( get_rest_url() )
$scripts->add_inline_script(
'wp.apiFetch.nonceMiddleware = wp.apiFetch.createNonceMiddleware( "%s" );',
( wp_installing() && ! is_multisite() ) ? '' : wp_create_nonce( 'wp_rest' )
'wp.apiFetch.use( wp.apiFetch.nonceMiddleware );',
'wp.apiFetch.use( wp.apiFetch.mediaUploadMiddleware );',
'wp.apiFetch.nonceEndpoint = "%s";',
admin_url( 'admin-ajax.php?action=rest-nonce' )
$scripts->add_inline_script(
' var userId = ' . get_current_user_ID() . ';',
' var storageKey = "WP_DATA_USER_" + userId;',
' .use( wp.data.plugins.persistence, { storageKey: storageKey } );',
' wp.data.plugins.persistence.__unstableMigrate( { storageKey: storageKey } );',
// Calculate the timezone abbr (EDT, PST) if possible.
$timezone_string = get_option( 'timezone_string', 'UTC' );
if ( ! empty( $timezone_string ) ) {
$timezone_date = new DateTime( null, new DateTimeZone( $timezone_string ) );
$timezone_abbr = $timezone_date->format( 'T' );
$scripts->add_inline_script(
'wp.date.setSettings( %s );',
'locale' => get_user_locale(),
'months' => array_values( $wp_locale->month ),
'monthsShort' => array_values( $wp_locale->month_abbrev ),
'weekdays' => array_values( $wp_locale->weekday ),
'weekdaysShort' => array_values( $wp_locale->weekday_abbrev ),
'meridiem' => (object) $wp_locale->meridiem,
/* translators: %s: Duration. */
'future' => __( '%s from now' ),
/* translators: %s: Duration. */
'past' => __( '%s ago' ),
/* translators: Time format, see https://www.php.net/manual/datetime.format.php */
'time' => get_option( 'time_format', __( 'g:i a' ) ),
/* translators: Date format, see https://www.php.net/manual/datetime.format.php */
'date' => get_option( 'date_format', __( 'F j, Y' ) ),
/* translators: Date/Time format, see https://www.php.net/manual/datetime.format.php */
'datetime' => __( 'F j, Y g:i a' ),
/* translators: Abbreviated date/time format, see https://www.php.net/manual/datetime.format.php */
'datetimeAbbreviated' => __( 'M j, Y g:i a' ),
'offset' => get_option( 'gmt_offset', 0 ),
'string' => $timezone_string,
'abbr' => $timezone_abbr,
// Loading the old editor and its config to ensure the classic block works as expected.
$scripts->add_inline_script(
'window.wp.oldEditor = window.wp.editor;',
* Adds inline scripts required for the TinyMCE in the block editor.
* These TinyMCE init settings are used to extend and override the default settings
* from `_WP_Editors::default_settings()` for the Classic block.
* @global WP_Scripts $wp_scripts
function wp_tinymce_inline_scripts() {
/** This filter is documented in wp-includes/class-wp-editor.php */
$editor_settings = apply_filters( 'wp_editor_settings', array( 'tinymce' => true ), 'classic-block' );
$tinymce_plugins = array(
/** This filter is documented in wp-includes/class-wp-editor.php */
$tinymce_plugins = apply_filters( 'tiny_mce_plugins', $tinymce_plugins, 'classic-block' );
$tinymce_plugins = array_unique( $tinymce_plugins );
$disable_captions = false;
// Runs after `tiny_mce_plugins` but before `mce_buttons`.
/** This filter is documented in wp-admin/includes/media.php */
if ( apply_filters( 'disable_captions', '' ) ) {
$disable_captions = true;
/** This filter is documented in wp-includes/class-wp-editor.php */
$toolbar1 = apply_filters( 'mce_buttons', $toolbar1, 'classic-block' );
/** This filter is documented in wp-includes/class-wp-editor.php */
$toolbar2 = apply_filters( 'mce_buttons_2', $toolbar2, 'classic-block' );
/** This filter is documented in wp-includes/class-wp-editor.php */
$toolbar3 = apply_filters( 'mce_buttons_3', array(), 'classic-block' );
/** This filter is documented in wp-includes/class-wp-editor.php */
$toolbar4 = apply_filters( 'mce_buttons_4', array(), 'classic-block' );
/** This filter is documented in wp-includes/class-wp-editor.php */
$external_plugins = apply_filters( 'mce_external_plugins', array(), 'classic-block' );
$tinymce_settings = array(
'plugins' => implode( ',', $tinymce_plugins ),
'toolbar1' => implode( ',', $toolbar1 ),
'toolbar2' => implode( ',', $toolbar2 ),
'toolbar3' => implode( ',', $toolbar3 ),
'toolbar4' => implode( ',', $toolbar4 ),
'external_plugins' => wp_json_encode( $external_plugins ),
'classic_block_editor' => true,