wp_localize_script()
wp_localize_script( string $handle, string $object_name…
wp_localize_script( string $handle, string $object_name, array $l10n )
本地化脚本。
Localize a script.
目录锚点:#说明#参数#源码#笔记
说明(Description)
仅当脚本已添加时才有效。接受一个关联数组$l10n并创建一个JavaScript对象:“$object_name”={key:value,key:value。。。}另请参阅WP_Scripts::localize()
参数(Parameters)
| 参数 | 类型 | 说明 |
|---|---|---|
| $handle | (string) | 数据将附加到的脚本句柄。 |
| $object_name | (string) | JavaScript对象的名称。直接传递,所以它应该是限定的JS变量。示例:’/[a-zA-Z0-9_]+/’。 |
| $l10n | (array) | 数据本身。数据可以是单个数组,也可以是多维数组。 |
源码(Source)
/**
* Localize a script.
*
* Works only if the script has already been added.
*
* Accepts an associative array $l10n and creates a JavaScript object:
*
* "$object_name" = {
* key: value,
* key: value,
* ...
* }
*
*
* @see WP_Dependencies::localize()
* @link https://core.trac.wordpress.org/ticket/11520
* @global WP_Scripts $wp_scripts The WP_Scripts object for printing scripts.
*
* @since 2.6.0
*
* @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.
* @return bool True if the script was successfully localized, false otherwise.
*/
function wp_localize_script( $handle, $object_name, $l10n ) {
global $wp_scripts;
if ( ! ( $wp_scripts instanceof WP_Scripts ) ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__ );
return false;
}
return $wp_scripts->localize( $handle, $object_name, $l10n );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.2.0 | wp-includes/functions.wp-scripts.php | 7 | 3 |
笔记(Notes)
例子
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。





还没有任何评论,赶紧来占个楼吧!