From 4546b73afbeffaea9dcd9f5b33a9044042089c4c Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Thu, 2 May 2024 15:06:16 +0000 Subject: [PATCH] Script Loader: Ensure wp_localize_script() works when called early. Before, wp_localize_script() did not work when the $wp_scripts global was not already set (for example because of a script registration happening elsewhere) and even emitted a warning in that case. Due to side effects such as block registration early in the load process, this usually never happened. However, the absence of these side effects in 6.5 caused the wp_localize_script() to no longer work in places such as the login_enqueue_scripts. By calling wp_scripts() in wp_localize_script(), the $wp_scripts global is automatically set if needed, restoring previous behavior. Adds both a PHP unit test and an e2e test to verify this use case. Hat tip: jorbin. Thanks for the birthday wishes, Pascal! Reviewed by Jorbin. Merges [58068] to the 6.5 branch. Props salcode, aslamdoctor, jorbin, swissspidy. Fixes #60862. Built from https://develop.svn.wordpress.org/branches/6.5@58078 git-svn-id: http://core.svn.wordpress.org/branches/6.5@57543 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.wp-scripts.php | 8 +------- wp-includes/version.php | 2 +- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/wp-includes/functions.wp-scripts.php b/wp-includes/functions.wp-scripts.php index 1207502c44..de134961f8 100644 --- a/wp-includes/functions.wp-scripts.php +++ b/wp-includes/functions.wp-scripts.php @@ -211,7 +211,6 @@ function wp_register_script( $handle, $src, $deps = array(), $ver = false, $args * * @see WP_Scripts::localize() * @link https://core.trac.wordpress.org/ticket/11520 - * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. * * @since 2.2.0 * @@ -224,12 +223,7 @@ function wp_register_script( $handle, $src, $deps = array(), $ver = false, $args * @return bool True if the script was successfully localized, false otherwise. */ function wp_localize_script( $handle, $object_name, $l10n ) { - global $wp_scripts; - - if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { - _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); - return false; - } + $wp_scripts = wp_scripts(); return $wp_scripts->localize( $handle, $object_name, $l10n ); } diff --git a/wp-includes/version.php b/wp-includes/version.php index 68df374498..b6e461eb13 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.5.3-alpha-58066'; +$wp_version = '6.5.3-alpha-58078'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.