diff --git a/src/wp-includes/class.wp-scripts.php b/src/wp-includes/class.wp-scripts.php index 649f086d60..f20964ead4 100644 --- a/src/wp-includes/class.wp-scripts.php +++ b/src/wp-includes/class.wp-scripts.php @@ -501,12 +501,17 @@ class WP_Scripts extends WP_Dependencies { ), '5.7.0' ); + + if ( false === $l10n ) { + // This should really not be needed, but is necessary for backward compatibility. + $l10n = array( $l10n ); + } } if ( is_string( $l10n ) ) { $l10n = html_entity_decode( $l10n, ENT_QUOTES, 'UTF-8' ); - } else { - foreach ( (array) $l10n as $key => $value ) { + } elseif ( is_array( $l10n ) ) { + foreach ( $l10n as $key => $value ) { if ( ! is_scalar( $value ) ) { continue; } diff --git a/tests/phpunit/tests/dependencies/scripts.php b/tests/phpunit/tests/dependencies/scripts.php index e799247352..9a85ee34f0 100644 --- a/tests/phpunit/tests/dependencies/scripts.php +++ b/tests/phpunit/tests/dependencies/scripts.php @@ -1428,17 +1428,8 @@ JS; * * @param mixed $l10n_data Localization data passed to wp_localize_script(). * @param string $expected Expected transformation of localization data. - * @param string $warning Optional. Whether a PHP native warning/error is expected. Default false. */ - public function test_wp_localize_script_data_formats( $l10n_data, $expected, $warning = false ) { - if ( $warning ) { - if ( PHP_VERSION_ID < 80000 ) { - $this->expectWarning(); - } else { - $this->expectError(); - } - } - + public function test_wp_localize_script_data_formats( $l10n_data, $expected ) { if ( ! is_array( $l10n_data ) ) { $this->setExpectedIncorrectUsage( 'WP_Scripts::localize' ); } @@ -1460,7 +1451,6 @@ JS; * * @type mixed $l10n_data Localization data passed to wp_localize_script(). * @type string $expected Expected transformation of localization data. - * @type string $warning Optional. Whether a PHP native warning/error is expected. * } */ public function data_wp_localize_script_data_formats() { @@ -1471,14 +1461,16 @@ JS; array( array( 'foo' => array( 'bar' => 'foobar' ) ), '{"foo":{"bar":"foobar"}}' ), array( array( 'foo' => 6.6 ), '{"foo":"6.6"}' ), array( array( 'foo' => 6 ), '{"foo":"6"}' ), + array( array(), '[]' ), // Unofficially supported format. array( 'string', '"string"' ), // Unsupported formats. - array( 1.5, '1.5', true ), - array( 1, '1', true ), + array( 1.5, '1.5' ), + array( 1, '1' ), array( false, '[""]' ), + array( null, 'null' ), ); }