Skip to:
Content
Pages
Categories
Search
Top
Bottom

Create a bbp forum automatically with a BuddyPress group


  • itsasiak
    Participant

    @itsasiak

    Hi all,

    I hope you can help me. I am trying to create and attach a bbp forum automatically after a BuddyPress group is created.

    I have “unset” the BuddyPress group creation steps, and only the “group settings” step remains.

    I have been digging in bbp code to try to reproduce the forum creation process, and this is what I put together (though it is not working):

    <?php $bbpforum = new BBP_Forums_Group_Extension; ?>
    <?php $bbpforum->__construct(); ?>

    <!-- Reproducing parts of public edit_screen() -->

    <!-- Reproducing fieldset return -->

    <?php $_POST['bbp-edit-group-forum'] = true; ?> <!-- this comes from the edit screen; this form field is sent -->

    <!-- end of fieldset return -->

    <!-- start of edit_screen_save -->

    <?php

    if ( empty( $group_id ) ) {
    $group_id = bp_get_new_group_id();
    }

    $create_forum = true; // Changed this to true (there was a switch structure down and I kept the true case only
    $forum_id = 0;
    $forum_ids = bbp_get_group_forum_ids( $group_id );

    if ( !empty( $forum_ids ) )
    $forum_id = (int) is_array( $forum_ids ) ? $forum_ids[0] : $forum_ids;

    // Set the default forum status

    $status = bbp_get_public_status_id();

    // Create the initial forum
    $forum_id = bbp_insert_forum( array(
    'post_parent' => bbp_get_group_forums_root_id(),
    'post_title' => bp_get_new_group_name(),
    'post_content' => bp_get_new_group_description(),
    'post_status' => $status
    ) );

    // Run the BP-specific functions for new groups
    $bbpforum->new_forum( array( 'forum_id' => $forum_id ) );

    // Update forum active
    groups_update_groupmeta( bp_get_new_group_id(), '_bbp_forum_enabled_' . $forum_id, true );

    // Toggle forum on
    $bbpforum->toggle_group_forum( bp_get_new_group_id(), true );

    ?>

    It is placed in create.php, right after the create group form submission entry.

    As you see, I have erased the wp_nonce_field functions and the associated admin_referrer functions to avoid the “Are you sure you want to do this?” screen.

    If it is not clear, please, let me know what else would be needed to try get the automatic forum, and of course, if you know a better and easier way of doing it.

    Thank you very much!

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar