Check the current state of a WordPress Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function check_plugin_status( $plugin_dir, $plugin_name = '' ) { | |
if ( '' == $plugin_name ) { $plugin_name = $plugin_dir . '.php'; } | |
if ( is_plugin_active( $plugin_dir . '/' . $plugin_name ) ) { | |
$status = 2; | |
} else { | |
$plugins = get_plugins( '/' . $plugin_dir ); | |
if ( $plugins ) { | |
$status = 1; | |
} else { | |
$status = 0; | |
} | |
} | |
return $status; | |
} | |
?> |
Modified the code to make it more streamlined - before I was checking first if it was installed and then checking if it was active. If I check active first and it is, you can assume it's installed! This makes the amount of processing less.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are two input parameters - the plugin directory name and the name. The second doesn't have to be specified if they're both the same. It will return a value of either 0, 1 or 2. 0=not installed, 1=installed but not active and 2 = installed and active.
https://artiss.blog/2016/10/how-to-work-out-the-current-state-of-a-plugin/