在打印而不是初始化上加载本地化数据。
原型
wp_just_in_time_script_localization()
描述
这些本地化需要即使是init也可能无法加载的信息。
源文件
路径:wp-includes/script-loader.php
<?php
...
function wp_just_in_time_script_localization() {
wp_localize_script( 'autosave', 'autosaveL10n', array(
'autosaveInterval' => AUTOSAVE_INTERVAL,
'blog_id' => get_current_blog_id(),
) );
wp_localize_script( 'mce-view', 'mceViewL10n', array(
'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array()
) );
wp_localize_script( 'word-count', 'wordCountL10n', array(
/*
* translators: If your word count is based on single characters (e.g. East Asian characters),
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
* Do not translate into your own language.
*/
'type' => _x( 'words', 'Word count type. Do not translate!' ),
'shortcodes' => ! empty( $GLOBALS['shortcode_tags'] ) ? array_keys( $GLOBALS['shortcode_tags'] ) : array()
) );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/wp_just_in_time_script_localization/