Checking For BuddyPress

Because of the way that WordPress loads plugins, it’s possible that your plugin could load before or after BuddyPress. This makes it difficult to know if BuddyPress is loaded, or if your plugin has the proper functions available that it might need. If you don’t check, and assume BuddyPress is loaded, it could take an entire site down when BuddyPress is upgraded.

It’s really easy to do this. In your plugin, create a loader.php file that will check to see if BuddyPress is active, and only then load code that relies on BP:


/*
Plugin Name: My Plugin
Plugin URI: http://example.org/my-plugin/
Description: My BuddyPress plugin
Version: 1.0
Requires at least: WordPress 2.9.1 / BuddyPress 1.2
Tested up to: WordPress 2.9.1 / BuddyPress 1.2
License: GNU/GPL 2
Author: Some Person
Author URI: http://example.org/me/
*/

/* Only load code that needs BuddyPress to run once BP is loaded and initialized. */
function my_plugin_init() {
require( dirname( __FILE__ ) . ‘/my-plugin.php’ );
}
add_action( ‘bp_include’, ‘my_plugin_init’ );

/* If you have code that does not need BuddyPress to run, then add it here. */