[wp-trac] [WordPress Trac] #29722: wp_localize_script should be able to manage scalars
WordPress Trac
noreply at wordpress.org
Thu Sep 10 14:37:39 UTC 2020
#29722: wp_localize_script should be able to manage scalars
---------------------------------------+------------------------------
Reporter: Fab1en | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Script Loader | Version: 3.3
Severity: normal | Resolution:
Keywords: has-patch needs-docs php8 | Focuses: javascript
---------------------------------------+------------------------------
Comment (by andraganescu):
A quick fix for PHP 8 is to do the array casting before the `foreach`
loop, in `/wp-includes/class.wp-scripts.php:localize` like:
{{{
$l10n = ( array ) $l10n;
foreach ( $l10n as $key => $value ) {
if ( ! is_scalar( $value ) ) {
continue;
}
$l10n[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES,
'UTF-8' );
}
}}}
But it seems so "hacky" :)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29722#comment:20>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list