Skip to content

Instantly share code, notes, and snippets.

@ajitbohra
Created November 16, 2016 12:23
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 ajitbohra/0fcaf3fb9be04688cd06d8f3e8d35203 to your computer and use it in GitHub Desktop.
Save ajitbohra/0fcaf3fb9be04688cd06d8f3e8d35203 to your computer and use it in GitHub Desktop.
Wordpress Get Plugin Status
<?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