Someone asked me this question in quora.com. Since it relates to WordPress in general I thought of making a post on it.
Apart from manually checking if a plugin is active, there is a simple in-built way to check if a plugin is active in WordPress using the function is_plugin_active function. This inbuilt function takes the name of the plugin as parameter.
This is how you will use the plugin
$flag = is_plugin_active($plugin);
The return value can be assigned to a variable to check if the plugin is active as shown above. If it is then the return value is 1 and if not then it returns nothing.
Note that according to WordPress documentation it should return a false value if the plugin is not active but it does not return any value. I checked the code myself.
The $plugin value it the name of the main plugin file path. It starts from the plugin directory name relative to plugin directory. So if you have a plugin my-awesome-plugin.php main file under my-awesome-plugin directory then the value of $plugin will be as follows
$plugin = 'my-awesome-plugin/my-awesome-plugin.php';
So if you want to check if your plugin is active or not then the code would be
$flag = is_plugin_active('my-awesome-plugin/my-awesome-plugin.php');
Please note that you will need to use the following line before using the code, else you will get an unknown function error
include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
So the complete code will look like
include_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $flag = is_plugin_active('my-awesome-plugin/my-awesome-plugin.php');
Thats all. If you know of any other method to view the status of a plugin then let me know in comments below.
Thanks for reading.