Created
November 16, 2016 12:23
-
-
Save ajitbohra/0fcaf3fb9be04688cd06d8f3e8d35203 to your computer and use it in GitHub Desktop.
Wordpress Get Plugin Status
This file contains hidden or 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 | |
/** | |
* Check the status of a plugin. | |
* | |
* @param string $location Base plugin path from plugins directory. | |
* @return int 1 if active; 2 if inactive; 0 if not installed | |
*/ | |
function get_plugin_status($location = '') { | |
if(is_plugin_active($location)) { | |
return 1; | |
} | |
if(!file_exists(trailingslashit(WP_PLUGIN_DIR). $location)) { | |
return false; | |
} | |
if(is_plugin_inactive($location)) { | |
return 2; | |
} | |
} | |
/** | |
* Check the status of a plugin. | |
*/ | |
$status = get_plugin_status('woocommerce/woocommerce.php'); | |
switch($status) { | |
case 1: echo 'Akismet is active.'; break; | |
case 2: echo 'Akismet is installed but inactive.'; break; | |
case 0: echo 'Akismet is not installed or active.'; break; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment