#23590 closed enhancement (wontfix)
Rename wp_localize_script
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | |
Component: | General | Keywords: | |
Focuses: | Cc: |
Description
Hello,
It's never made any sense to me to call a function that makes data from a php file accessible to a js file localize script. The name localize script makes me think of passing language specific data to a script. That is a valid and useful use of that method but it is only one use. It is similar to calling a spoon a cereal delivery system.
If we can give it a better name then other developers will be better able to find it an use it instead of coming up with their own methods (like embedding JS in a php file; eek!).
If you do a Google search for "pass php variable to js in wordpress" you get a lot of: "I didn't know how to do this until someone told me about this function". Here's some of the confusion:
- http://tosbourn.com/2011/08/wordpress/accessing-php-variables-from-within-javascript-under-wordpress/
- http://ottopress.com/2010/passing-parameters-from-php-to-javascripts-in-plugins/
For backwards compatibility would could make the wp_localize_script function an alias of the new method.
Related: #11520, #21547
[18464] introduced
wp_add_script_data()
, which was later reverted in [18490] and [18491].[19217] introduced
wp_add_script_before()
, which was later reverted in [19573].Relevant IRC discussion: https://irclogs.wordpress.org/chanlog.php?channel=wordpress-dev&day=2011-12-08&sort=asc#m342977