So when I write a custom component, I should no longer write:
$bp = array(
‘image_base’ => site_url() . ‘/wp-content/mu-plugins/bp-mycomponent/images’,
‘slug’ => ‘mycomponent’,
‘table_name’ => ‘wp_bp_mycomponent_table’
);
I should instead write… what?
Instead, I should write:
$bp->mycomponent->image_base = site_url() . '/wp-content/mu-plugins/bp-mycomponent/images';
$bp->mycomponent->slug = 'mycomponent';
$bp->mycomponent->table_name = 'wp_bp_mycomponent_table';
I may have to write $bp->mycomponent = new stdClass; first, Andy will let us know:
<apeatlin> you may have to first do $bp->flickr = new stdClass; then do it though
<apeatlin> I’m not sure yet
<apeatlin> I’ll let you know
Yes, exactly, you also don’t need the new stdClass; bit.
Hopefully these changes will be documented
D’oh! I’ve to replace global in my plugins!
I want to know more info about
$bp
$bp
$bp
$bp
$bp
thanks
Andy, stdClass change is all good, but $bp is weirdly unreachable.. $bp->loggedin_user->id for example randomly decides to return empty string how ever we tried. Yes, wp-blog-header is included and global $bp line is there.
Do you do anything extra to call this variable? or any preparation is necessary other than what we are doing?
Anyone experiencing similar error?
I haven’t had problems with $bp->loggedin_user->id. I had problems with the old $bp which is now $bp->displayed_user->id. It wasn’t really a problem it was my lack of understanding at first, what it represented and when it was available. It was only valid when the user was in the member theme.
Exactly where and when is $bp->loggedin_user->id becoming invalid?
Hi Burtadsit, for example, you have mu-plugins/myplugin.php and it includes with require_once(myplugin/classes/myclass.php)
then you try to get $bp->loggedin_user->id; it is just empty in that class file, although each function starts with ‘global $bp’; It used to work when it was array, now strangely it is empty at random.
This is the weird part, it is empty sometimes.
I temporarily saved all $bp stuff that i need to Session. My code is not poetry anymore…
devrim you’ve first to require_once(‘bp-core.php’);
or call the global $bp
$test is empty. no matter what we do.
/wp-content/mu-plugins/x.php
<?php
require_once( ‘bp-core.php’ );
global $bp, $wpdb, $current_blog;
require_once( ‘x/classes/DB_Operations.php’ );
require_once( ‘x/classes/FS_Operations.php’ );
require_once( ‘x/classes/POST_Operations.php’ );
require_once( ‘x/classes/Render_to_Browser.php’ );
require_once( ‘x/classes/x_Environment.php’ );
require_once( ‘x/classes/File.php’ );
require_once( ‘x/classes/Notification.php’ );
$init_environment = new x_Environment();
$doPostActions = new POST_Operations();
$test = $bp->loggedin_user->id;
?>
in fact whole print_r($bp); is empty.
Devrim, you can’t just set this stuff up outside of a function call. You should download the skeleton component to understand how to write WPMU capable plugins.
You need to wrap your code in a function then call it on the ‘wp’ action.
function mystuff() {
…
}
add_action( ‘wp’, ‘mystuff’ );
You are running into problems because your code is executing before anything has been set up. BuddyPress is entirely action based, if you start programming outside of this, you’ll run into many issues.
Thanks Andy. This fixed it. I’m still curious as to why it was ok on previous version though, but stdClass is definitely better than array (because we didn’t change anything).
And unfortunately our application uses bp as a feature, so I’ll have to go outside of ‘action-based’ architecture a lot, and yet have to find ways to make it fully integrated.
So far so good. Thanks again.
As long as you wrap all of your code and execute it on the ‘wp’ action call, you’ll be fine.