Skip to:
Content
Pages
Categories
Search
Top
Bottom

Trying To Get Access BBPress In My BuddyPress Plugin

  • @dimensionmedia

    Participant

    Howdy folks. My question is simple, but instead of being embrassed to share it i’ve decided to “Let It Go” (singing the Frozen theme song here).

    Basically I’m writing a BuddyPress plugin that imports data from a client’s DB tables to create BuddyPress Groups. That’s fine. But i’m trying to create a forum for each group and i’m attempting to use BP functions that hook into bbPress (such as groups_edit_group_settings()). But from what I can gather, the bbPress functions to create the forum and associate it to the group don’t exist. I’ve even nailed it down to the below code that I load in my loader.php in the my plugin:

    function curgi_group_import_init() {

    if ( !function_exists(‘bb_update_forummeta’) ) { echo “crapstop”; exit; }

    }
    add_action( ‘bp_loaded’, ‘curgi_group_import_init’ );

    I’ve tried a variety of priority settings (and also plugins_loaded action) but I can’t seem to get around this. Any suggestions how to get the above working? bbPRess and BuddyPress are both activate and latest versions (WP is latest as well).

Viewing 13 replies - 1 through 13 (of 13 total)
  • @danbp

    Participant

    Hi,

    did you searched in bbPress ?
    plugins\bbpress\includes\extend\buddypress

    maybe you’ll find some answers there ?

    like bbp_add_group_id_to_forum() in extend/buddypress/functions.php

    @shanebp

    Moderator

    Have you looked at function groups_new_group_forum in bp-groups\bp-groups-forums.php ?

    @dimensionmedia

    Participant

    @shanebp – I have looked at that. function groups_new_group_forum is called by function groups_edit_group_settings which i’m calling. The “checkbox” for groups to have a forum is updated but no forum is created.

    Here’s the lines of code in groups_edit_group_settings() in bp-groups-functions.php

    
    	// If forums have been enabled, and a forum does not yet exist, we need to create one.
    	if ( $group->enable_forum ) {
    		if ( bp_is_active( 'forums' ) && !groups_get_groupmeta( $group->id, 'forum_id' ) ) {
    			groups_new_group_forum( $group->id, $group->name, $group->description );
    		}
    	}
    

    I believe the bp_is_active( ‘forums’ ) never is true for when my plugin calls it. Therefore the groups_new_group_forum never gets run. I tried calling the groups_new_group_forum directly but that doesn’t work either. Here’s the key part in groups_new_group_forum:


    $forum_id = bp_forums_new_forum( array(
    'forum_name' => $group_name,
    'forum_desc' => $group_desc
    ) );

    That bp_forums_new_forum doesn’t exist. So I could change my oringial code example above to this to illustrate the same problem (the result of the code below is ‘crapstop’ showing):


    function curgi_group_import_init() {

    if ( !function_exists('bp_forums_new_forum') ) { echo "crapstop"; exit; }

    }
    add_action( 'bp_loaded', 'curgi_group_import_init' );

    @dimensionmedia

    Participant

    Furthermore, I can create a group with my plugin WITH the “this groups has a forum” checkmark (but remember – my problem is that i can’t ACTUALLY create the forum). I can go into the “groups” area in the WP backend and simply edit the group and hit ‘update’ and WordPress DOES create the group. So it works there, but not in myplugin. I’m thinking that bbPress simply isn’t being loaded or activated prior to my plugin but I can’t figure it where or why.

    @shanebp

    Moderator

    What happens if you use a different hook ?

    function curgi_group_import_init() {
         if ( !function_exists('bp_forums_new_forum') ) { echo "crapstop"; exit; }
    }
    add_action( 'bp_ready', 'curgi_group_import_init', 20 );

    @dimensionmedia

    Participant

    @shanebp

    The change to ‘bp_ready’ gets past the “crapstop” but my plugin no longer shows up in the menu. Although i’ve always thought ‘bp_loaded’ was the proper hook here, for the moment i’ll take it.

    Here’s the full bit of code. Perhaps i’m not init the class properly here?


    function curgi_group_import_init() {

    if ( !function_exists('bp_forums_new_forum') ) { echo "crapstop"; exit; }

    buddypress()->curgi_group_import = new CurrikiGroupImport();

    }
    add_action( 'bp_ready', 'curgi_group_import_init', 20 );

    @shanebp

    Moderator

    You don’t need to load everything from one hook.

    Use bp_loaded hook in your plugin loader file.
    In that function, include or require one or more other files.
    In one of those files, use the bp_ready hook, and go from there.

    @dimensionmedia

    Participant

    @shanebp

    Thanks for the response. That in a nutshell is what i’m doing right now with the change you suggest. Loader.php loads the file that contains the code above via bp_loaded. Then i try to initialize my class CurrikiGroupImport. So it’s a chicken and egg thing – either I can init my class and get the plugin loaded and showing up in the WP admin menu and can’t get bbPress loaded first OR bbPress seems to load but my plugin doesn’t show up.

    If it helps, I can zip up a simple version of the plugin and assuming you have BP and BBPRESS loaded you can give it a spin.

    @shanebp

    Moderator

    Use bp_loaded to load the file that creates the class instance.
    Add the bp_ready hook in your class constructor.
    Something like:
    add_action( 'bp_ready', array( $this, 'curgi_group_something'), 99 );

    Timing issues can be tough.
    Kudos for trying to use BP native functions.
    If you’re in a hurry, you can always use the brute force approach and write some custom sql to insert a forum.

    @dimensionmedia

    Participant

    Thanks. Sadly this isn’t working out. I’m going to post this here in case someone can tinker with it (you’ll need BP and bbPress installed):

    https://dl.dropboxusercontent.com/u/14006840/curriki-group-import.zip

    Yeah, i’m trying to use the BP native functions and hooks. I have no problem with the BuddyPress flow – just when it comes to relying on bbPress to create the forums is when it falls apart.

    If anyone figures this out, i’ll throw them some PayPal change for some coffee. 🙂

    @dimensionmedia

    Participant

    BTW, thanks for the responses @shanebp @danbp

    @henrywright

    Moderator

    Hi @dimensionmedia

    I had a look at the .zip, in particular I looked at your class that extends BP_Component. I noticed you’re not registering it as an active component. So inside your constructor method after your call to parent::start(), you can do:

    $bp->active_components[$this->id] = '1';

    It may explain why things aren’t working because you seem to be bootstrapping your component properly. Actually (I’m now thinking out load), try dumping the $bp global just to make sure one of the global variables you’ve set shows up.

    @dimensionmedia

    Participant

    @henrywright

    Thanks but that didn’t seem to do much either. I even checked back to other BP_Component examples and i’m using the same hooks. I’m guessing this is something “weird” (or something i’m not aware of) with bbPress. I just went ahead and created the bbPress forum and connected it to the BP group in my plugin manually. I hate to do that – if bbPress decides to change something my plugin is going to be out of date, but such is life.

    Thanks for the attempts.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Trying To Get Access BBPress In My BuddyPress Plugin’ is closed to new replies.
Skip to toolbar