IMPORTANT — Plugin Devs – Read this
-
When writing a plugin that requires BuddyPress, it’s important to include the following code to make sure your plugin is registered correctly:
From JJJ:
For BuddyPress 1.2, I’ve been using this.
function your_custom_loader() {
// Put the code that needs BuddyPress here. This could be something like...
require_once( WP_PLUGIN_DIR . '/your-custom-plugin/your-plugin-buddypress.php' );
}
if ( defined( 'BP_VERSION' ) )
your_custom_loader();
else
add_action( 'bp_init', 'your_custom_loader' );This way it isn’t loading any files and isn’t force loading BuddyPress; instead it’s looking to see if it’s active, and if it is your plugin loads; if it’s not it adds itself to the new bp_init action at the end of the BuddyPress load cycle, and loads then.
This method also follows the philosophy that plugins should be made for WordPress but be BuddyPress aware. This way you can tuck your BuddyPress functions and features away in a special
your-plugin-buddypress.php
file, and only load that file when BuddyPress is already loaded and active, and without errors.Also, you’re not adding any overhead by doing this, other than a binary check for BP_VERSION. Your plugin will load itself as usual in the WordPress plugins screen, and will only start looking for BuddyPress code when BuddyPress tells it too. This is actually how I made the BuddyPress Backpat plugin load itself.
- The topic ‘IMPORTANT — Plugin Devs – Read this’ is closed to new replies.