wp_get_translation_updates()
云策文档标注
概述
wp_get_translation_updates() 函数用于检索所有可用的语言更新列表。它通过检查核心、插件和主题的翻译更新,返回一个包含翻译对象的数组。
关键要点
- 函数返回一个对象数组,每个对象代表一个可用的翻译更新。
- 内部实现基于 get_site_transient() 获取更新数据,并遍历 'update_core'、'update_plugins' 和 'update_themes' 这三个瞬态。
- 如果瞬态中没有 translations 数据,则跳过处理。
代码示例
function wp_get_translation_updates() {
$updates = array();
$transients = array(
'update_core' => 'core',
'update_plugins' => 'plugin',
'update_themes' => 'theme',
);
foreach ( $transients as $transient => $type ) {
$transient = get_site_transient( $transient );
if ( empty( $transient->translations ) ) {
continue;
}
foreach ( $transient->translations as $translation ) {
$updates[] = (object) $translation;
}
}
return $updates;
}
原文内容
Retrieves a list of all language updates available.
Source
function wp_get_translation_updates() {
$updates = array();
$transients = array(
'update_core' => 'core',
'update_plugins' => 'plugin',
'update_themes' => 'theme',
);
foreach ( $transients as $transient => $type ) {
$transient = get_site_transient( $transient );
if ( empty( $transient->translations ) ) {
continue;
}
foreach ( $transient->translations as $translation ) {
$updates[] = (object) $translation;
}
}
return $updates;
}
Changelog
| Version | Description |
|---|---|
| 3.7.0 | Introduced. |