WordPress.org

Make WordPress Core

Changeset 31030


Ignore:
Timestamp:
01/03/2015 03:53:30 AM (4 years ago)
Author:
wonderboymusic
Message:

Allow the 3rd argument to wp_localize_script()/WP_Scripts->localize() to be a callable, allowing data to be lazy-loaded when the script is actually enqueued.

Props jtsternberg.
Fixes #26111.

Location:
trunk/src/wp-includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class.wp-scripts.php

    r30753 r31030  
    143143        $tag = "<script type='text/javascript' src='$src'></script>\n";
    144144
    145         /** 
     145        /**
    146146         * Filter the HTML script tag of an enqueued script.
    147147         *
     
    172172            $handle = 'jquery-core';
    173173
     174        if ( is_callable( $l10n ) ) {
     175            $l10n = call_user_func( $l10n );
     176        }
     177
    174178        if ( is_array($l10n) && isset($l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present
    175179            $after = $l10n['l10n_print_after'];
  • trunk/src/wp-includes/functions.wp-scripts.php

    r31028 r31030  
    107107 * @todo Documentation cleanup
    108108 *
    109  * @param string $handle      Script handle the data will be attached to.
    110  * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable.
    111  *                            Example: '/[a-zA-Z0-9_]+/'.
    112  * @param array $l10n         The data itself. The data can be either a single or multi-dimensional array.
     109 * @param string         $handle       Script handle the data will be attached to.
     110 * @param string         $object_name  Name for the JavaScript object. Passed directly, so it should be qualified JS variable.
     111 *                                     Example: '/[a-zA-Z0-9_]+/'.
     112 * @param array|callable $l10n         The data itself. The data can be either a single or multi-dimensional array. If a callable
     113 *                                     is passed, it will be invoked at runtime.
    113114 * @return bool True if the script was successfully localized, false otherwise.
    114115 */
Note: See TracChangeset for help on using the changeset viewer.