Ticket #26111: 26111.2.diff
File 26111.2.diff, 4.0 KB (added by , 10 years ago) |
---|
-
src/wp-includes/class.wp-scripts.php
184 184 } 185 185 186 186 /** 187 * Localizes a script 187 * Localizes a script. 188 188 * 189 189 * Localizes only if the script has already been added 190 * 191 * @since 2.6.0 192 * @since 4.2.0 The optional `$l10n_is_callable` parameter was added. 193 * 194 * @param string $handle Script handle the data will be attached to. 195 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be 196 * a qualified JS variable. Example: '/[a-zA-Z0-9_]+/'. 197 * @param array|callable $l10n The data itself. The data can be either a single or multi-dimensional 198 * array. If a callable is passed and `$l10n_is_callable` is true, it will 199 * be invoked at runtime. 200 * @param bool $l10n_is_callable Optional. Whether `$l10n` when passed as a string should be considered 201 * callable. Added for back-compat. Default false. 202 * @return bool True if the script was successfully localized, false otherwise. 190 203 */ 191 public function localize( $handle, $object_name, $l10n ) {204 public function localize( $handle, $object_name, $l10n, $l10n_is_callable = false ) { 192 205 if ( $handle === 'jquery' ) 193 206 $handle = 'jquery-core'; 194 207 195 if ( is_callable( $l10n ) ) {208 if ( is_callable( $l10n ) && true === $l10n_is_callable ) { 196 209 $l10n = call_user_func( $l10n, $handle, $object_name ); 197 210 } 198 211 -
src/wp-includes/functions.wp-scripts.php
135 135 * @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts. 136 136 * 137 137 * @since 2.6.0 138 * @since 4.2.0 The optional `$l10n_is_callable` parameter was added. 138 139 * 139 140 * @todo Documentation cleanup 140 141 * 141 * @param string $handle Script handle the data will be attached to. 142 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified JS variable. 143 * Example: '/[a-zA-Z0-9_]+/'. 144 * @param array|callable $l10n The data itself. The data can be either a single or multi-dimensional array. If a callable 145 * is passed, it will be invoked at runtime. 142 * @param string $handle Script handle the data will be attached to. 143 * @param string $object_name Name for the JavaScript object. Passed directly, so it should be qualified 144 * JS variable. Example: '/[a-zA-Z0-9_]+/'. 145 * @param array|callable $l10n The data itself. The data can be either a single or multi-dimensional array. 146 * If a callable is passed and `$l10n_is_callable` is true, it will be invoked 147 * at runtime. 148 * @param bool $l10n_is_callable Optional. Whether `$l10n` when passed as a string should be considered 149 * callable. Added for back-compat. Default false. 146 150 * @return bool True if the script was successfully localized, false otherwise. 147 151 */ 148 function wp_localize_script( $handle, $object_name, $l10n ) {152 function wp_localize_script( $handle, $object_name, $l10n, $l10n_is_callable = false ) { 149 153 global $wp_scripts; 150 154 if ( ! ( $wp_scripts instanceof WP_Scripts ) ) { 151 155 _wp_scripts_maybe_doing_it_wrong( __FUNCTION__ ); … … 152 156 return false; 153 157 } 154 158 155 return wp_scripts()->localize( $handle, $object_name, $l10n );159 return wp_scripts()->localize( $handle, $object_name, $l10n, $l10n_is_callable ); 156 160 } 157 161 158 162 /**