How to Check if a WordPress Plugin is Active Using PHP

When developing WordPress plugins, it can be helpful to know if another specific plugin is active. This can be particularly useful for compatibility checks or for enhancing your plugin’s functionality based on the presence of another plugin. WordPress provides a straightforward way to achieve this with the is_plugin_active() function.

Why Check if a Plugin is Active?

Knowing whether a plugin is active can help you:

  • Enhance Compatibility: Ensure that your plugin works smoothly alongside other plugins.
  • Conditional Features: Enable or disable features based on the activation of another plugin.
  • Avoid Conflicts: Prevent potential conflicts with other active plugins.

Using get_option()

This is actually the method I went with when making the MightyShare plugin. Using get_option works on the front end and admin dashboard, this allows you to search the array of active plugins.

<?php
// Checking if a WordPress plugin (works for admin or front end)
if ( in_array( 'plugin-directory/main-plugin-file.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
// Plugin is active
}

Using is_plugin_active()

The is_plugin_active() function allows you to check if a specific plugin is active. Here’s how to use it, depending on whether you’re in the Admin Area or on the front-end.

Check in the Admin Dashboard

If you’re in the WP Admin Area, you can use the function directly. For example:

<?php
// Checking if a WordPress plugin is active in the admin dashboard
if ( is_plugin_active( 'plugin-directory/main-plugin-file.php' ) ) {
// plugin is active
}

The parameter for is_plugin_active() requires both the plugin subdirectory and the main plugin file name.

Check on the Front-End

According to the WP Documentation:

is_plugin_active() is defined in /wp-admin/includes/plugin.php, so it’s only available in the admin pages. To use it in a template, you need to manually include plugin.php.

Here’s an example of using the function to check if a plugin is active on the front-end:

<?php
// Checking if a WordPress plugin is active on the front end
include_once ABSPATH . 'wp-admin/includes/plugin.php';
if ( is_plugin_active( 'plugin-directory/main-plugin-file.php' ) ) {
// plugin is active
}

The function returns true if the specified plugin is active, and false if it’s not.


Conclusion

For more information on WordPress development and plugin functions, check out the official WordPress website.

Leveraging the is_plugin_active() function or get_options() can significantly boost your plugin’s utility and reliability, ensuring a seamless experience for your users across different plugin environments.

Picture of Andy Feliciotti

Andy Feliciotti

Andy has been a full time WordPress developer for over 10 years. Through his years of experience has built 100s of sites and learned plenty of tricks along the way. Found this article helpful? Buy Me A Coffee

2 Responses

  1. Hello, I'm Drisya, best digital marketing strategist in kannur, kerala. I can use digital marketing techniques to assist you in expanding your company.

    seasoned digital marketer holding a degree of commerce (BCOM) and receiving specialized instruction in digital marketing from cda academy.

    I help with Google advertisements, social media marketing, and search engine optimization as the best digital marketing strategist in Kannur.

Leave a Reply

Your email address will not be published. Required fields are marked *

WordPress Tips Monthly
Get the latest from SmartWP to your inbox.