[wp-trac] [WordPress Trac] #26111: wp_localize_script array from callback for performance
WordPress Trac
noreply at wordpress.org
Tue Nov 19 21:20:49 UTC 2013
#26111: wp_localize_script array from callback for performance
-------------------------+------------------------------
Reporter: ciantic | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Performance | Version: 2.6
Severity: normal | Resolution:
Keywords: close |
-------------------------+------------------------------
Comment (by ciantic):
Neat that it is possible, however this is not very developer friendly way.
Adding a callback to `wp_localize_script` would make this more usable and
provide better performance benefit over time if people start to use it.
Replying to [comment:2 SergeyBiryukov]:
> > WordPress could then run the callback ''only if the script e.g.
date_18n is enqueued''.
>
> You can check if the script is enqueued using
[http://codex.wordpress.org/Function_Reference/wp_script_is
wp_script_is()]:
> {{{
> function date_i18n_callback() {
> ...
> return array( ... );
> }
>
> function localize_scripts_26111() {
> if ( wp_script_is( 'date_i18n' ) ) {
> wp_localize_script( 'date_i18n', 'DATE_I18N',
date_i18n_callback() );
> }
> }
> add_action( 'wp_enqueue_scripts', 'localize_scripts_26111', 11 );
> }}}
> `date_i18n_callback()` will only run if `'date_i18n'` is enqueued. No
changes to `wp_localize_script()` are needed.
--
Ticket URL: <http://core.trac.wordpress.org/ticket/26111#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list