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.
Here’s the solution:
http://codex.wordpress.org/Function_Reference/is_plugin_active
You can set that plugin-directory-path either to a fixed path, or to a relative path. (Just not a web URL path.)
Note that wp-admin/includes/plugin.php must be loaded for the above code to work. Therefore, the final solution was: