is_plugin_inactive()
云策文档标注
概述
is_plugin_inactive() 是 WordPress 核心函数,用于判断指定插件是否处于未激活状态。它是 is_plugin_active() 的反向函数,通常用作回调函数。
关键要点
- 函数功能:检查插件是否未激活,返回布尔值(True 表示未激活,False 表示激活)
- 参数:$plugin(字符串,必需),插件文件相对于 plugins 目录的路径
- 依赖关系:需要先加载 wp-admin/includes/plugin.php 文件才能使用此函数
- 使用场景:常用于后台管理区域、主题或插件开发中,作为条件判断
代码示例
// 确保函数已定义再使用
if ( ! function_exists( 'is_plugin_inactive' ) ) {
require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
}
if ( is_plugin_inactive( 'plugin-directory/plugin-file.php' ) ) {
// 插件未激活时的处理代码
}注意事项
- 此函数并非始终可用,在插件主文件中直接使用可能导致致命错误,需先检查函数是否存在并加载必要文件
原文内容
Determines whether the plugin is inactive.
Description
Reverse of is_plugin_active() . Used as a callback.
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
See also
Parameters
$pluginstringrequired-
Path to the plugin file relative to the plugins directory.
Source
function is_plugin_inactive( $plugin ) {
return ! is_plugin_active( $plugin );
}
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |
Skip to note 3 content
Codex
Example
// Makes sure the function is defined before trying to use it if ( ! function_exists( 'is_plugin_inactive' ) ) { require_once( ABSPATH . '/wp-admin/includes/plugin.php' ); } if ( is_plugin_inactive( 'plugin-directory/plugin-file.php' ) ) { //plugin is not activated }Skip to note 4 content
Gerard Reches
Notice that this function is not available at all times. Using it in your plugin’s main file will result in a fatal error.