bbp_get_user_blog_role( int $user_id )

Return a user’s blog role

Description

Parameters

$user_id

(Required)

Return

(string)

Source

File: bp-forums/users/capabilities.php

function bbp_get_user_blog_role( $user_id = 0 ) {

	// Add Forums roles (returns $wp_roles global)
	bbp_add_forums_roles();

	// Validate user id
	$user_id = bbp_get_user_id( $user_id );
	$user    = get_userdata( $user_id );
	$role    = false;

	// User has roles so lets
	if ( ! empty( $user->roles ) ) {

		// Look for a non Forums role
		$roles     = array_intersect(
			array_values( $user->roles ),
			array_keys( bbp_get_blog_roles() )
		);

		// If there's a role in the array, use the first one. This isn't very
		// smart, but since roles aren't exactly hierarchical, and WordPress
		// does not yet have a UI for multiple user roles, it's fine for now.
		if ( !empty( $roles ) ) {
			$role = array_shift( $roles );
		}
	}

	return apply_filters( 'bbp_get_user_blog_role', $role, $user_id, $user );
}

Changelog

Changelog
Version Description
bbPress (r4446) 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.