Usually I use this method to test whether a plugin is active (usually my own).
This would be in the plugin I’m checking for:
function my_plugin_setup() {
// setup code here
}
add_action( 'plugins_loaded', 'my_plugin_setup' );
From another file or plugin I would use has_filter
on the function which is fired on plugins_loaded
:
if ( has_filter( 'plugins_loaded', 'my_plugin_setup' ) ) {
// plugin is active, do something
}
How would I use this same method above but for a class based plugin? Ie the plugin code looks something like:
class My_Plugin {
public function __construct() {
add_action( 'plugins_loaded', array( $this, 'setup' ) );
}
// other stuff below
}
Obviously this doesn’t work:
if ( has_filter( 'plugins_loaded', array( $this, 'My_Plugin' ) ) ) {
// do something
}
Note: I’d like to use this method instead of using is_plugin_active
because the plugin’s folder name might change and hence is_plugin_active would no longer work.