Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: How To bp_set_member_type?

@henrywright

Moderator

Hi @youmin

If you don’t already have your roles set-up then this is how you’d add them:

add_role(
    'student',
    __( 'Student' ),
    array(
        'read'         => true,  // true allows this capability
        'edit_posts'   => true,
        'delete_posts' => false, // Use false to explicitly deny
    )
);

The 3rd parameter is where you’d put your capabilities. In my example above, I’ve created a ‘student’ role which can read and edit posts but can’t delete posts. Feel free to amend these capabilities.

Ref: https://codex.wordpress.org/Function_Reference/add_role

Then to pick up on Boone’s suggestion in the Trac ticket, you could do this:

function youmin_set_role( $user_id, $member_type, $append ) {
    $userdata = array( 'ID' => $user_id, 'role' => $member_type );
    wp_update_user( $userdata );
}
add_action( 'bp_set_member_type', 'youmin_set_role', 10, 3 );

When you use the bp_set_member_type() function like I have done here, this code will assign a role to the user who is signing up. The role that is assigned will be the type you use in bp_set_member_type().

Hope this helps you.

Skip to toolbar