Last active
February 14, 2018 14:15
-
-
Save dartiss/759609111722a9b303c217ca82d26800 to your computer and use it in GitHub Desktop.
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; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.