Skip to content

Instantly share code, notes, and snippets.

@dartiss
Last active Feb 14, 2018
Embed
What would you like to do?
Check the current state of a WordPress Plugin
<?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;
}
?>
@dartiss
Copy link
Author

dartiss commented Nov 15, 2017

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/

@dartiss
Copy link
Author

dartiss commented Feb 14, 2018

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