Group photograph of 13 young men in dark suits

Create Groups in BuddyPress Programmatically

Let’s say that you that you are building a custom application with BuddyPress (like maybe a Project Management application) and you had a need to programmatically create a BuddyPress group. Now there are ways to customize the BuddyPress group creation process that I will cover in a future post, but there is actually a very simple function that will do all the heavy lifting. So, without any further ado, I’d like to introduce you to groups_create_group().

groups_create_group()

Defined on line 83 of bp-groups-functions.php, groups_create_group() does exactly what you would think that it would; it creates a new BuddyPress group with the provided parameters and returns the ID of the newly created group. Let’s take a look at the default arguments for this function and then step through each.

/BuddyPress/blob/master/src/bp-groups/bp-groups-functions.php
85
86
87
88
89
90
91
92
93
94
	$defaults = array(
		'group_id'     => 0,
		'creator_id'   => 0,
		'name'         => '',
		'description'  => '',
		'slug'         => '',
		'status'       => 'public',
		'enable_forum' => 0,
		'date_created' => bp_core_current_time()
	);

group_id

Use this parameter to define a group to update. Yes that’s right, you can use groups_create_group() to update an existing group.

Required: no
Default: 0, create a new group.

creator_id

The id of the user to be used as the group creator.

Required: no
Default: 0, uses the currently logged in user.

name

The name of the new group to be created.

Required: yes
Default: ”

description

A description for the new group.

Required: no
Default: ”

slug

The unique slug to be used for this group.

Required: no
Default: ”, will auto calculate based off of the group name

status

The visibility of the group. Valid options are ‘public’, ‘private’, or ‘hidden’ as defined on line 342 of bp-groups-loader.php.

Required: no
Default: ‘public’

enable_forum

Whether or not this group supports a forum. Use 1 for yes and 0 for no. Note: this will not create a forum for the group. In order to do that, use groups_new_group_forum()

Required: no
Default: 0

date_created

The date to log as the group creation date.

Required: no
Default: bp_core_current_time()


I hope this has been helpful to you! If you have any questions or corrections, please leave a comment below.

Jean Weil in ABC studio making international phone call

Have You Heard of BuddyPress?

Last year I was working on a new membership feature for my church’s website (actually, I’m still working on it) that would help to facilitate interaction among the churchgoers throughout the week. Being a hard core developer, I rolled up my sleeves and started working through how I would handle discussions, notifications, user profiles, and the like. After spending a few weeks of weekends and evenings hacking on it I decided to check and see what kind of prebuilt solution for this kind of application might already exist (yes this is the problem with developers: code now – research later). Read more

President Franklin D. Roosevelt aboard train: Jacksonville, Florida

Do Not Fear the Command Line

A year and a half ago and the Mac terminal scared me spitless. I didn’t know how to do anything with it and I didn’t know of anything that I really wanted to do with it. Then I started working with Vagrant, and then Git, and then Grunt, and pretty soon the command line didn’t seem so frightening any more. In fact, once I got down a few basic commands I started helping with server administration and other command liney things at the agency I worked for. Read more

Grayson, Westley, Stanislaus County, Western San Joaquin Valley, California. Seventh and eighth grad . . .

WPSessions VIP Enrollment Opens

I just received an email from Brian at WPSessions with the word that WPSessions VIP is now taking enrollments. This signup period will be limited to the first 100 enrollees so if you want to signup then you need to act right away. Here’s the cool part, even if you didn’t sign up for the WPSessions VIP waiting list, you can still use my referral link to secure a spot!

One other thing. Use the coupon code FIRST100 get $50 dollars off of your subscription reducing the price from $247 to $197. But again, you must move quickly because the offer is only valid for the next 48 hours or first 100 enrollees.

I just enrolled and hope to see you in WPSessions also!

Get Schooled

A Better Developer via WPSessions

This past week I attended WordCamp Seattle and boy was it amazing! One of my favorite sessions was a panel on Becoming a Better WordPress Developer. During this session, the panel was asked how a developer could become a better developer. The general consensus was to surround yourself with professionals in your field that constantly push you and introduce you to new tools and techniques.

I wholeheartedly agree, but this is somewhat of an abstract idea if you don’t know where to find the professionals in your field, specifically in this case WordPress development. WordCamps are a great place to find these people, but wouldn’t it be great if there was a place to find out about new leaders and stay up to date on a regular basis?

WPSessions

Enter WPSessions

I found out about WPSessions several months ago and promptly signed up for the WordPress and Backbone.js session and it was fantastic! Most recently I signed up for Working with BuddyPress and look forward to watching the recording since I missed it live because of WordCamp Seattle. Read more