返回介绍

is_plugin_active()

发布于 2017-09-11 01:22:04 字数 3303 浏览 1037 评论 0 收藏 0

is_plugin_active( string $plugin )

Check whether a plugin is active.


description

Only plugins installed in the plugins/ folder can be active.

Plugins in the mu-plugins/ folder can’t be "activated," so this function will return false for those plugins.


参数

$plugin

(string) (Required) Path to the main plugin file from plugins directory.


返回值

(bool) True, if in the active plugins list. False, not in the list.


源代码

File: wp-admin/includes/plugin.php

function is_plugin_active( $plugin ) {
	return in_array( $plugin, (array) get_option( 'active_plugins', array() ) ) || is_plugin_active_for_network( $plugin );
}

更新日志

Versiondescription
2.5.0Introduced.

相关函数

Uses

  • wp-admin/includes/plugin.php: is_plugin_active_for_network()
  • wp-includes/option.php: get_option()

Used By

  • wp-admin/includes/ajax-actions.php: wp_ajax_delete_plugin()
  • wp-admin/includes/class-plugin-upgrader.php: Plugin_Upgrader::bulk_upgrade()
  • wp-admin/includes/class-plugin-upgrader.php: Plugin_Upgrader::deactivate_plugin_before_upgrade()
  • wp-admin/includes/class-wp-plugins-list-table.php: WP_Plugins_List_Table::single_row()
  • wp-admin/includes/class-wp-plugins-list-table.php: WP_Plugins_List_Table::prepare_items()
  • wp-admin/includes/class-plugin-upgrader-skin.php: Plugin_Upgrader_Skin::__construct()
  • wp-admin/includes/update.php: wp_plugin_update_row()
  • wp-admin/includes/plugin.php: is_plugin_inactive()
  • wp-admin/includes/plugin.php: deactivate_plugins()
  • wp-admin/includes/class-wp-plugin-install-list-table.php: WP_Plugin_Install_List_Table::display_rows()
  • Show 5 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 2You must log in to vote on the helpfulness of this note Contributed by Codex

    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
    } 
    
    
  2. Admin area

    
    <?php
    /**
     * Detect plugin. For use in Admin area only.
     */
    if ( is_plugin_active( 'plugin-directory/plugin-file.php' ) ) {
    	//plugin is activated
    } 
    
    
    
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文