WordPress 检查插件是否安装
is_plugin_active()函数可以检查插件是否被安装和激活,但要注意:
在wp-admin/includes/plugin.php中有声明,该函数只能在后台管理页面中使用,并且对此函数的任何引用都必须挂钩到admin_init或更高权限的操作。如果要在前台模板中使用此功能,需要手动引入plugin.php。
例子:
Admin area
<?php /** * Detect plugin. For use in Admin area only. */ if (is_plugin_active('plugin-directory/plugin-file.php')) { //plugin is activated }
Front end
<?php /** * Detect plugin. For use on Front End only. */ include_once(ABSPATH . 'wp-admin/includes/plugin.php'); // check for plugin using plugin name if (is_plugin_active('plugin-directory/plugin-file.php')) { //plugin is activated }