BuddyPress

Checking BuddyPress is Active

ContentsHow-To Guides → Checking BuddyPress is Active

It’s vitally important that when you build a plugin for BuddyPress that you first check that BuddyPress is active before doing anything. If your plugin does not, then it can 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_init', 'my_plugin_init' );

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