--- a/wp/wp-includes/script-loader.php Thu Sep 29 08:06:27 2022 +0200
+++ b/wp/wp-includes/script-loader.php Fri Sep 05 18:40:08 2025 +0200
@@ -20,16 +20,16 @@
require ABSPATH . WPINC . '/class-wp-dependency.php';
/** WordPress Dependencies Class */
-require ABSPATH . WPINC . '/class.wp-dependencies.php';
+require ABSPATH . WPINC . '/class-wp-dependencies.php';
/** WordPress Scripts Class */
-require ABSPATH . WPINC . '/class.wp-scripts.php';
+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';
+require ABSPATH . WPINC . '/class-wp-styles.php';
/** WordPress Styles Functions */
require ABSPATH . WPINC . '/functions.wp-styles.php';
@@ -57,8 +57,10 @@
$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).
+ /*
+ * Load tinymce.js when running from /src, otherwise load wp-tinymce.js.gz (in production)
+ * or tinymce.min.js (when SCRIPT_DEBUG is true).
+ */
if ( $compressed ) {
$scripts->add( 'wp-tinymce', includes_url( 'js/tinymce/' ) . 'wp-tinymce.js', array(), $tinymce_version );
} else {
@@ -87,35 +89,41 @@
$suffix = wp_scripts_get_suffix();
$vendor_scripts = array(
- 'react' => array( 'wp-polyfill' ),
- 'react-dom' => array( 'react' ),
+ 'react',
+ 'react-dom' => array( 'react' ),
+ 'react-jsx-runtime' => array( 'react' ),
'regenerator-runtime',
'moment',
'lodash',
'wp-polyfill-fetch',
'wp-polyfill-formdata',
+ 'wp-polyfill-importmap',
'wp-polyfill-node-contains',
'wp-polyfill-url',
'wp-polyfill-dom-rect',
'wp-polyfill-element-closest',
'wp-polyfill-object-fit',
- 'wp-polyfill' => array( 'regenerator-runtime' ),
+ 'wp-polyfill-inert',
+ 'wp-polyfill',
);
$vendor_scripts_versions = array(
- 'react' => '17.0.1',
- 'react-dom' => '17.0.1',
- 'regenerator-runtime' => '0.13.9',
+ 'react' => '18.3.1',
+ 'react-dom' => '18.3.1',
+ 'react-jsx-runtime' => '18.3.1',
+ 'regenerator-runtime' => '0.14.0',
'moment' => '2.29.4',
- 'lodash' => '4.17.19',
- 'wp-polyfill-fetch' => '3.6.2',
+ 'lodash' => '4.17.21',
+ 'wp-polyfill-fetch' => '3.6.17',
'wp-polyfill-formdata' => '4.0.10',
- 'wp-polyfill-node-contains' => '4.0.0',
+ 'wp-polyfill-node-contains' => '4.8.0',
'wp-polyfill-url' => '3.6.4',
- 'wp-polyfill-dom-rect' => '4.0.0',
- 'wp-polyfill-element-closest' => '2.0.2',
+ 'wp-polyfill-dom-rect' => '4.8.0',
+ 'wp-polyfill-element-closest' => '3.0.2',
'wp-polyfill-object-fit' => '2.3.5',
+ 'wp-polyfill-inert' => '3.1.2',
'wp-polyfill' => '3.15.0',
+ 'wp-polyfill-importmap' => '1.8.2',
);
foreach ( $vendor_scripts as $handle => $dependencies ) {
@@ -136,7 +144,7 @@
'moment',
sprintf(
"moment.updateLocale( '%s', %s );",
- get_user_locale(),
+ esc_js( get_user_locale() ),
wp_json_encode(
array(
'months' => array_values( $wp_locale->month ),
@@ -169,7 +177,7 @@
* @since 5.0.0
*
* @param WP_Scripts $scripts WP_Scripts object.
- * @param array $tests Features to detect.
+ * @param string[] $tests Features to detect.
* @return string Conditional polyfill inline script.
*/
function wp_get_script_polyfill( $scripts, $tests ) {
@@ -182,7 +190,7 @@
$src = $scripts->registered[ $handle ]->src;
$ver = $scripts->registered[ $handle ]->ver;
- if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $scripts->content_url && 0 === strpos( $src, $scripts->content_url ) ) ) {
+ if ( ! preg_match( '|^(https?:)?//|', $src ) && ! ( $scripts->content_url && str_starts_with( $src, $scripts->content_url ) ) ) {
$src = $scripts->base_url . $src;
}
@@ -190,7 +198,7 @@
$src = add_query_arg( 'ver', $ver, $src );
}
- /** This filter is documented in wp-includes/class.wp-scripts.php */
+ /** This filter is documented in wp-includes/class-wp-scripts.php */
$src = esc_url( apply_filters( 'script_loader_src', $src, $handle ) );
if ( ! $src ) {
@@ -227,6 +235,7 @@
if (
! defined( 'SCRIPT_DEBUG' ) || ! SCRIPT_DEBUG
|| empty( $scripts->registered['react'] )
+ || defined( 'WP_RUN_CORE_TESTS' )
) {
return;
}
@@ -264,8 +273,7 @@
* @param WP_Scripts $scripts WP_Scripts object.
*/
function wp_default_packages_scripts( $scripts ) {
- $suffix = wp_scripts_get_suffix();
-
+ $suffix = defined( 'WP_RUN_CORE_TESTS' ) ? '.min' : wp_scripts_get_suffix();
/*
* Expects multidimensional array like:
*
@@ -273,10 +281,10 @@
* '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' );
+ $assets = include ABSPATH . WPINC . "/assets/script-loader-packages{$suffix}.php";
+
+ foreach ( $assets as $file_name => $package_data ) {
+ $basename = str_replace( $suffix . '.js', '', basename( $file_name ) );
$handle = 'wp-' . $basename;
$path = "/wp-includes/js/dist/{$basename}{$suffix}.js";
@@ -294,6 +302,9 @@
case 'wp-edit-post':
array_push( $dependencies, 'media-models', 'media-views', 'postbox', 'wp-dom-ready' );
break;
+ case 'wp-preferences':
+ array_push( $dependencies, 'wp-preferences-persistence' );
+ break;
}
$scripts->add( $handle, $path, $dependencies, $package_data['version'], 1 );
@@ -322,13 +333,15 @@
* Adds inline scripts required for the WordPress JavaScript packages.
*
* @since 5.0.0
+ * @since 6.4.0 Added relative time strings for the `wp-date` inline script output.
*
* @global WP_Locale $wp_locale WordPress date and time locale object.
+ * @global wpdb $wpdb WordPress database abstraction object.
*
* @param WP_Scripts $scripts WP_Scripts object.
*/
function wp_default_packages_inline_scripts( $scripts ) {
- global $wp_locale;
+ global $wp_locale, $wpdb;
if ( isset( $scripts->registered['wp-api-fetch'] ) ) {
$scripts->registered['wp-api-fetch']->deps[] = 'wp-hooks';
@@ -337,7 +350,7 @@
'wp-api-fetch',
sprintf(
'wp.apiFetch.use( wp.apiFetch.createRootURLMiddleware( "%s" ) );',
- esc_url_raw( get_rest_url() )
+ sanitize_url( get_rest_url() )
),
'after'
);
@@ -360,6 +373,26 @@
),
'after'
);
+
+ $meta_key = $wpdb->get_blog_prefix() . 'persisted_preferences';
+ $user_id = get_current_user_id();
+ $preload_data = get_user_meta( $user_id, $meta_key, true );
+ $scripts->add_inline_script(
+ 'wp-preferences',
+ sprintf(
+ '( function() {
+ var serverData = %s;
+ var userId = "%d";
+ var persistenceLayer = wp.preferencesPersistence.__unstableCreatePersistenceLayer( serverData, userId );
+ var preferencesStore = wp.preferences.store;
+ wp.data.dispatch( preferencesStore ).setPersistenceLayer( persistenceLayer );
+ } ) ();',
+ wp_json_encode( $preload_data ),
+ $user_id
+ )
+ );
+
+ // Backwards compatibility - configure the old wp-data persistence system.
$scripts->add_inline_script(
'wp-data',
implode(
@@ -370,7 +403,6 @@
' var storageKey = "WP_DATA_USER_" + userId;',
' wp.data',
' .use( wp.data.plugins.persistence, { storageKey: storageKey } );',
- ' wp.data.plugins.persistence.__unstableMigrate( { storageKey: storageKey } );',
'} )();',
)
)
@@ -385,6 +417,8 @@
$timezone_abbr = $timezone_date->format( 'T' );
}
+ $gmt_offset = get_option( 'gmt_offset', 0 );
+
$scripts->add_inline_script(
'wp-date',
sprintf(
@@ -403,7 +437,32 @@
'future' => __( '%s from now' ),
/* translators: %s: Duration. */
'past' => __( '%s ago' ),
+ /* translators: One second from or to a particular datetime, e.g., "a second ago" or "a second from now". */
+ 's' => __( 'a second' ),
+ /* translators: %d: Duration in seconds from or to a particular datetime, e.g., "4 seconds ago" or "4 seconds from now". */
+ 'ss' => __( '%d seconds' ),
+ /* translators: One minute from or to a particular datetime, e.g., "a minute ago" or "a minute from now". */
+ 'm' => __( 'a minute' ),
+ /* translators: %d: Duration in minutes from or to a particular datetime, e.g., "4 minutes ago" or "4 minutes from now". */
+ 'mm' => __( '%d minutes' ),
+ /* translators: One hour from or to a particular datetime, e.g., "an hour ago" or "an hour from now". */
+ 'h' => __( 'an hour' ),
+ /* translators: %d: Duration in hours from or to a particular datetime, e.g., "4 hours ago" or "4 hours from now". */
+ 'hh' => __( '%d hours' ),
+ /* translators: One day from or to a particular datetime, e.g., "a day ago" or "a day from now". */
+ 'd' => __( 'a day' ),
+ /* translators: %d: Duration in days from or to a particular datetime, e.g., "4 days ago" or "4 days from now". */
+ 'dd' => __( '%d days' ),
+ /* translators: One month from or to a particular datetime, e.g., "a month ago" or "a month from now". */
+ 'M' => __( 'a month' ),
+ /* translators: %d: Duration in months from or to a particular datetime, e.g., "4 months ago" or "4 months from now". */
+ 'MM' => __( '%d months' ),
+ /* translators: One year from or to a particular datetime, e.g., "a year ago" or "a year from now". */
+ 'y' => __( 'a year' ),
+ /* translators: %d: Duration in years from or to a particular datetime, e.g., "4 years ago" or "4 years from now". */
+ 'yy' => __( '%d years' ),
),
+ 'startOfWeek' => (int) get_option( 'start_of_week', 0 ),
),
'formats' => array(
/* translators: Time format, see https://www.php.net/manual/datetime.format.php */
@@ -416,9 +475,10 @@
'datetimeAbbreviated' => __( 'M j, Y g:i a' ),
),
'timezone' => array(
- 'offset' => get_option( 'gmt_offset', 0 ),
- 'string' => $timezone_string,
- 'abbr' => $timezone_abbr,
+ 'offset' => (float) $gmt_offset,
+ 'offsetFormatted' => str_replace( array( '.25', '.5', '.75' ), array( ':15', ':30', ':45' ), (string) $gmt_offset ),
+ 'string' => $timezone_string,
+ 'abbr' => $timezone_abbr,
),
)
)
@@ -559,8 +619,10 @@
/** This filter is documented in wp-includes/class-wp-editor.php */
$tinymce_settings = apply_filters( 'tiny_mce_before_init', $tinymce_settings, 'classic-block' );
- // Do "by hand" translation from PHP array to js object.
- // Prevents breakage in some custom settings.
+ /*
+ * Do "by hand" translation from PHP array to js object.
+ * Prevents breakage in some custom settings.
+ */
$init_obj = '';
foreach ( $tinymce_settings as $key => $value ) {
if ( is_bool( $value ) ) {
@@ -625,6 +687,11 @@
// Include an unmodified $wp_version.
require ABSPATH . WPINC . '/version.php';
+ /*
+ * Note: str_contains() is not used here, as this file can be included
+ * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
+ * the polyfills from wp-includes/compat.php are not loaded.
+ */
$develop_src = false !== strpos( $wp_version, '-src' );
if ( ! defined( 'SCRIPT_DEBUG' ) ) {
@@ -732,7 +799,7 @@
$scripts->add( 'editor', "/wp-admin/js/editor$suffix.js", array( 'utils', 'jquery' ), false, 1 );
- $scripts->add( 'clipboard', "/wp-includes/js/clipboard$suffix.js", array(), '2.0.10', 1 );
+ $scripts->add( 'clipboard', "/wp-includes/js/clipboard$suffix.js", array(), '2.0.11', 1 );
$scripts->add( 'wp-ajax-response', "/wp-includes/js/wp-ajax-response$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 );
did_action( 'init' ) && $scripts->localize(
@@ -750,7 +817,7 @@
'wp-api-request',
'wpApiSettings',
array(
- 'root' => esc_url_raw( get_rest_url() ),
+ 'root' => sanitize_url( get_rest_url() ),
'nonce' => wp_installing() ? '' : wp_create_nonce( 'wp_rest' ),
'versionString' => 'wp/v2/',
)
@@ -780,6 +847,9 @@
$scripts->add( 'wp-lists', "/wp-includes/js/wp-lists$suffix.js", array( 'wp-ajax-response', 'jquery-color' ), false, 1 );
+ $scripts->add( 'site-icon', '/wp-admin/js/site-icon.js', array( 'jquery' ), false, 1 );
+ $scripts->set_translations( 'site-icon' );
+
// WordPress no longer uses or bundles Prototype or script.aculo.us. These are now pulled from an external source.
$scripts->add( 'prototype', 'https://ajax.googleapis.com/ajax/libs/prototype/1.7.1.0/prototype.js', array(), '1.7.1' );
$scripts->add( 'scriptaculous-root', 'https://ajax.googleapis.com/ajax/libs/scriptaculous/1.9.0/scriptaculous.js', array( 'prototype' ), '1.9.0' );
@@ -794,80 +864,72 @@
// Not used in core, replaced by Jcrop.js.
$scripts->add( 'cropper', '/wp-includes/js/crop/cropper.js', array( 'scriptaculous-dragdrop' ) );
- // jQuery.
- // The unminified jquery.js and jquery-migrate.js are included to facilitate debugging.
- $scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '3.6.0' );
- $scripts->add( 'jquery-core', "/wp-includes/js/jquery/jquery$suffix.js", array(), '3.6.0' );
- $scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '3.3.2' );
-
- // Full jQuery UI.
- // The build process in 1.12.1 has changed significantly.
- // In order to keep backwards compatibility, and to keep the optimized loading,
- // the source files were flattened and included with some modifications for AMD loading.
- // A notable change is that 'jquery-ui-core' now contains 'jquery-ui-position' and 'jquery-ui-widget'.
- $scripts->add( 'jquery-ui-core', "/wp-includes/js/jquery/ui/core$suffix.js", array( 'jquery' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-core', "/wp-includes/js/jquery/ui/effect$suffix.js", array( 'jquery' ), '1.13.1', 1 );
-
- $scripts->add( 'jquery-effects-blind', "/wp-includes/js/jquery/ui/effect-blind$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-bounce', "/wp-includes/js/jquery/ui/effect-bounce$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-clip', "/wp-includes/js/jquery/ui/effect-clip$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-drop', "/wp-includes/js/jquery/ui/effect-drop$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-explode', "/wp-includes/js/jquery/ui/effect-explode$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-fade', "/wp-includes/js/jquery/ui/effect-fade$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-fold', "/wp-includes/js/jquery/ui/effect-fold$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-highlight', "/wp-includes/js/jquery/ui/effect-highlight$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-puff', "/wp-includes/js/jquery/ui/effect-puff$suffix.js", array( 'jquery-effects-core', 'jquery-effects-scale' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-pulsate', "/wp-includes/js/jquery/ui/effect-pulsate$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-scale', "/wp-includes/js/jquery/ui/effect-scale$suffix.js", array( 'jquery-effects-core', 'jquery-effects-size' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-shake', "/wp-includes/js/jquery/ui/effect-shake$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-size', "/wp-includes/js/jquery/ui/effect-size$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-slide', "/wp-includes/js/jquery/ui/effect-slide$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-effects-transfer', "/wp-includes/js/jquery/ui/effect-transfer$suffix.js", array( 'jquery-effects-core' ), '1.13.1', 1 );
+ /*
+ * jQuery.
+ * The unminified jquery.js and jquery-migrate.js are included to facilitate debugging.
+ */
+ $scripts->add( 'jquery', false, array( 'jquery-core', 'jquery-migrate' ), '3.7.1' );
+ $scripts->add( 'jquery-core', "/wp-includes/js/jquery/jquery$suffix.js", array(), '3.7.1' );
+ $scripts->add( 'jquery-migrate', "/wp-includes/js/jquery/jquery-migrate$suffix.js", array(), '3.4.1' );
+
+ /*
+ * Full jQuery UI.
+ * The build process in 1.12.1 has changed significantly.
+ * In order to keep backwards compatibility, and to keep the optimized loading,
+ * the source files were flattened and included with some modifications for AMD loading.
+ * A notable change is that 'jquery-ui-core' now contains 'jquery-ui-position' and 'jquery-ui-widget'.
+ */
+ $scripts->add( 'jquery-ui-core', "/wp-includes/js/jquery/ui/core$suffix.js", array( 'jquery' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-core', "/wp-includes/js/jquery/ui/effect$suffix.js", array( 'jquery' ), '1.13.3', 1 );
+
+ $scripts->add( 'jquery-effects-blind', "/wp-includes/js/jquery/ui/effect-blind$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-bounce', "/wp-includes/js/jquery/ui/effect-bounce$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-clip', "/wp-includes/js/jquery/ui/effect-clip$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-drop', "/wp-includes/js/jquery/ui/effect-drop$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-explode', "/wp-includes/js/jquery/ui/effect-explode$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-fade', "/wp-includes/js/jquery/ui/effect-fade$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-fold', "/wp-includes/js/jquery/ui/effect-fold$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-highlight', "/wp-includes/js/jquery/ui/effect-highlight$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-puff', "/wp-includes/js/jquery/ui/effect-puff$suffix.js", array( 'jquery-effects-core', 'jquery-effects-scale' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-pulsate', "/wp-includes/js/jquery/ui/effect-pulsate$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-scale', "/wp-includes/js/jquery/ui/effect-scale$suffix.js", array( 'jquery-effects-core', 'jquery-effects-size' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-shake', "/wp-includes/js/jquery/ui/effect-shake$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-size', "/wp-includes/js/jquery/ui/effect-size$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-slide', "/wp-includes/js/jquery/ui/effect-slide$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-effects-transfer', "/wp-includes/js/jquery/ui/effect-transfer$suffix.js", array( 'jquery-effects-core' ), '1.13.3', 1 );
// Widgets
- $scripts->add( 'jquery-ui-accordion', "/wp-includes/js/jquery/ui/accordion$suffix.js", array( 'jquery-ui-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-autocomplete', "/wp-includes/js/jquery/ui/autocomplete$suffix.js", array( 'jquery-ui-menu', 'wp-a11y' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-button', "/wp-includes/js/jquery/ui/button$suffix.js", array( 'jquery-ui-core', 'jquery-ui-controlgroup', 'jquery-ui-checkboxradio' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-datepicker', "/wp-includes/js/jquery/ui/datepicker$suffix.js", array( 'jquery-ui-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog$suffix.js", array( 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-menu', "/wp-includes/js/jquery/ui/menu$suffix.js", array( 'jquery-ui-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-mouse', "/wp-includes/js/jquery/ui/mouse$suffix.js", array( 'jquery-ui-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-progressbar', "/wp-includes/js/jquery/ui/progressbar$suffix.js", array( 'jquery-ui-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-selectmenu', "/wp-includes/js/jquery/ui/selectmenu$suffix.js", array( 'jquery-ui-menu' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-slider', "/wp-includes/js/jquery/ui/slider$suffix.js", array( 'jquery-ui-mouse' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-spinner', "/wp-includes/js/jquery/ui/spinner$suffix.js", array( 'jquery-ui-button' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-tabs', "/wp-includes/js/jquery/ui/tabs$suffix.js", array( 'jquery-ui-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-tooltip', "/wp-includes/js/jquery/ui/tooltip$suffix.js", array( 'jquery-ui-core' ), '1.13.1', 1 );
+ $scripts->add( 'jquery-ui-accordion', "/wp-includes/js/jquery/ui/accordion$suffix.js", array( 'jquery-ui-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-autocomplete', "/wp-includes/js/jquery/ui/autocomplete$suffix.js", array( 'jquery-ui-menu', 'wp-a11y' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-button', "/wp-includes/js/jquery/ui/button$suffix.js", array( 'jquery-ui-core', 'jquery-ui-controlgroup', 'jquery-ui-checkboxradio' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-datepicker', "/wp-includes/js/jquery/ui/datepicker$suffix.js", array( 'jquery-ui-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-dialog', "/wp-includes/js/jquery/ui/dialog$suffix.js", array( 'jquery-ui-resizable', 'jquery-ui-draggable', 'jquery-ui-button' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-menu', "/wp-includes/js/jquery/ui/menu$suffix.js", array( 'jquery-ui-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-mouse', "/wp-includes/js/jquery/ui/mouse$suffix.js", array( 'jquery-ui-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-progressbar', "/wp-includes/js/jquery/ui/progressbar$suffix.js", array( 'jquery-ui-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-selectmenu', "/wp-includes/js/jquery/ui/selectmenu$suffix.js", array( 'jquery-ui-menu' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-slider', "/wp-includes/js/jquery/ui/slider$suffix.js", array( 'jquery-ui-mouse' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-spinner', "/wp-includes/js/jquery/ui/spinner$suffix.js", array( 'jquery-ui-button' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-tabs', "/wp-includes/js/jquery/ui/tabs$suffix.js", array( 'jquery-ui-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-tooltip', "/wp-includes/js/jquery/ui/tooltip$suffix.js", array( 'jquery-ui-core' ), '1.13.3', 1 );
// New in 1.12.1
- $scripts->add( 'jquery-ui-checkboxradio', "/wp-includes/js/jquery/ui/checkboxradio$suffix.js", array( 'jquery-ui-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-controlgroup', "/wp-includes/js/jquery/ui/controlgroup$suffix.js", array( 'jquery-ui-core' ), '1.13.1', 1 );
+ $scripts->add( 'jquery-ui-checkboxradio', "/wp-includes/js/jquery/ui/checkboxradio$suffix.js", array( 'jquery-ui-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-controlgroup', "/wp-includes/js/jquery/ui/controlgroup$suffix.js", array( 'jquery-ui-core' ), '1.13.3', 1 );
// Interactions
- $scripts->add( 'jquery-ui-draggable', "/wp-includes/js/jquery/ui/draggable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-droppable', "/wp-includes/js/jquery/ui/droppable$suffix.js", array( 'jquery-ui-draggable' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-resizable', "/wp-includes/js/jquery/ui/resizable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-selectable', "/wp-includes/js/jquery/ui/selectable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-sortable', "/wp-includes/js/jquery/ui/sortable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.1', 1 );
-
- // As of 1.12.1 `jquery-ui-position` and `jquery-ui-widget` are part of `jquery-ui-core`.
- // Listed here for back-compat.
- $scripts->add( 'jquery-ui-position', false, array( 'jquery-ui-core' ), '1.13.1', 1 );
- $scripts->add( 'jquery-ui-widget', false, array( 'jquery-ui-core' ), '1.13.1', 1 );
-
- // Strings for 'jquery-ui-autocomplete' live region messages.
- did_action( 'init' ) && $scripts->localize(
- 'jquery-ui-autocomplete',
- 'uiAutocompleteL10n',
- array(
- 'noResults' => __( 'No results found.' ),
- /* translators: Number of results found when using jQuery UI Autocomplete. */
- 'oneResult' => __( '1 result found. Use up and down arrow keys to navigate.' ),
- /* translators: %d: Number of results found when using jQuery UI Autocomplete. */
- 'manyResults' => __( '%d results found. Use up and down arrow keys to navigate.' ),
- 'itemSelected' => __( 'Item selected.' ),
- )
- );
+ $scripts->add( 'jquery-ui-draggable', "/wp-includes/js/jquery/ui/draggable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-droppable', "/wp-includes/js/jquery/ui/droppable$suffix.js", array( 'jquery-ui-draggable' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-resizable', "/wp-includes/js/jquery/ui/resizable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-selectable', "/wp-includes/js/jquery/ui/selectable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-sortable', "/wp-includes/js/jquery/ui/sortable$suffix.js", array( 'jquery-ui-mouse' ), '1.13.3', 1 );
+
+ /*
+ * As of 1.12.1 `jquery-ui-position` and `jquery-ui-widget` are part of `jquery-ui-core`.
+ * Listed here for back-compat.
+ */
+ $scripts->add( 'jquery-ui-position', false, array( 'jquery-ui-core' ), '1.13.3', 1 );
+ $scripts->add( 'jquery-ui-widget', false, array( 'jquery-ui-core' ), '1.13.3', 1 );
// Deprecated, not used in core, most functionality is included in jQuery 1.3.
$scripts->add( 'jquery-form', "/wp-includes/js/jquery/jquery.form$suffix.js", array( 'jquery' ), '4.3.0', 1 );
@@ -884,9 +946,11 @@
// Not used any more, registered for backward compatibility.
$scripts->add( 'suggest', "/wp-includes/js/jquery/suggest$suffix.js", array( 'jquery' ), '1.1-20110113', 1 );
- // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv.
- // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way.
- $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '4.1.4', 1 );
+ /*
+ * Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv.
+ * It sets jQuery as a dependency, as the theme may have been implicitly loading it this way.
+ */
+ $scripts->add( 'imagesloaded', '/wp-includes/js/imagesloaded.min.js', array(), '5.0.0', 1 );
$scripts->add( 'masonry', '/wp-includes/js/masonry.min.js', array( 'imagesloaded' ), '4.2.2', 1 );
$scripts->add( 'jquery-masonry', '/wp-includes/js/jquery/jquery.masonry.min.js', array( 'jquery', 'masonry' ), '3.1.2b', 1 );
@@ -964,12 +1028,13 @@
did_action( 'init' ) && $scripts->localize( 'swfupload-handlers', 'swfuploadL10n', $uploader_l10n );
$scripts->add( 'comment-reply', "/wp-includes/js/comment-reply$suffix.js", array(), false, 1 );
+ did_action( 'init' ) && $scripts->add_data( 'comment-reply', 'strategy', 'async' );
$scripts->add( 'json2', "/wp-includes/js/json2$suffix.js", array(), '2015-05-03' );
did_action( 'init' ) && $scripts->add_data( 'json2', 'conditional', 'lt IE 8' );
- $scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.13.3', 1 );
- $scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore', 'jquery' ), '1.4.1', 1 );
+ $scripts->add( 'underscore', "/wp-includes/js/underscore$dev_suffix.js", array(), '1.13.4', 1 );
+ $scripts->add( 'backbone', "/wp-includes/js/backbone$dev_suffix.js", array( 'underscore', 'jquery' ), '1.5.0', 1 );
$scripts->add( 'wp-util', "/wp-includes/js/wp-util$suffix.js", array( 'underscore', 'jquery' ), false, 1 );
did_action( 'init' ) && $scripts->localize(
@@ -988,8 +1053,8 @@
$scripts->add( 'imgareaselect', "/wp-includes/js/imgareaselect/jquery.imgareaselect$suffix.js", array( 'jquery' ), false, 1 );
- $scripts->add( 'mediaelement', false, array( 'jquery', 'mediaelement-core', 'mediaelement-migrate' ), '4.2.16', 1 );
- $scripts->add( 'mediaelement-core', "/wp-includes/js/mediaelement/mediaelement-and-player$suffix.js", array(), '4.2.16', 1 );
+ $scripts->add( 'mediaelement', false, array( 'jquery', 'mediaelement-core', 'mediaelement-migrate' ), '4.2.17', 1 );
+ $scripts->add( 'mediaelement-core', "/wp-includes/js/mediaelement/mediaelement-and-player$suffix.js", array(), '4.2.17', 1 );
$scripts->add( 'mediaelement-migrate', "/wp-includes/js/mediaelement/mediaelement-migrate$suffix.js", array(), false, 1 );
did_action( 'init' ) && $scripts->add_inline_script(
@@ -1079,12 +1144,16 @@
'before'
);
- $scripts->add( 'mediaelement-vimeo', '/wp-includes/js/mediaelement/renderers/vimeo.min.js', array( 'mediaelement' ), '4.2.16', 1 );
+ $scripts->add( 'mediaelement-vimeo', '/wp-includes/js/mediaelement/renderers/vimeo.min.js', array( 'mediaelement' ), '4.2.17', 1 );
$scripts->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.js", array( 'mediaelement' ), false, 1 );
$mejs_settings = array(
- 'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ),
- 'classPrefix' => 'mejs-',
- 'stretching' => 'responsive',
+ 'pluginPath' => includes_url( 'js/mediaelement/', 'relative' ),
+ 'classPrefix' => 'mejs-',
+ 'stretching' => 'responsive',
+ /** This filter is documented in wp-includes/media.php */
+ 'audioShortcodeLibrary' => apply_filters( 'wp_audio_shortcode_library', 'mediaelement' ),
+ /** This filter is documented in wp-includes/media.php */
+ 'videoShortcodeLibrary' => apply_filters( 'wp_video_shortcode_library', 'mediaelement' ),
);
did_action( 'init' ) && $scripts->localize(
'mediaelement',
@@ -1107,7 +1176,7 @@
$scripts->add( 'htmlhint', '/wp-includes/js/codemirror/htmlhint.js', array(), '0.9.14-xwp' );
$scripts->add( 'htmlhint-kses', '/wp-includes/js/codemirror/htmlhint-kses.js', array( 'htmlhint' ) );
$scripts->add( 'code-editor', "/wp-admin/js/code-editor$suffix.js", array( 'jquery', 'wp-codemirror', 'underscore' ) );
- $scripts->add( 'wp-theme-plugin-editor', "/wp-admin/js/theme-plugin-editor$suffix.js", array( 'common', 'wp-util', 'wp-sanitize', 'jquery', 'jquery-ui-core', 'wp-a11y', 'underscore' ) );
+ $scripts->add( 'wp-theme-plugin-editor', "/wp-admin/js/theme-plugin-editor$suffix.js", array( 'common', 'wp-util', 'wp-sanitize', 'jquery', 'jquery-ui-core', 'wp-a11y', 'underscore' ), false, 1 );
$scripts->set_translations( 'wp-theme-plugin-editor' );
$scripts->add( 'wp-playlist', "/wp-includes/js/mediaelement/wp-playlist$suffix.js", array( 'wp-util', 'backbone', 'mediaelement' ), false, 1 );
@@ -1136,6 +1205,9 @@
);
$scripts->set_translations( 'password-strength-meter' );
+ $scripts->add( 'password-toggle', "/wp-admin/js/password-toggle$suffix.js", array(), false, 1 );
+ $scripts->set_translations( 'password-toggle' );
+
$scripts->add( 'application-passwords', "/wp-admin/js/application-passwords$suffix.js", array( 'jquery', 'wp-util', 'wp-api-request', 'wp-date', 'wp-i18n', 'wp-hooks' ), false, 1 );
$scripts->set_translations( 'application-passwords' );
@@ -1160,7 +1232,8 @@
$scripts->add( 'admin-bar', "/wp-includes/js/admin-bar$suffix.js", array( 'hoverintent-js' ), false, 1 );
- $scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'jquery', 'wp-a11y' ), false, 1 );
+ $scripts->add( 'wplink', "/wp-includes/js/wplink$suffix.js", array( 'common', 'jquery', 'wp-a11y', 'wp-i18n' ), false, 1 );
+ $scripts->set_translations( 'wplink' );
did_action( 'init' ) && $scripts->localize(
'wplink',
'wpLinkL10n',
@@ -1263,8 +1336,8 @@
'invalidValue' => __( 'Invalid value.' ),
'blockThemeNotification' => sprintf(
/* translators: 1: Link to Site Editor documentation on HelpHub, 2: HTML button. */
- __( 'Hurray! Your theme supports Full Site Editing with blocks. <a href="%1$s">Tell me more</a>. %2$s' ),
- __( 'https://wordpress.org/support/article/site-editor/' ),
+ __( 'Hurray! Your theme supports site editing with blocks. <a href="%1$s">Tell me more</a>. %2$s' ),
+ __( 'https://wordpress.org/documentation/article/site-editor/' ),
sprintf(
'<button type="button" data-action="%1$s" class="button switch-to-editor">%2$s</button>',
esc_url( admin_url( 'site-editor.php' ) ),
@@ -1298,10 +1371,13 @@
)
);
- $scripts->add( 'wp-embed', "/wp-includes/js/wp-embed$suffix.js", array(), false, 1 );
-
- // To enqueue media-views or media-editor, call wp_enqueue_media().
- // Both rely on numerous settings, styles, and templates to operate correctly.
+ $scripts->add( 'wp-embed', "/wp-includes/js/wp-embed$suffix.js" );
+ did_action( 'init' ) && $scripts->add_data( 'wp-embed', 'strategy', 'defer' );
+
+ /*
+ * To enqueue media-views or media-editor, call wp_enqueue_media().
+ * Both rely on numerous settings, styles, and templates to operate correctly.
+ */
$scripts->add( 'media-views', "/wp-includes/js/media-views$suffix.js", array( 'utils', 'media-models', 'wp-plupload', 'jquery-ui-sortable', 'wp-mediaelement', 'wp-api-request', 'wp-a11y', 'clipboard' ), false, 1 );
$scripts->set_translations( 'media-views' );
@@ -1335,7 +1411,7 @@
$scripts->add( 'tags-box', "/wp-admin/js/tags-box$suffix.js", array( 'jquery', 'tags-suggest' ), false, 1 );
$scripts->set_translations( 'tags-box' );
- $scripts->add( 'tags-suggest', "/wp-admin/js/tags-suggest$suffix.js", array( 'jquery-ui-autocomplete', 'wp-a11y' ), false, 1 );
+ $scripts->add( 'tags-suggest', "/wp-admin/js/tags-suggest$suffix.js", array( 'common', 'jquery-ui-autocomplete', 'wp-a11y', 'wp-i18n' ), false, 1 );
$scripts->set_translations( 'tags-suggest' );
$scripts->add( 'post', "/wp-admin/js/post$suffix.js", array( 'suggest', 'wp-lists', 'postbox', 'tags-box', 'underscore', 'word-count', 'wp-a11y', 'wp-sanitize', 'clipboard' ), false, 1 );
@@ -1450,6 +1526,11 @@
require ABSPATH . WPINC . '/version.php';
if ( ! defined( 'SCRIPT_DEBUG' ) ) {
+ /*
+ * Note: str_contains() is not used here, as this file can be included
+ * via wp-admin/load-scripts.php or wp-admin/load-styles.php, in which case
+ * the polyfills from wp-includes/compat.php are not loaded.
+ */
define( 'SCRIPT_DEBUG', false !== strpos( $wp_version, '-src' ) );
}
@@ -1542,7 +1623,7 @@
// External libraries and friends.
$styles->add( 'imgareaselect', '/wp-includes/js/imgareaselect/imgareaselect.css', array(), '0.9.8' );
$styles->add( 'wp-jquery-ui-dialog', "/wp-includes/css/jquery-ui-dialog$suffix.css", array( 'dashicons' ) );
- $styles->add( 'mediaelement', '/wp-includes/js/mediaelement/mediaelementplayer-legacy.min.css', array(), '4.2.16' );
+ $styles->add( 'mediaelement', '/wp-includes/js/mediaelement/mediaelementplayer-legacy.min.css', array(), '4.2.17' );
$styles->add( 'wp-mediaelement', "/wp-includes/js/mediaelement/wp-mediaelement$suffix.css", array( 'mediaelement' ) );
$styles->add( 'thickbox', '/wp-includes/js/thickbox/thickbox.css', array( 'dashicons' ) );
$styles->add( 'wp-codemirror', '/wp-includes/js/codemirror/codemirror.min.css', array(), '5.29.1-alpha-ee20357' );
@@ -1583,23 +1664,39 @@
array()
);
+ $styles->add(
+ 'wp-block-editor-content',
+ "/wp-includes/css/dist/block-editor/content$suffix.css",
+ array( 'wp-components' )
+ );
+
$wp_edit_blocks_dependencies = array(
'wp-components',
'wp-editor',
- // This need to be added before the block library styles,
- // The block library styles override the "reset" styles.
+ /*
+ * This needs to be added before the block library styles,
+ * The block library styles override the "reset" styles.
+ */
'wp-reset-editor-styles',
'wp-block-library',
'wp-reusable-blocks',
+ 'wp-block-editor-content',
+ 'wp-patterns',
);
// Only load the default layout and margin styles for themes without theme.json file.
- if ( ! WP_Theme_JSON_Resolver::theme_has_support() ) {
+ if ( ! wp_theme_has_theme_json() ) {
$wp_edit_blocks_dependencies[] = 'wp-editor-classic-layout-styles';
}
- if ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 ) {
- // Include opinionated block styles if no $editor_styles are declared, so the editor never appears broken.
+ if (
+ current_theme_supports( 'wp-block-styles' ) &&
+ ( ! is_array( $editor_styles ) || count( $editor_styles ) === 0 )
+ ) {
+ /*
+ * Include opinionated block styles if the theme supports block styles and
+ * no $editor_styles are declared, so the editor never appears broken.
+ */
$wp_edit_blocks_dependencies[] = 'wp-block-library-theme';
}
@@ -1610,27 +1707,32 @@
);
$package_styles = array(
- 'block-editor' => array( 'wp-components' ),
+ 'block-editor' => array( 'wp-components', 'wp-preferences' ),
'block-library' => array(),
'block-directory' => array(),
'components' => array(),
+ 'commands' => array(),
'edit-post' => array(
'wp-components',
'wp-block-editor',
'wp-editor',
'wp-edit-blocks',
'wp-block-library',
- 'wp-nux',
+ 'wp-commands',
+ 'wp-preferences',
),
'editor' => array(
'wp-components',
'wp-block-editor',
- 'wp-nux',
'wp-reusable-blocks',
+ 'wp-patterns',
+ 'wp-preferences',
),
'format-library' => array(),
'list-reusable-blocks' => array( 'wp-components' ),
'reusable-blocks' => array( 'wp-components' ),
+ 'patterns' => array( 'wp-components' ),
+ 'preferences' => array( 'wp-components' ),
'nux' => array( 'wp-components' ),
'widgets' => array(
'wp-components',
@@ -1641,6 +1743,8 @@
'wp-edit-blocks',
'wp-block-library',
'wp-reusable-blocks',
+ 'wp-patterns',
+ 'wp-preferences',
),
'customize-widgets' => array(
'wp-widgets',
@@ -1648,11 +1752,15 @@
'wp-edit-blocks',
'wp-block-library',
'wp-reusable-blocks',
+ 'wp-patterns',
+ 'wp-preferences',
),
'edit-site' => array(
'wp-components',
'wp-block-editor',
'wp-edit-blocks',
+ 'wp-commands',
+ 'wp-preferences',
),
);
@@ -1708,6 +1816,7 @@
'wp-block-editor',
'wp-block-library',
'wp-block-directory',
+ 'wp-commands',
'wp-components',
'wp-customize-widgets',
'wp-edit-post',
@@ -1717,6 +1826,7 @@
'wp-format-library',
'wp-list-reusable-blocks',
'wp-reusable-blocks',
+ 'wp-patterns',
'wp-nux',
'wp-widgets',
// Deprecated CSS.
@@ -1737,8 +1847,8 @@
*
* @since 2.3.1
*
- * @param array $js_array JavaScript scripts array
- * @return array Reordered array, if needed.
+ * @param string[] $js_array JavaScript scripts array
+ * @return string[] Reordered array, if needed.
*/
function wp_prototype_before_jquery( $js_array ) {
$prototype = array_search( 'prototype', $js_array, true );
@@ -1770,6 +1880,8 @@
* These localizations require information that may not be loaded even by init.
*
* @since 2.5.0
+ *
+ * @global array $shortcode_tags
*/
function wp_just_in_time_script_localization() {
@@ -1794,12 +1906,7 @@
'word-count',
'wordCountL10n',
array(
- /*
- * translators: If your word count is based on single characters (e.g. East Asian characters),
- * enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
- * Do not translate into your own language.
- */
- 'type' => _x( 'words', 'Word count type. Do not translate!' ),
+ 'type' => wp_get_word_count_type(),
'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array(),
)
);
@@ -2323,20 +2430,8 @@
wp_enqueue_style( 'wp-block-library' );
- if ( current_theme_supports( 'wp-block-styles' ) ) {
- if ( wp_should_load_separate_core_block_assets() ) {
- $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? 'css' : 'min.css';
- $files = glob( __DIR__ . "/blocks/**/theme.$suffix" );
- foreach ( $files as $path ) {
- $block_name = basename( dirname( $path ) );
- if ( is_rtl() && file_exists( __DIR__ . "/blocks/$block_name/theme-rtl.$suffix" ) ) {
- $path = __DIR__ . "/blocks/$block_name/theme-rtl.$suffix";
- }
- wp_add_inline_style( "wp-block-{$block_name}", file_get_contents( $path ) );
- }
- } else {
- wp_enqueue_style( 'wp-block-library-theme' );
- }
+ if ( current_theme_supports( 'wp-block-styles' ) && ! wp_should_load_separate_core_block_assets() ) {
+ wp_enqueue_style( 'wp-block-library-theme' );
}
/**
@@ -2353,6 +2448,30 @@
}
/**
+ * Applies a filter to the list of style nodes that comes from WP_Theme_JSON::get_style_nodes().
+ *
+ * This particular filter removes all of the blocks from the array.
+ *
+ * We want WP_Theme_JSON to be ignorant of the implementation details of how the CSS is being used.
+ * This filter allows us to modify the output of WP_Theme_JSON depending on whether or not we are
+ * loading separate assets, without making the class aware of that detail.
+ *
+ * @since 6.1.0
+ *
+ * @param array $nodes The nodes to filter.
+ * @return array A filtered array of style nodes.
+ */
+function wp_filter_out_block_nodes( $nodes ) {
+ return array_filter(
+ $nodes,
+ static function ( $node ) {
+ return ! in_array( 'blocks', $node['path'], true );
+ },
+ ARRAY_FILTER_USE_BOTH
+ );
+}
+
+/**
* Enqueues the global styles defined via theme.json.
*
* @since 5.8.0
@@ -2376,42 +2495,45 @@
return;
}
+ /*
+ * If loading the CSS for each block separately, then load the theme.json CSS conditionally.
+ * This removes the CSS from the global-styles stylesheet and adds it to the inline CSS for each block.
+ * This filter must be registered before calling wp_get_global_stylesheet();
+ */
+ add_filter( 'wp_theme_json_get_style_nodes', 'wp_filter_out_block_nodes' );
+
$stylesheet = wp_get_global_stylesheet();
if ( empty( $stylesheet ) ) {
return;
}
- wp_register_style( 'global-styles', false, array(), true, true );
+ wp_register_style( 'global-styles', false );
wp_add_inline_style( 'global-styles', $stylesheet );
wp_enqueue_style( 'global-styles' );
+
+ // Add each block as an inline css.
+ wp_add_global_styles_for_blocks();
}
/**
- * Renders the SVG filters supplied by theme.json.
+ * Enqueues the global styles custom css defined via theme.json.
*
- * Note that this doesn't render the per-block user-defined
- * filters which are handled by wp_render_duotone_support,
- * but it should be rendered before the filtered content
- * in the body to satisfy Safari's rendering quirks.
- *
- * @since 5.9.1
+ * @since 6.2.0
*/
-function wp_global_styles_render_svg_filters() {
- /*
- * When calling via the in_admin_header action, we only want to render the
- * SVGs on block editor pages.
- */
- if (
- is_admin() &&
- ! get_current_screen()->is_block_editor()
- ) {
+function wp_enqueue_global_styles_custom_css() {
+ if ( ! wp_is_block_theme() ) {
return;
}
- $filters = wp_get_global_styles_svg_filters();
- if ( ! empty( $filters ) ) {
- echo $filters;
+ // Don't enqueue Customizer's custom CSS separately.
+ remove_action( 'wp_head', 'wp_custom_css_cb', 101 );
+
+ $custom_css = wp_get_custom_css();
+ $custom_css .= wp_get_global_styles_custom_css();
+
+ if ( ! empty( $custom_css ) ) {
+ wp_add_inline_style( 'global-styles', $custom_css );
}
}
@@ -2463,7 +2585,7 @@
* @return bool Whether separate assets will be loaded.
*/
function wp_should_load_separate_core_block_assets() {
- if ( is_admin() || is_feed() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
+ if ( is_admin() || is_feed() || wp_is_rest_endpoint() ) {
return false;
}
@@ -2496,28 +2618,30 @@
return;
}
- $load_editor_scripts = is_admin() && wp_should_load_block_editor_scripts_and_styles();
+ $load_editor_scripts_and_styles = is_admin() && wp_should_load_block_editor_scripts_and_styles();
$block_registry = WP_Block_Type_Registry::get_instance();
foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
- // Front-end styles.
- if ( ! empty( $block_type->style ) ) {
- wp_enqueue_style( $block_type->style );
+ // Front-end and editor styles.
+ foreach ( $block_type->style_handles as $style_handle ) {
+ wp_enqueue_style( $style_handle );
}
- // Front-end script.
- if ( ! empty( $block_type->script ) ) {
- wp_enqueue_script( $block_type->script );
+ // Front-end and editor scripts.
+ foreach ( $block_type->script_handles as $script_handle ) {
+ wp_enqueue_script( $script_handle );
}
- // Editor styles.
- if ( $load_editor_scripts && ! empty( $block_type->editor_style ) ) {
- wp_enqueue_style( $block_type->editor_style );
- }
-
- // Editor script.
- if ( $load_editor_scripts && ! empty( $block_type->editor_script ) ) {
- wp_enqueue_script( $block_type->editor_script );
+ if ( $load_editor_scripts_and_styles ) {
+ // Editor styles.
+ foreach ( $block_type->editor_style_handles as $editor_style_handle ) {
+ wp_enqueue_style( $editor_style_handle );
+ }
+
+ // Editor scripts.
+ foreach ( $block_type->editor_script_handles as $editor_script_handle ) {
+ wp_enqueue_script( $editor_script_handle );
+ }
}
}
}
@@ -2542,7 +2666,7 @@
if ( wp_should_load_separate_core_block_assets() ) {
add_filter(
'render_block',
- function( $html, $block ) use ( $block_name, $style_properties ) {
+ static function ( $html, $block ) use ( $block_name, $style_properties ) {
if ( $block['blockName'] === $block_name ) {
wp_enqueue_style( $style_properties['style_handle'] );
}
@@ -2604,7 +2728,7 @@
$register_script_lines[] = '} )();';
$inline_script = implode( "\n", $register_script_lines );
- wp_register_script( 'wp-block-styles', false, array( 'wp-blocks' ), true, true );
+ wp_register_script( 'wp-block-styles', false, array( 'wp-blocks' ), true, array( 'in_footer' => true ) );
wp_add_inline_script( 'wp-block-styles', $inline_script );
wp_enqueue_script( 'wp-block-styles' );
}
@@ -2644,8 +2768,10 @@
$html5_script_support = ! is_admin() && ! current_theme_supports( 'html5', 'script' );
$attributes_string = '';
- // If HTML5 script tag is supported, only the attribute name is added
- // to $attributes_string for entries with a boolean value, and that are true.
+ /*
+ * If HTML5 script tag is supported, only the attribute name is added
+ * to $attributes_string for entries with a boolean value, and that are true.
+ */
foreach ( $attributes as $attribute_name => $attribute_value ) {
if ( is_bool( $attribute_value ) ) {
if ( $attribute_value ) {
@@ -2672,7 +2798,11 @@
*/
function wp_get_script_tag( $attributes ) {
if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
- $attributes['type'] = 'text/javascript';
+ // Keep the type attribute as the first for legacy reasons (it has always been this way in core).
+ $attributes = array_merge(
+ array( 'type' => 'text/javascript' ),
+ $attributes
+ );
}
/**
* Filters attributes to be added to a script tag.
@@ -2703,21 +2833,79 @@
}
/**
- * Wraps inline JavaScript in `<script>` tag.
+ * Constructs an inline script tag.
*
* It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
* Automatically injects type attribute if needed.
*
* @since 5.7.0
*
- * @param string $javascript Inline JavaScript code.
+ * @param string $data Data for script tag: JavaScript, importmap, speculationrules, etc.
* @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes.
* @return string String containing inline JavaScript code wrapped around `<script>` tag.
*/
-function wp_get_inline_script_tag( $javascript, $attributes = array() ) {
- if ( ! isset( $attributes['type'] ) && ! is_admin() && ! current_theme_supports( 'html5', 'script' ) ) {
- $attributes['type'] = 'text/javascript';
+function wp_get_inline_script_tag( $data, $attributes = array() ) {
+ $is_html5 = current_theme_supports( 'html5', 'script' ) || is_admin();
+ if ( ! isset( $attributes['type'] ) && ! $is_html5 ) {
+ // Keep the type attribute as the first for legacy reasons (it has always been this way in core).
+ $attributes = array_merge(
+ array( 'type' => 'text/javascript' ),
+ $attributes
+ );
}
+
+ /*
+ * XHTML extracts the contents of the SCRIPT element and then the XML parser
+ * decodes character references and other syntax elements. This can lead to
+ * misinterpretation of the script contents or invalid XHTML documents.
+ *
+ * Wrapping the contents in a CDATA section instructs the XML parser not to
+ * transform the contents of the SCRIPT element before passing them to the
+ * JavaScript engine.
+ *
+ * Example:
+ *
+ * <script>console.log('…');</script>
+ *
+ * In an HTML document this would print "…" to the console,
+ * but in an XHTML document it would print "…" to the console.
+ *
+ * <script>console.log('An image is <img> in HTML');</script>
+ *
+ * In an HTML document this would print "An image is <img> in HTML",
+ * but it's an invalid XHTML document because it interprets the `<img>`
+ * as an empty tag missing its closing `/`.
+ *
+ * @see https://www.w3.org/TR/xhtml1/#h-4.8
+ */
+ if (
+ ! $is_html5 &&
+ (
+ ! isset( $attributes['type'] ) ||
+ 'module' === $attributes['type'] ||
+ str_contains( $attributes['type'], 'javascript' ) ||
+ str_contains( $attributes['type'], 'ecmascript' ) ||
+ str_contains( $attributes['type'], 'jscript' ) ||
+ str_contains( $attributes['type'], 'livescript' )
+ )
+ ) {
+ /*
+ * If the string `]]>` exists within the JavaScript it would break
+ * out of any wrapping CDATA section added here, so to start, it's
+ * necessary to escape that sequence which requires splitting the
+ * content into two CDATA sections wherever it's found.
+ *
+ * Note: it's only necessary to escape the closing `]]>` because
+ * an additional `<![CDATA[` leaves the contents unchanged.
+ */
+ $data = str_replace( ']]>', ']]]]><![CDATA[>', $data );
+
+ // Wrap the entire escaped script inside a CDATA section.
+ $data = sprintf( "/* <![CDATA[ */\n%s\n/* ]]> */", $data );
+ }
+
+ $data = "\n" . trim( $data, "\n\r " ) . "\n";
+
/**
* Filters attributes to be added to a script tag.
*
@@ -2726,28 +2914,26 @@
* @param array $attributes Key-value pairs representing `<script>` tag attributes.
* Only the attribute name is added to the `<script>` tag for
* entries with a boolean value, and that are true.
- * @param string $javascript Inline JavaScript code.
+ * @param string $data Inline data.
*/
- $attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $javascript );
-
- $javascript = "\n" . trim( $javascript, "\n\r " ) . "\n";
-
- return sprintf( "<script%s>%s</script>\n", wp_sanitize_script_attributes( $attributes ), $javascript );
+ $attributes = apply_filters( 'wp_inline_script_attributes', $attributes, $data );
+
+ return sprintf( "<script%s>%s</script>\n", wp_sanitize_script_attributes( $attributes ), $data );
}
/**
- * Prints inline JavaScript wrapped in `<script>` tag.
+ * Prints an inline script tag.
*
* It is possible to inject attributes in the `<script>` tag via the {@see 'wp_script_attributes'} filter.
* Automatically injects type attribute if needed.
*
* @since 5.7.0
*
- * @param string $javascript Inline JavaScript code.
+ * @param string $data Data for script tag: JavaScript, importmap, speculationrules, etc.
* @param array $attributes Optional. Key-value pairs representing `<script>` tag attributes.
*/
-function wp_print_inline_script_tag( $javascript, $attributes = array() ) {
- echo wp_get_inline_script_tag( $javascript, $attributes );
+function wp_print_inline_script_tag( $data, $attributes = array() ) {
+ echo wp_get_inline_script_tag( $data, $attributes );
}
/**
@@ -2779,12 +2965,21 @@
// Build an array of styles that have a path defined.
foreach ( $wp_styles->queue as $handle ) {
- if ( wp_styles()->get_data( $handle, 'path' ) && file_exists( $wp_styles->registered[ $handle ]->extra['path'] ) ) {
+ if ( ! isset( $wp_styles->registered[ $handle ] ) ) {
+ continue;
+ }
+ $src = $wp_styles->registered[ $handle ]->src;
+ $path = $wp_styles->get_data( $handle, 'path' );
+ if ( $path && $src ) {
+ $size = wp_filesize( $path );
+ if ( ! $size ) {
+ continue;
+ }
$styles[] = array(
'handle' => $handle,
- 'src' => $wp_styles->registered[ $handle ]->src,
- 'path' => $wp_styles->registered[ $handle ]->extra['path'],
- 'size' => filesize( $wp_styles->registered[ $handle ]->extra['path'] ),
+ 'src' => $src,
+ 'path' => $path,
+ 'size' => $size,
);
}
}
@@ -2793,7 +2988,7 @@
// Reorder styles array based on size.
usort(
$styles,
- static function( $a, $b ) {
+ static function ( $a, $b ) {
return ( $a['size'] <= $b['size'] ) ? -1 : 1;
}
);
@@ -2817,8 +3012,10 @@
// Get the styles if we don't already have them.
$style['css'] = file_get_contents( $style['path'] );
- // Check if the style contains relative URLs that need to be modified.
- // URLs relative to the stylesheet's path should be converted to relative to the site's root.
+ /*
+ * Check if the style contains relative URLs that need to be modified.
+ * URLs relative to the stylesheet's path should be converted to relative to the site's root.
+ */
$style['css'] = _wp_normalize_relative_css_links( $style['css'], $style['src'] );
// Set `src` to `false` and add styles inline.
@@ -2846,41 +3043,33 @@
* @return string The CSS with URLs made relative to the WordPress installation.
*/
function _wp_normalize_relative_css_links( $css, $stylesheet_url ) {
- $has_src_results = preg_match_all( '#url\s*\(\s*[\'"]?\s*([^\'"\)]+)#', $css, $src_results );
- if ( $has_src_results ) {
- // Loop through the URLs to find relative ones.
- foreach ( $src_results[1] as $src_index => $src_result ) {
- // Skip if this is an absolute URL.
- if ( 0 === strpos( $src_result, 'http' ) || 0 === strpos( $src_result, '//' ) ) {
- continue;
- }
-
- // Skip if the URL is an HTML ID.
- if ( str_starts_with( $src_result, '#' ) ) {
- continue;
- }
-
- // Skip if the URL is a data URI.
- if ( str_starts_with( $src_result, 'data:' ) ) {
- continue;
+ return preg_replace_callback(
+ '#(url\s*\(\s*[\'"]?\s*)([^\'"\)]+)#',
+ static function ( $matches ) use ( $stylesheet_url ) {
+ list( , $prefix, $url ) = $matches;
+
+ // Short-circuit if the URL does not require normalization.
+ if (
+ str_starts_with( $url, 'http:' ) ||
+ str_starts_with( $url, 'https:' ) ||
+ str_starts_with( $url, '//' ) ||
+ str_starts_with( $url, '#' ) ||
+ str_starts_with( $url, 'data:' )
+ ) {
+ return $matches[0];
}
// Build the absolute URL.
- $absolute_url = dirname( $stylesheet_url ) . '/' . $src_result;
+ $absolute_url = dirname( $stylesheet_url ) . '/' . $url;
$absolute_url = str_replace( '/./', '/', $absolute_url );
+
// Convert to URL related to the site root.
- $relative_url = wp_make_link_relative( $absolute_url );
-
- // Replace the URL in the CSS.
- $css = str_replace(
- $src_results[0][ $src_index ],
- str_replace( $src_result, $relative_url, $src_results[0][ $src_index ] ),
- $css
- );
- }
- }
-
- return $css;
+ $url = wp_make_link_relative( $absolute_url );
+
+ return $prefix . $url;
+ },
+ $css
+ );
}
/**
@@ -2889,27 +3078,26 @@
* @since 5.9.0
*/
function wp_enqueue_global_styles_css_custom_properties() {
- wp_register_style( 'global-styles-css-custom-properties', false, array(), true, true );
+ wp_register_style( 'global-styles-css-custom-properties', false );
wp_add_inline_style( 'global-styles-css-custom-properties', wp_get_global_stylesheet( array( 'variables' ) ) );
wp_enqueue_style( 'global-styles-css-custom-properties' );
}
/**
- * This function takes care of adding inline styles
- * in the proper place, depending on the theme in use.
+ * Hooks inline styles in the proper place, depending on the active theme.
*
* @since 5.9.1
+ * @since 6.1.0 Added the `$priority` parameter.
*
- * For block themes, it's loaded in the head.
- * For classic ones, it's loaded in the body
- * because the wp_head action happens before
- * the render_block.
+ * For block themes, styles are loaded in the head.
+ * For classic ones, styles are loaded in the body because the wp_head action happens before render_block.
*
* @link https://core.trac.wordpress.org/ticket/53494.
*
- * @param string $style String containing the CSS styles to be added.
+ * @param string $style String containing the CSS styles to be added.
+ * @param int $priority To set the priority for the add_action.
*/
-function wp_enqueue_block_support_styles( $style ) {
+function wp_enqueue_block_support_styles( $style, $priority = 10 ) {
$action_hook_name = 'wp_footer';
if ( wp_is_block_theme() ) {
$action_hook_name = 'wp_head';
@@ -2918,8 +3106,79 @@
$action_hook_name,
static function () use ( $style ) {
echo "<style>$style</style>\n";
+ },
+ $priority
+ );
+}
+
+/**
+ * Fetches, processes and compiles stored core styles, then combines and renders them to the page.
+ * Styles are stored via the style engine API.
+ *
+ * @link https://developer.wordpress.org/block-editor/reference-guides/packages/packages-style-engine/
+ *
+ * @since 6.1.0
+ *
+ * @param array $options {
+ * Optional. An array of options to pass to wp_style_engine_get_stylesheet_from_context().
+ * Default empty array.
+ *
+ * @type bool $optimize Whether to optimize the CSS output, e.g., combine rules.
+ * Default false.
+ * @type bool $prettify Whether to add new lines and indents to output.
+ * Default to whether the `SCRIPT_DEBUG` constant is defined.
+ * }
+ */
+function wp_enqueue_stored_styles( $options = array() ) {
+ $is_block_theme = wp_is_block_theme();
+ $is_classic_theme = ! $is_block_theme;
+
+ /*
+ * For block themes, this function prints stored styles in the header.
+ * For classic themes, in the footer.
+ */
+ if (
+ ( $is_block_theme && doing_action( 'wp_footer' ) ) ||
+ ( $is_classic_theme && doing_action( 'wp_enqueue_scripts' ) )
+ ) {
+ return;
+ }
+
+ $core_styles_keys = array( 'block-supports' );
+ $compiled_core_stylesheet = '';
+ $style_tag_id = 'core';
+ // Adds comment if code is prettified to identify core styles sections in debugging.
+ $should_prettify = isset( $options['prettify'] ) ? true === $options['prettify'] : defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG;
+ foreach ( $core_styles_keys as $style_key ) {
+ if ( $should_prettify ) {
+ $compiled_core_stylesheet .= "/**\n * Core styles: $style_key\n */\n";
}
- );
+ // Chains core store ids to signify what the styles contain.
+ $style_tag_id .= '-' . $style_key;
+ $compiled_core_stylesheet .= wp_style_engine_get_stylesheet_from_context( $style_key, $options );
+ }
+
+ // Combines Core styles.
+ if ( ! empty( $compiled_core_stylesheet ) ) {
+ wp_register_style( $style_tag_id, false );
+ wp_add_inline_style( $style_tag_id, $compiled_core_stylesheet );
+ wp_enqueue_style( $style_tag_id );
+ }
+
+ // Prints out any other stores registered by themes or otherwise.
+ $additional_stores = WP_Style_Engine_CSS_Rules_Store::get_stores();
+ foreach ( array_keys( $additional_stores ) as $store_name ) {
+ if ( in_array( $store_name, $core_styles_keys, true ) ) {
+ continue;
+ }
+ $styles = wp_style_engine_get_stylesheet_from_context( $store_name, $options );
+ if ( ! empty( $styles ) ) {
+ $key = "wp-style-engine-$store_name";
+ wp_register_style( $key, false );
+ wp_add_inline_style( $key, $styles );
+ wp_enqueue_style( $key );
+ }
+ }
}
/**
@@ -2932,7 +3191,16 @@
* @since 5.9.0
*
* @param string $block_name The block-name, including namespace.
- * @param array $args An array of arguments [handle,src,deps,ver,media].
+ * @param array $args {
+ * An array of arguments. See wp_register_style() for full information about each argument.
+ *
+ * @type string $handle The handle for the stylesheet.
+ * @type string|false $src The source URL of the stylesheet.
+ * @type string[] $deps Array of registered stylesheet handles this stylesheet depends on.
+ * @type string|bool|null $ver Stylesheet version number.
+ * @type string $media The media for which this stylesheet has been defined.
+ * @type string|null $path Absolute path to the stylesheet, so that it can potentially be inlined.
+ * }
*/
function wp_enqueue_block_style( $block_name, $args ) {
$args = wp_parse_args(
@@ -2954,7 +3222,7 @@
* is to ensure the content exists.
* @return string Block content.
*/
- $callback = static function( $content ) use ( $args ) {
+ $callback = static function ( $content ) use ( $args ) {
// Register the stylesheet.
if ( ! empty( $args['src'] ) ) {
wp_register_style( $args['handle'], $args['src'], $args['deps'], $args['ver'], $args['media'] );
@@ -2992,7 +3260,7 @@
* @param array $block The full block, including name and attributes.
* @return string Block content.
*/
- $callback_separate = static function( $content, $block ) use ( $block_name, $callback ) {
+ $callback_separate = static function ( $content, $block ) use ( $block_name, $callback ) {
if ( ! empty( $block['blockName'] ) && $block_name === $block['blockName'] ) {
return $callback( $content );
}
@@ -3028,502 +3296,109 @@
}
/**
- * Runs the theme.json webfonts handler.
+ * Loads classic theme styles on classic themes in the frontend.
*
- * Using `WP_Theme_JSON_Resolver`, it gets the fonts defined
- * in the `theme.json` for the current selection and style
- * variations, validates the font-face properties, generates
- * the '@font-face' style declarations, and then enqueues the
- * styles for both the editor and front-end.
+ * This is needed for backwards compatibility for button blocks specifically.
*
- * Design Notes:
- * This is not a public API, but rather an internal handler.
- * A future public Webfonts API will replace this stopgap code.
- *
- * This code design is intentional.
- * a. It hides the inner-workings.
- * b. It does not expose API ins or outs for consumption.
- * c. It only works with a theme's `theme.json`.
+ * @since 6.1.0
+ */
+function wp_enqueue_classic_theme_styles() {
+ if ( ! wp_theme_has_theme_json() ) {
+ $suffix = wp_scripts_get_suffix();
+ wp_register_style( 'classic-theme-styles', '/' . WPINC . "/css/classic-themes$suffix.css" );
+ wp_style_add_data( 'classic-theme-styles', 'path', ABSPATH . WPINC . "/css/classic-themes$suffix.css" );
+ wp_enqueue_style( 'classic-theme-styles' );
+ }
+}
+
+/**
+ * Loads classic theme styles on classic themes in the editor.
*
- * Why?
- * a. To avoid backwards-compatibility issues when
- * the Webfonts API is introduced in Core.
- * b. To make `fontFace` declarations in `theme.json` work.
+ * This is needed for backwards compatibility for button blocks specifically.
*
- * @link https://github.com/WordPress/gutenberg/issues/40472
+ * @since 6.1.0
*
- * @since 6.0.0
- * @access private
+ * @param array $editor_settings The array of editor settings.
+ * @return array A filtered array of editor settings.
*/
-function _wp_theme_json_webfonts_handler() {
- // Block themes are unavailable during installation.
- if ( wp_installing() ) {
- return;
+function wp_add_editor_classic_theme_styles( $editor_settings ) {
+ if ( wp_theme_has_theme_json() ) {
+ return $editor_settings;
}
- // Webfonts to be processed.
- $registered_webfonts = array();
-
- /**
- * Gets the webfonts from theme.json.
- *
- * @since 6.0.0
- *
- * @return array Array of defined webfonts.
+ $suffix = wp_scripts_get_suffix();
+ $classic_theme_styles = ABSPATH . WPINC . "/css/classic-themes$suffix.css";
+
+ /*
+ * This follows the pattern of get_block_editor_theme_styles,
+ * but we can't use get_block_editor_theme_styles directly as it
+ * only handles external files or theme files.
*/
- $fn_get_webfonts_from_theme_json = static function() {
- // Get settings from theme.json.
- $settings = WP_Theme_JSON_Resolver::get_merged_data()->get_settings();
-
- // If in the editor, add webfonts defined in variations.
- if ( is_admin() || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) ) {
- $variations = WP_Theme_JSON_Resolver::get_style_variations();
- foreach ( $variations as $variation ) {
- // Skip if fontFamilies are not defined in the variation.
- if ( empty( $variation['settings']['typography']['fontFamilies'] ) ) {
- continue;
- }
-
- // Initialize the array structure.
- if ( empty( $settings['typography'] ) ) {
- $settings['typography'] = array();
- }
- if ( empty( $settings['typography']['fontFamilies'] ) ) {
- $settings['typography']['fontFamilies'] = array();
- }
- if ( empty( $settings['typography']['fontFamilies']['theme'] ) ) {
- $settings['typography']['fontFamilies']['theme'] = array();
- }
-
- // Combine variations with settings. Remove duplicates.
- $settings['typography']['fontFamilies']['theme'] = array_merge( $settings['typography']['fontFamilies']['theme'], $variation['settings']['typography']['fontFamilies']['theme'] );
- $settings['typography']['fontFamilies'] = array_unique( $settings['typography']['fontFamilies'] );
- }
- }
-
- // Bail out early if there are no settings for webfonts.
- if ( empty( $settings['typography']['fontFamilies'] ) ) {
- return array();
- }
-
- $webfonts = array();
-
- // Look for fontFamilies.
- foreach ( $settings['typography']['fontFamilies'] as $font_families ) {
- foreach ( $font_families as $font_family ) {
-
- // Skip if fontFace is not defined.
- if ( empty( $font_family['fontFace'] ) ) {
- continue;
- }
-
- // Skip if fontFace is not an array of webfonts.
- if ( ! is_array( $font_family['fontFace'] ) ) {
- continue;
- }
-
- $webfonts = array_merge( $webfonts, $font_family['fontFace'] );
- }
- }
-
- return $webfonts;
- };
-
- /**
- * Transforms each 'src' into an URI by replacing 'file:./'
- * placeholder from theme.json.
- *
- * The absolute path to the webfont file(s) cannot be defined in
- * theme.json. `file:./` is the placeholder which is replaced by
- * the theme's URL path to the theme's root.
- *
- * @since 6.0.0
- *
- * @param array $src Webfont file(s) `src`.
- * @return array Webfont's `src` in URI.
- */
- $fn_transform_src_into_uri = static function( array $src ) {
- foreach ( $src as $key => $url ) {
- // Tweak the URL to be relative to the theme root.
- if ( ! str_starts_with( $url, 'file:./' ) ) {
- continue;
- }
-
- $src[ $key ] = get_theme_file_uri( str_replace( 'file:./', '', $url ) );
- }
-
- return $src;
- };
-
- /**
- * Converts the font-face properties (i.e. keys) into kebab-case.
- *
- * @since 6.0.0
- *
- * @param array $font_face Font face to convert.
- * @return array Font faces with each property in kebab-case format.
- */
- $fn_convert_keys_to_kebab_case = static function( array $font_face ) {
- foreach ( $font_face as $property => $value ) {
- $kebab_case = _wp_to_kebab_case( $property );
- $font_face[ $kebab_case ] = $value;
- if ( $kebab_case !== $property ) {
- unset( $font_face[ $property ] );
- }
- }
-
- return $font_face;
- };
-
- /**
- * Validates a webfont.
- *
- * @since 6.0.0
- *
- * @param array $webfont The webfont arguments.
- * @return array|false The validated webfont arguments, or false if the webfont is invalid.
- */
- $fn_validate_webfont = static function( $webfont ) {
- $webfont = wp_parse_args(
- $webfont,
- array(
- 'font-family' => '',
- 'font-style' => 'normal',
- 'font-weight' => '400',
- 'font-display' => 'fallback',
- 'src' => array(),
+ $classic_theme_styles_settings = array(
+ 'css' => file_get_contents( $classic_theme_styles ),
+ '__unstableType' => 'core',
+ 'isGlobalStyles' => false,
+ );
+
+ // Add these settings to the start of the array so that themes can override them.
+ array_unshift( $editor_settings['styles'], $classic_theme_styles_settings );
+
+ return $editor_settings;
+}
+
+/**
+ * Removes leading and trailing _empty_ script tags.
+ *
+ * This is a helper meant to be used for literal script tag construction
+ * within `wp_get_inline_script_tag()` or `wp_print_inline_script_tag()`.
+ * It removes the literal values of "<script>" and "</script>" from
+ * around an inline script after trimming whitespace. Typically this
+ * is used in conjunction with output buffering, where `ob_get_clean()`
+ * is passed as the `$contents` argument.
+ *
+ * Example:
+ *
+ * // Strips exact literal empty SCRIPT tags.
+ * $js = '<script>sayHello();</script>;
+ * 'sayHello();' === wp_remove_surrounding_empty_script_tags( $js );
+ *
+ * // Otherwise if anything is different it warns in the JS console.
+ * $js = '<script type="text/javascript">console.log( "hi" );</script>';
+ * 'console.error( ... )' === wp_remove_surrounding_empty_script_tags( $js );
+ *
+ * @since 6.4.0
+ * @access private
+ *
+ * @see wp_print_inline_script_tag()
+ * @see wp_get_inline_script_tag()
+ *
+ * @param string $contents Script body with manually created SCRIPT tag literals.
+ * @return string Script body without surrounding script tag literals, or
+ * original contents if both exact literals aren't present.
+ */
+function wp_remove_surrounding_empty_script_tags( $contents ) {
+ $contents = trim( $contents );
+ $opener = '<SCRIPT>';
+ $closer = '</SCRIPT>';
+
+ if (
+ strlen( $contents ) > strlen( $opener ) + strlen( $closer ) &&
+ strtoupper( substr( $contents, 0, strlen( $opener ) ) ) === $opener &&
+ strtoupper( substr( $contents, -strlen( $closer ) ) ) === $closer
+ ) {
+ return substr( $contents, strlen( $opener ), -strlen( $closer ) );
+ } else {
+ $error_message = __( 'Expected string to start with script tag (without attributes) and end with script tag, with optional whitespace.' );
+ _doing_it_wrong( __FUNCTION__, $error_message, '6.4' );
+ return sprintf(
+ 'console.error(%s)',
+ wp_json_encode(
+ sprintf(
+ /* translators: %s: wp_remove_surrounding_empty_script_tags() */
+ __( 'Function %s used incorrectly in PHP.' ),
+ 'wp_remove_surrounding_empty_script_tags()'
+ ) . ' ' . $error_message
)
);
-
- // Check the font-family.
- if ( empty( $webfont['font-family'] ) || ! is_string( $webfont['font-family'] ) ) {
- trigger_error( __( 'Webfont font family must be a non-empty string.' ) );
-
- return false;
- }
-
- // Check that the `src` property is defined and a valid type.
- if ( empty( $webfont['src'] ) || ( ! is_string( $webfont['src'] ) && ! is_array( $webfont['src'] ) ) ) {
- trigger_error( __( 'Webfont src must be a non-empty string or an array of strings.' ) );
-
- return false;
- }
-
- // Validate the `src` property.
- foreach ( (array) $webfont['src'] as $src ) {
- if ( ! is_string( $src ) || '' === trim( $src ) ) {
- trigger_error( __( 'Each webfont src must be a non-empty string.' ) );
-
- return false;
- }
- }
-
- // Check the font-weight.
- if ( ! is_string( $webfont['font-weight'] ) && ! is_int( $webfont['font-weight'] ) ) {
- trigger_error( __( 'Webfont font weight must be a properly formatted string or integer.' ) );
-
- return false;
- }
-
- // Check the font-display.
- if ( ! in_array( $webfont['font-display'], array( 'auto', 'block', 'fallback', 'swap' ), true ) ) {
- $webfont['font-display'] = 'fallback';
- }
-
- $valid_props = array(
- 'ascend-override',
- 'descend-override',
- 'font-display',
- 'font-family',
- 'font-stretch',
- 'font-style',
- 'font-weight',
- 'font-variant',
- 'font-feature-settings',
- 'font-variation-settings',
- 'line-gap-override',
- 'size-adjust',
- 'src',
- 'unicode-range',
- );
-
- foreach ( $webfont as $prop => $value ) {
- if ( ! in_array( $prop, $valid_props, true ) ) {
- unset( $webfont[ $prop ] );
- }
- }
-
- return $webfont;
- };
-
- /**
- * Registers webfonts declared in theme.json.
- *
- * @since 6.0.0
- *
- * @uses $registered_webfonts To access and update the registered webfonts registry (passed by reference).
- * @uses $fn_get_webfonts_from_theme_json To run the function that gets the webfonts from theme.json.
- * @uses $fn_convert_keys_to_kebab_case To run the function that converts keys into kebab-case.
- * @uses $fn_validate_webfont To run the function that validates each font-face (webfont) from theme.json.
- */
- $fn_register_webfonts = static function() use ( &$registered_webfonts, $fn_get_webfonts_from_theme_json, $fn_convert_keys_to_kebab_case, $fn_validate_webfont, $fn_transform_src_into_uri ) {
- $registered_webfonts = array();
-
- foreach ( $fn_get_webfonts_from_theme_json() as $webfont ) {
- if ( ! is_array( $webfont ) ) {
- continue;
- }
-
- $webfont = $fn_convert_keys_to_kebab_case( $webfont );
-
- $webfont = $fn_validate_webfont( $webfont );
-
- $webfont['src'] = $fn_transform_src_into_uri( (array) $webfont['src'] );
-
- // Skip if not valid.
- if ( empty( $webfont ) ) {
- continue;
- }
-
- $registered_webfonts[] = $webfont;
- }
- };
-
- /**
- * Orders 'src' items to optimize for browser support.
- *
- * @since 6.0.0
- *
- * @param array $webfont Webfont to process.
- * @return array Ordered `src` items.
- */
- $fn_order_src = static function( array $webfont ) {
- $src = array();
- $src_ordered = array();
-
- foreach ( $webfont['src'] as $url ) {
- // Add data URIs first.
- if ( str_starts_with( trim( $url ), 'data:' ) ) {
- $src_ordered[] = array(
- 'url' => $url,
- 'format' => 'data',
- );
- continue;
- }
- $format = pathinfo( $url, PATHINFO_EXTENSION );
- $src[ $format ] = $url;
- }
-
- // Add woff2.
- if ( ! empty( $src['woff2'] ) ) {
- $src_ordered[] = array(
- 'url' => sanitize_url( $src['woff2'] ),
- 'format' => 'woff2',
- );
- }
-
- // Add woff.
- if ( ! empty( $src['woff'] ) ) {
- $src_ordered[] = array(
- 'url' => sanitize_url( $src['woff'] ),
- 'format' => 'woff',
- );
- }
-
- // Add ttf.
- if ( ! empty( $src['ttf'] ) ) {
- $src_ordered[] = array(
- 'url' => sanitize_url( $src['ttf'] ),
- 'format' => 'truetype',
- );
- }
-
- // Add eot.
- if ( ! empty( $src['eot'] ) ) {
- $src_ordered[] = array(
- 'url' => sanitize_url( $src['eot'] ),
- 'format' => 'embedded-opentype',
- );
- }
-
- // Add otf.
- if ( ! empty( $src['otf'] ) ) {
- $src_ordered[] = array(
- 'url' => sanitize_url( $src['otf'] ),
- 'format' => 'opentype',
- );
- }
- $webfont['src'] = $src_ordered;
-
- return $webfont;
- };
-
- /**
- * Compiles the 'src' into valid CSS.
- *
- * @since 6.0.0
- *
- * @param string $font_family Font family.
- * @param array $value Value to process.
- * @return string The CSS.
- */
- $fn_compile_src = static function( $font_family, array $value ) {
- $src = "local($font_family)";
-
- foreach ( $value as $item ) {
-
- if (
- str_starts_with( $item['url'], site_url() ) ||
- str_starts_with( $item['url'], home_url() )
- ) {
- $item['url'] = wp_make_link_relative( $item['url'] );
- }
-
- $src .= ( 'data' === $item['format'] )
- ? ", url({$item['url']})"
- : ", url('{$item['url']}') format('{$item['format']}')";
- }
-
- return $src;
- };
-
- /**
- * Compiles the font variation settings.
- *
- * @since 6.0.0
- *
- * @param array $font_variation_settings Array of font variation settings.
- * @return string The CSS.
- */
- $fn_compile_variations = static function( array $font_variation_settings ) {
- $variations = '';
-
- foreach ( $font_variation_settings as $key => $value ) {
- $variations .= "$key $value";
- }
-
- return $variations;
- };
-
- /**
- * Builds the font-family's CSS.
- *
- * @since 6.0.0
- *
- * @uses $fn_compile_src To run the function that compiles the src.
- * @uses $fn_compile_variations To run the function that compiles the variations.
- *
- * @param array $webfont Webfont to process.
- * @return string This font-family's CSS.
- */
- $fn_build_font_face_css = static function( array $webfont ) use ( $fn_compile_src, $fn_compile_variations ) {
- $css = '';
-
- // Wrap font-family in quotes if it contains spaces.
- if (
- str_contains( $webfont['font-family'], ' ' ) &&
- ! str_contains( $webfont['font-family'], '"' ) &&
- ! str_contains( $webfont['font-family'], "'" )
- ) {
- $webfont['font-family'] = '"' . $webfont['font-family'] . '"';
- }
-
- foreach ( $webfont as $key => $value ) {
- /*
- * Skip "provider", since it's for internal API use,
- * and not a valid CSS property.
- */
- if ( 'provider' === $key ) {
- continue;
- }
-
- // Compile the "src" parameter.
- if ( 'src' === $key ) {
- $value = $fn_compile_src( $webfont['font-family'], $value );
- }
-
- // If font-variation-settings is an array, convert it to a string.
- if ( 'font-variation-settings' === $key && is_array( $value ) ) {
- $value = $fn_compile_variations( $value );
- }
-
- if ( ! empty( $value ) ) {
- $css .= "$key:$value;";
- }
- }
-
- return $css;
- };
-
- /**
- * Gets the '@font-face' CSS styles for locally-hosted font files.
- *
- * @since 6.0.0
- *
- * @uses $registered_webfonts To access and update the registered webfonts registry (passed by reference).
- * @uses $fn_order_src To run the function that orders the src.
- * @uses $fn_build_font_face_css To run the function that builds the font-face CSS.
- *
- * @return string The `@font-face` CSS.
- */
- $fn_get_css = static function() use ( &$registered_webfonts, $fn_order_src, $fn_build_font_face_css ) {
- $css = '';
-
- foreach ( $registered_webfonts as $webfont ) {
- // Order the webfont's `src` items to optimize for browser support.
- $webfont = $fn_order_src( $webfont );
-
- // Build the @font-face CSS for this webfont.
- $css .= '@font-face{' . $fn_build_font_face_css( $webfont ) . '}';
- }
-
- return $css;
- };
-
- /**
- * Generates and enqueues webfonts styles.
- *
- * @since 6.0.0
- *
- * @uses $fn_get_css To run the function that gets the CSS.
- */
- $fn_generate_and_enqueue_styles = static function() use ( $fn_get_css ) {
- // Generate the styles.
- $styles = $fn_get_css();
-
- // Bail out if there are no styles to enqueue.
- if ( '' === $styles ) {
- return;
- }
-
- // Enqueue the stylesheet.
- wp_register_style( 'wp-webfonts', '' );
- wp_enqueue_style( 'wp-webfonts' );
-
- // Add the styles to the stylesheet.
- wp_add_inline_style( 'wp-webfonts', $styles );
- };
-
- /**
- * Generates and enqueues editor styles.
- *
- * @since 6.0.0
- *
- * @uses $fn_get_css To run the function that gets the CSS.
- */
- $fn_generate_and_enqueue_editor_styles = static function() use ( $fn_get_css ) {
- // Generate the styles.
- $styles = $fn_get_css();
-
- // Bail out if there are no styles to enqueue.
- if ( '' === $styles ) {
- return;
- }
-
- wp_add_inline_style( 'wp-block-library', $styles );
- };
-
- add_action( 'wp_loaded', $fn_register_webfonts );
- add_action( 'wp_enqueue_scripts', $fn_generate_and_enqueue_styles );
- add_action( 'admin_init', $fn_generate_and_enqueue_editor_styles );
+ }
}