#29918 closed enhancement (invalid)
Allow script localization to be set on wp_register_script
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.0 |
Component: | Script Loader | Keywords: | |
Focuses: | Cc: |
Description
Not sure if that has been asked before, could not find it.
Let script_a.js be a script that needs some localization. Let script_b.js be a script that has script_a.js as a dependency. We can register both of them with the right dependency settings, and enqueue just script_b.js. This will enqueue script_a.js, but we have no way of localizing it. The only way to do so is to enqueue script_a.js manually, making the dependency feature useless.
The goal should be to have the localization data ready on enqueue time, no matter whether the script is being used as a dependency or not. As you can add multiple localizations to the same script, this should not break existing calls to wp_localize_script.
I see that the registering of both styles and scripts is handled by the same base method WP_Dependencies::add, so this might not be as simple as to add another parameter to wp_register_script. Anyhow, this would be a very nice feature.
Shouldn't this work: