Probably your plugin is getting loaded before BuddyPress is.
I’m not even sure this code works as it should, but try adding this (renaming the function of course):
/* Check that BuddyPress is loaded before Achievements */
function dpa_load_buddypress() {
if ( function_exists( 'bp_core_setup_globals' ) )
return true;
/* Get the list of active sitewide plugins */
$active_sitewide_plugins = maybe_unserialize( get_site_option( 'active_sitewide_plugins' ) );
if ( !isset( $active_sidewide_plugins['buddypress/bp-loader.php'] ) )
return false;
if ( isset( $active_sidewide_plugins['buddypress/bp-loader.php'] ) && !function_exists( 'bp_core_setup_globals' ) ) {
require_once( WP_PLUGIN_DIR . '/buddypress/bp-loader.php' );
return true;
}
return false;
}
add_action( 'plugins_loaded', 'dpa_load_buddypress', 11 );
DJPaul, thanks for that idea. I’ll try that!
I never could get this to work right. I had to instead create a plugin that hooked into actions to save the data and then hooks into the template to add the edit fields on the group profile page.
I am running into this same problem in 1.1.3 with the groups extension api. I found a semi-ridiculous work around – name your plugin directory something that comes after “Buddypress” in the alphabet. Does any one know a way of specifying plugin dependencies?
Also, I never had this problem until I upgraded to mu 2.9.1. I can’t reproduce this issue on any of my pre-2.9.1 installations. On the older versions BP plugins always manage to get loaded after Buddypress.
I think plugins_loaded is already too late to try and load Buddypress if your plugin got loaded before it. do_action( ‘plugins_loaded comes’ ) after all plugins have been loaded, so if there is a missing class dependency, loading BP after that won’t help.
The following code works for me:
function bpgc_load_buddypress() {
//buddypress is loaded
if ( function_exists( 'bp_core_setup_globals' ) )
return false;
// Get the list of active sitewide plugins
$active_sitewide_plugins = maybe_unserialize( get_site_option( 'active_sitewide_plugins' ) );
$bp_activated = $active_sitewide_plugins['buddypress/bp-loader.php'];
//bp is not activated
if ( !$bp_activated ){
return false;
}
//bp is activated but not yet loaded
if ( $bp_activated ) {
return true;
}
return false;
}
//load bp if its not activated
if ( bpgc_load_buddypress() ){
require_once( WP_PLUGIN_DIR . '/buddypress/bp-loader.php' );
}
Add this to the top of your plugin and it ought to load correctly.
In the trunk and in version 1.2+ use the action “bp_init” as this will ensure BP is completely loaded before your plugin does anything.
Thanks andy, bp_init does the trick for my class dependencies. I suppose what I should do is create a loader.php file that loads the rest of my files on the action bp_init.
Also just for the record the code I posted above doesn’t work in 1.2, but it shouldn’t really need to if you use the bp_init action.