[wp-trac] [WordPress Trac] #26111: wp_localize_script array from callback for performance

WordPress Trac noreply at wordpress.org
Tue Nov 19 15:57:57 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        |
-------------------------+------------------------------
Changes (by SergeyBiryukov):

 * keywords:   => close


Comment:

 > 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:2>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list