Bugs and modifications to localize script
|Reported by:||ssmathias||Owned by:|
After working in trunk, I noted that I get a fatal error when trying to localize some objects with wp_localize_script informing me that I cannot use an object of that type as an array. For tests, I've done this with $wp, $wp_query, $wpdb, and $wp_scripts on a clean install with no plugins.
I also have been working on sites that would like to compress all of their JS calls into a single request where possible, but in the past I was not able to keep localizations that certain scripts required, and had to leave them out.
With the changes I've made in this patch file, the issues regarding pushing arbitrary objects for localization are addressed. It also stores those objects, rather than a string of JS with $wp_scripts. This allows me to pull the localizations used for some files, and attach them instead to another file using wp_localize_script.
As a side benefit, by not processing the object into JS until output, we are able to preserve the data cleanly, and reduce process on any script that may be dequeued later that has such dependencies.
I would like to submit this patch as a core patch for a future release. Its design is fully compatible with existing functionality in 3.3, with the exception of any code modifying the underlying data key in an enqueued script directly.
Change History (8)
comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 @ssmathias — 3 years ago
comment:6 @c3mdigital — 23 months ago
- Keywords close added
- Resolution set to wontfix
- Status changed from new to closed