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.


git-svn-id: https://develop.svn.wordpress.org/trunk@31030 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Scott Taylor
2015-01-03 03:53:30 +00:00
parent d5328fc674
commit c69dbc8b5a
2 changed files with 10 additions and 5 deletions

View File

@@ -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']);