The is_plugin_inactive() WordPress PHP function determines whether a specific plugin is inactive.
Usage
is_plugin_inactive( 'plugin-directory/plugin-file.php' );
Parameters
$plugin(string) – Required. The path to the plugin file relative to the plugins directory.
More information
See WordPress Developer Resources: is_plugin_inactive()
Examples
Check if a plugin is inactive before displaying a notice
This example checks if the plugin ‘my-custom-plugin’ is inactive and displays a notice to activate it.
if ( is_plugin_inactive( 'my-custom-plugin/my-custom-plugin.php' ) ) {
echo '<p>Please activate the <strong>My Custom Plugin</strong> to access its features.</p>';
}
Activate a plugin if it’s inactive
This example activates the plugin ‘another-plugin’ if it’s inactive.
if ( is_plugin_inactive( 'another-plugin/another-plugin.php' ) ) {
activate_plugin( 'another-plugin/another-plugin.php' );
}
Deactivate another plugin if a specific plugin is inactive
This example deactivates the plugin ‘related-plugin’ if the plugin ‘main-plugin’ is inactive.
if ( is_plugin_inactive( 'main-plugin/main-plugin.php' ) ) {
deactivate_plugins( 'related-plugin/related-plugin.php' );
}
Check multiple plugins for inactivity
This example checks if either of the plugins ‘plugin-one’ or ‘plugin-two’ are inactive and displays a notice accordingly.
if ( is_plugin_inactive( 'plugin-one/plugin-one.php' ) || is_plugin_inactive( 'plugin-two/plugin-two.php' ) ) {
echo '<p>One or more required plugins are inactive. Please activate them.</p>';
}
Include a file if a plugin is inactive
This example includes a fallback file if the plugin ‘optional-plugin’ is inactive.
if ( is_plugin_inactive( 'optional-plugin/optional-plugin.php' ) ) {
include( 'fallback-file.php' );
}