Skip to:
Content
Pages
Categories
Search
Top
Bottom

Plugin Developers: Changes around $bp global

  • Avatar of Andy Peatling
    Andy Peatling
    Keymaster

    @apeatling

    Just a warning, I’m going to be making a change to $bp before this first release that will effect plugin developers.

    Currently, $bp is an array, and you access variables like $bp and $bp.

    This will be changing to an object – the structure will remain the same, however the way you reference variables is different. Here’s some examples:

    $bp changes to $bp->current_component

    $bp changes to $bp->groups->slug

    $bp changes to $bp->friends->table_name

    $bp changes to $bp->loggedin_user->domain;

    $bp changes to $bp->loggedin_user->id;

    $bp changes to $bp->displayed_user->domain;

    $bp changes to $bp->displayed_user->id;

    These changes will be committed sometime today. Not only is it much cleaner, it also is easier to include within SQL statements without the need to escape.

Viewing 16 replies - 1 through 16 (of 16 total)
  • Avatar of Plrk
    plrk
    Participant

    @plrk

    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?

    Avatar of Plrk
    plrk
    Participant

    @plrk

    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

    Avatar of Andy Peatling
    Andy Peatling
    Keymaster

    @apeatling

    Yes, exactly, you also don’t need the new stdClass; bit.

    Hopefully these changes will be documented :)

    Avatar of Nicola Greco
    nicolagreco
    Participant

    @nicolagreco

    D’oh! I’ve to replace global in my plugins!

    Avatar of Nicola Greco
    nicolagreco
    Participant

    @nicolagreco

    I want to know more info about

    $bp

    $bp

    $bp

    $bp

    $bp

    thanks :)

    Avatar of Nicola Greco
    nicolagreco
    Participant

    @nicolagreco

    Avatar of Devrim
    Devrim
    Participant

    @devrim

    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?

    Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    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?

    Avatar of Devrim
    Devrim
    Participant

    @devrim

    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…

    Avatar of Nicola Greco
    nicolagreco
    Participant

    @nicolagreco

    devrim you’ve first to require_once(‘bp-core.php’);

    or call the global $bp

    Avatar of Devrim
    Devrim
    Participant

    @devrim

    $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;

    ?>

    Avatar of Devrim
    Devrim
    Participant

    @devrim

    in fact whole print_r($bp); is empty.

    Avatar of Andy Peatling
    Andy Peatling
    Keymaster

    @apeatling

    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.

    Avatar of Devrim
    Devrim
    Participant

    @devrim

    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.

    Avatar of Andy Peatling
    Andy Peatling
    Keymaster

    @apeatling

    As long as you wrap all of your code and execute it on the ‘wp’ action call, you’ll be fine.

Viewing 16 replies - 1 through 16 (of 16 total)

You must be logged in to reply to this topic.