is_plugin_paused()
云策文档标注
概述
is_plugin_paused() 函数用于判断一个插件在技术上处于活动状态,但在加载过程中是否被暂停。它检查插件是否在暂停插件列表中,返回布尔值。
关键要点
- 函数接受一个必需参数 $plugin,表示插件文件相对于插件目录的路径。
- 返回值为布尔类型:如果插件在暂停列表中返回 true,否则返回 false。
- 函数内部首先检查全局变量 $_paused_plugins 是否存在,然后验证插件是否处于活动状态,最后通过插件 slug 判断是否在暂停列表中。
- 该函数自 WordPress 5.2.0 版本引入。
代码示例
function is_plugin_paused( $plugin ) {
if ( ! isset( $GLOBALS['_paused_plugins'] ) ) {
return false;
}
if ( ! is_plugin_active( $plugin ) ) {
return false;
}
list( $plugin ) = explode( '/', $plugin );
return array_key_exists( $plugin, $GLOBALS['_paused_plugins'] );
}
原文内容
Determines whether a plugin 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
$pluginstringrequired-
Path to the plugin file relative to the plugins directory.
Source
function is_plugin_paused( $plugin ) {
if ( ! isset( $GLOBALS['_paused_plugins'] ) ) {
return false;
}
if ( ! is_plugin_active( $plugin ) ) {
return false;
}
list( $plugin ) = explode( '/', $plugin );
return array_key_exists( $plugin, $GLOBALS['_paused_plugins'] );
}
Changelog
| Version | Description |
|---|---|
| 5.2.0 | Introduced. |