Skip to:
Content
Pages
Categories
Search
Top
Bottom

[RESOLVED] Programmatically creating a group


  • genotype
    Member

    @genotype

    Hi,
    Following the instructions on this blog I got the first part of creating a group in php down: http://danpolant.com/how-to-create-groups-in-buddypress-with-php/

        function create_a_group() {
    
    $new_group = new BP_Groups_Group;
    
    $new_group->creator_id = 1;
    $new_group->name = ‘test’;
    $new_group->slug = ‘test’;
    $new_group->description = ‘nothing’;
    $new_group->news = ‘whatever’;
    $new_group->status = ‘public’;
    $new_group->is_invitation_only = 1;
    $new_group->enable_wire = 1;
    $new_group->enable_forum = 1;
    $new_group->enable_photos = 1;
    $new_group->photos_admin_only = 1;
    $new_group->date_created = current_time(‘mysql’);
    $new_group->total_member_count = 1;
    $new_group->avatar_thumb = ‘some kind of path’;
    $new_group->avatar_full = ‘some kind of path’;
    
    $new_group -> save();
    
    groups_update_groupmeta( $id, ‘total_member_count’, 1 );
    groups_update_groupmeta( $id, ‘last_activity’, time() );
    groups_update_groupmeta( $id, ‘theme’, ‘buddypress’ );
    groups_update_groupmeta( $id, ‘stylesheet’, ‘buddypress’ );
    
    }
    

    I’m having trouble with the groups_update_groupmeta() function because I don’t know how to get the id ($id) of the group that was just created. The `$new_group -> save’ only returns a boolean, not the new id, as I had hoped. So how do I find $id?

Viewing 1 replies (of 1 total)

  • genotype
    Member

    @genotype

    I figured it out by going through a plugin that creates groups. The bottom part of the above code can be replaced with:

    	$saved = $new_group -> save();
    
    if ( $saved )
    {
    $id = $new_group->id;
    groups_update_groupmeta( $id, 'total_member_count', 1 );
    groups_update_groupmeta( $id, 'last_activity', time() );
    groups_update_groupmeta( $id, 'theme’, ‘buddypress' );
    groups_update_groupmeta( $id, 'stylesheet’, ‘buddypress' );
    
    } else {
    return false;
    }
    
Viewing 1 replies (of 1 total)
  • The topic ‘[RESOLVED] Programmatically creating a group’ is closed to new replies.
Skip to toolbar