函数文档

is_theme_paused()

💡 云策文档标注

概述

is_theme_paused() 函数用于判断一个主题在技术上是否处于活动状态,但在加载过程中被暂停。它检查主题是否在暂停主题列表中。

关键要点

  • 函数接受一个必需参数 $theme,表示相对于主题目录的主题路径字符串。
  • 返回布尔值:如果主题在暂停列表中返回 true,否则返回 false。
  • 函数内部检查全局变量 $_paused_themes 是否存在,并验证主题是否为当前活动主题或父主题。

代码示例

function is_theme_paused( $theme ) {
	if ( ! isset( $GLOBALS['_paused_themes'] ) ) {
		return false;
	}

	if ( get_stylesheet() !== $theme && get_template() !== $theme ) {
		return false;
	}

	return array_key_exists( $theme, $GLOBALS['_paused_themes'] );
}

注意事项

  • 此函数自 WordPress 5.2.0 版本引入。
  • 相关函数包括 get_template() 和 get_stylesheet(),用于获取活动主题和当前样式表名称。
  • 更多信息可参考主题开发者手册中的条件标签文章。

📄 原文内容

Determines whether a theme is technically active but was paused while loading.

Description

For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.

Parameters

$themestringrequired
Path to the theme directory relative to the themes directory.

Return

bool True, if in the list of paused themes. False, not in the list.

Source

function is_theme_paused( $theme ) {
	if ( ! isset( $GLOBALS['_paused_themes'] ) ) {
		return false;
	}

	if ( get_stylesheet() !== $theme && get_template() !== $theme ) {
		return false;
	}

	return array_key_exists( $theme, $GLOBALS['_paused_themes'] );
}

Changelog

Version Description
5.2.0 Introduced.