Skip to content

Instantly share code, notes, and snippets.

@dartiss
Last active February 14, 2018 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dartiss/759609111722a9b303c217ca82d26800 to your computer and use it in GitHub Desktop.
Save dartiss/759609111722a9b303c217ca82d26800 to your computer and use it in GitHub Desktop.
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