diff -r 34716fd837a4 -r be944660c56a wp/wp-includes/class.wp-scripts.php
--- a/wp/wp-includes/class.wp-scripts.php Tue Dec 15 15:52:01 2020 +0100
+++ b/wp/wp-includes/class.wp-scripts.php Wed Sep 21 18:19:35 2022 +0200
@@ -415,7 +415,7 @@
*
* @param string $handle Name of the script to add the inline script to.
* Must be lowercase.
- * @param string $data String containing the javascript to be added.
+ * @param string $data String containing the JavaScript to be added.
* @param string $position Optional. Whether to add the inline script
* before the handle or after. Default 'after'.
* @return bool True on success, false on failure.
@@ -484,12 +484,29 @@
unset( $l10n['l10n_print_after'] );
}
- foreach ( (array) $l10n as $key => $value ) {
- if ( ! is_scalar( $value ) ) {
- continue;
+ if ( ! is_array( $l10n ) ) {
+ _doing_it_wrong(
+ __METHOD__,
+ sprintf(
+ /* translators: 1: $l10n, 2: wp_add_inline_script() */
+ __( 'The %1$s parameter must be an array. To pass arbitrary data to scripts, use the %2$s function instead.' ),
+ '$l10n
',
+ 'wp_add_inline_script()
'
+ ),
+ '5.7.0'
+ );
+ }
+
+ if ( is_string( $l10n ) ) {
+ $l10n = html_entity_decode( $l10n, ENT_QUOTES, 'UTF-8' );
+ } else {
+ foreach ( (array) $l10n as $key => $value ) {
+ if ( ! is_scalar( $value ) ) {
+ continue;
+ }
+
+ $l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
}
-
- $l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
}
$script = "var $object_name = " . wp_json_encode( $l10n ) . ';';