bp_set_current_user_default_role()

Set a default role for the current user.

Description

Give a user the default role when creating content on a site they do not already have a role or capability on.

Source

File: bp-core/bp-core-caps.php

function bp_set_current_user_default_role() {

	// Bail if not multisite or not root blog.
	if ( ! is_multisite() || ! bp_is_root_blog() ) {
		return;
	}

	// Bail if user is not logged in or already a member.
	if ( ! is_user_logged_in() || is_user_member_of_blog() ) {
		return;
	}

	// Bail if user is not active.
	if ( bp_is_user_inactive() ) {
		return;
	}

	// Set the current users default role.
	buddypress()->current_user->set_role( bp_get_option( 'default_role', 'subscriber' ) );
}

Changelog

Changelog
Version Description
BuddyPress 1.6.0 Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.