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. Built from https://develop.svn.wordpress.org/trunk@31030 git-svn-id: http://core.svn.wordpress.org/trunk@31011 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
618c5b4333
commit
e649887e40
|
@ -142,7 +142,7 @@ class WP_Scripts extends WP_Dependencies {
|
|||
|
||||
$tag = "<script type='text/javascript' src='$src'></script>\n";
|
||||
|
||||
/**
|
||||
/**
|
||||
* Filter the HTML script tag of an enqueued script.
|
||||
*
|
||||
* @since 4.1.0
|
||||
|
@ -171,6 +171,10 @@ class WP_Scripts extends WP_Dependencies {
|
|||
if ( $handle === 'jquery' )
|
||||
$handle = 'jquery-core';
|
||||
|
||||
if ( is_callable( $l10n ) ) {
|
||||
$l10n = call_user_func( $l10n );
|
||||
}
|
||||
|
||||
if ( is_array($l10n) && isset($l10n['l10n_print_after']) ) { // back compat, preserve the code in 'l10n_print_after' if present
|
||||
$after = $l10n['l10n_print_after'];
|
||||
unset($l10n['l10n_print_after']);
|
||||
|
|
|
@ -106,10 +106,11 @@ function wp_register_script( $handle, $src, $deps = array(), $ver = false, $in_f
|
|||
*
|
||||
* @todo Documentation cleanup
|
||||
*
|
||||
* @param string $handle Script handle the data will be attached to.
|
||||
* @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable.
|
||||
* Example: '/[a-zA-Z0-9_]+/'.
|
||||
* @param array $l10n The data itself. The data can be either a single or multi-dimensional array.
|
||||
* @param string $handle Script handle the data will be attached to.
|
||||
* @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable.
|
||||
* Example: '/[a-zA-Z0-9_]+/'.
|
||||
* @param array|callable $l10n The data itself. The data can be either a single or multi-dimensional array. If a callable
|
||||
* is passed, it will be invoked at runtime.
|
||||
* @return bool True if the script was successfully localized, false otherwise.
|
||||
*/
|
||||
function wp_localize_script( $handle, $object_name, $l10n ) {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '4.2-alpha-31029';
|
||||
$wp_version = '4.2-alpha-31030';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue