BuddyPress: hook to add new profile fields and groups

Well seems like not many people are digging into BP so here is the solution I found.

To add a new field group using BP hooks:

// Create new Field Group       
$group_args = array(
     'name' => 'Social Networks'
     );
$group_id = xprofile_insert_field_group( $group_args ); // group's ID

To add some fields to this new group:

// Insert New Field
xprofile_insert_field(
    array (
           field_group_id  => $group_id,
           name            => 'Twitter',
           can_delete      => false, // Doesn't work *
           field_order  => 1,
           is_required     => false,
           type            => 'textbox'
    )
);

I think there is currently a bug in BP. can_delete = 0 means you cannot delete something (ie field or group), but no matter what you pass to xprofile_insert_field() it is going to be can_delete = 1.

Leave a Comment