Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: set default Role of new user


Andy Peatling
Keymaster

@apeatling

I did this on this site, and like this:

function register_user_as_contributor($username) {
global $bp, $wpdb;

$user_id = bp_core_get_userid_from_user_login( $username );

if ( !$user_id )
return false;

$role = maybe_unserialize( get_usermeta( $user_id, $wpdb->base_prefix . '1_capabilities' ) );

if ( is_array($role) )
$role = $role[0];

if ( !$role || '' == $role || 'subscriber' == $role ) {
$role['contributor'] = 1;

update_usermeta( $user_id, $wpdb->base_prefix . '1_capabilities', $role );
update_usermeta( $user_id, 'primary_blog', 1 );
update_usermeta( $user_id, 'source_domain', 'buddypress.org' );
}
}
add_action( 'wp_login', 'register_user_as_contributor' );

I’m sure there is another action you can use so it doesn’t run on every login, but this works.

Skip to toolbar