wp_skip_paused_themes()
云策文档标注
概述
wp_skip_paused_themes() 是一个 WordPress 函数,用于过滤主题列表,移除其中已暂停的主题。它接收一个主题目录路径数组,并返回过滤后的数组,同时将暂停主题信息存储在全局变量中。
关键要点
- 函数作用:从给定的主题列表中移除所有已暂停的主题。
- 参数:$themes,一个必需的主题绝对目录路径数组。
- 返回值:过滤后的主题绝对路径数组,不包含任何暂停主题。
- 内部逻辑:通过 wp_paused_themes()->get_all() 获取暂停主题列表,遍历输入数组并移除匹配项。
- 副作用:将暂停主题信息存储在 $GLOBALS['_paused_themes'] 中,用于显示管理通知。
- 引入版本:WordPress 5.2.0。
代码示例
function wp_skip_paused_themes( array $themes ) {
$paused_themes = wp_paused_themes()->get_all();
if ( empty( $paused_themes ) ) {
return $themes;
}
foreach ( $themes as $index => $theme ) {
$theme = basename( $theme );
if ( array_key_exists( $theme, $paused_themes ) ) {
unset( $themes[ $index ] );
// Store list of paused themes for displaying an admin notice.
$GLOBALS['_paused_themes'][ $theme ] = $paused_themes[ $theme ];
}
}
return $themes;
}注意事项
- 函数依赖于 wp_paused_themes() 来获取暂停主题列表,确保相关扩展保护机制已启用。
- 移除主题时使用 basename() 提取主题目录名进行匹配,确保路径格式正确。
- 全局变量 $_paused_themes 用于后续管理界面显示,开发者应避免直接修改此变量。
原文内容
Filters a given list of themes, removing any paused themes from it.
Parameters
$themesstring[]required-
Array of absolute theme directory paths.
Source
function wp_skip_paused_themes( array $themes ) {
$paused_themes = wp_paused_themes()->get_all();
if ( empty( $paused_themes ) ) {
return $themes;
}
foreach ( $themes as $index => $theme ) {
$theme = basename( $theme );
if ( array_key_exists( $theme, $paused_themes ) ) {
unset( $themes[ $index ] );
// Store list of paused themes for displaying an admin notice.
$GLOBALS['_paused_themes'][ $theme ] = $paused_themes[ $theme ];
}
}
return $themes;
}
Changelog
| Version | Description |
|---|---|
| 5.2.0 | Introduced. |