[wp-trac] [WordPress Trac] #29722: wp_localize_script should be able to manage scalars
WordPress Trac
noreply at wordpress.org
Mon Sep 22 13:27:46 UTC 2014
#29722: wp_localize_script should be able to manage scalars
-------------------------+------------------------------
Reporter: Fab1en | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: I18N | Version: trunk
Severity: normal | Resolution:
Keywords: | Focuses: javascript
-------------------------+------------------------------
Comment (by kitchin):
To document this in wp_localize_script() I ran some tests. Inline doc
would go:
{{{
- * @param array $l10n The data itself. The data can be either a
single or multi-dimensional array.
+ * @param mixed $l10n The data to pass through to json_encode().
If the data is a string, html entities are
decoded.
If the data is an array, first dimension
string values are html decoded.
}}}
Here is how the patch changes current behavior:
{{{
No change:
null, bool(true), integer, float, array
Changes:
#1. var_dump(v): bool(false)
(was) $script : var v = [""];
(now) $script : var v = false;
#2. var_dump(v): string(19) "Save & Activate"
(was) $script : var v = "Save & Activate";
(now) $script : var v = "Save & Activate";
#3. var_dump(v): object(stdClass)#1 (1) {
["foo"]=>
string(3) "bar"
}
(was) [die]
(now) $script : var v = {"foo":"bar"};
}}}
The WP calls in script-loader.php are not affected because they all use
arrays. One oddball uses a multidimensional array to protect an integer
from getting made into a string by the old behavior. Another oddball wraps
the array elements in esc_attr() which could be nixed:
{{{
did_action( 'init' ) && $scripts->localize( 'quicktags', 'quicktagsL10n',
array(
'closeAllOpenTags' => esc_attr(__('Close all open tags')),
...
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/29722#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list