How Do I Programmatically Check if a WordPress Plugin Is Already Activated?

Posted by Volomike on Stack Overflow See other posts from Stack Overflow or by Volomike
Published on 2010-04-20T03:56:11Z Indexed on 2010/04/20 4:13 UTC
Read the original article Hit count: 305

I know I can use activate_plugin() from inside a given, active plugin in WordPress, to activate another plugin. But what I want to know is how do I programmatically check if that plugin is already active?

For instance, this snippet of code can be temporarily added to an existing plugin's initial file to activate a partner plugin:

add_action('wp','activatePlugins');

function activatePlugins() {
  if( is_single() || is_page() || is_home() || is_archive() || is_category() || is_tag()) {
    @ activate_plugin('../mypartnerplugin/thepluginsmainfile.php');
  }
}

Then, use a Linux command line tool to spider all your sites that have this code, and it will force a page view. That page view will cause the above code to fire and activate that other plugin. That's how to programmatically activate another plugin from a given plugin as far as I can tell.

But the problem is that it gets activated over and over and over again. What would be great is if I had an if/then condition and some function I could call in WordPress to see if that plugin is already activated, and only activate it once if not active.

© Stack Overflow or respective owner

Related posts about Wordpress

Related posts about wordpress-plugin