Skip to:
Content

BuddyPress.org

Opened 14 years ago

Closed 14 years ago

#1724 closed defect (bug) (no action required)

Hardcoded table prefix in get_blog_role_for_user

Reported by: garrettmoon's profile garrettmoon Owned by:
Milestone: Priority: minor
Severity: Version:
Component: Core Keywords:
Cc:

Description

get_blog_role_for_user in bp-core-adminbar uses a hardcoded table prefix to get a users role from the db. Problem is not every install uses the default wp_ prefix. This function should work:

function get_blog_role_for_user( $user, $blog ) {

global $wpdb, $current_blog;

If the user is a site admin, just display admin.
if ( is_site_admin() )

return ( 'Admin', 'buddypress');


$root_prefix = preg_replace('/' . preg_quote($current_blog->blog_id . '_', '/') . '$/', , $wpdb->prefix);

$roles = get_usermeta( $user, $root_prefix . $blog . '_capabilities' );

if ( isset( $rolessubscriber? ) )

$role = ( 'Subscriber', 'buddypress' );

elseif ( isset( $rolescontributor? ) )

$role = ( 'Contributor', 'buddypress' );

elseif ( isset( $rolesauthor? ) )

$role = ( 'Author', 'buddypress' );

elseif ( isset( $roleseditor? ) )

$role = ( 'Editor', 'buddypress' );

elseif ( isset( $rolesadministrator? ) )

$role = ( 'Admin', 'buddypress' );

else

return false;

return $role;

}

Change History (2)

#1 @garrettmoon
14 years ago

whoops, forgot to put that in a code block:

function get_blog_role_for_user( $user, $blog ) {

	global $wpdb, $current_blog;

	// If the user is a site admin, just display admin.
	if ( is_site_admin() )
		return __( 'Admin', 'buddypress');
		
	$root_prefix = preg_replace('/' . preg_quote($current_blog->blog_id . '_', '/') . '$/', '', $wpdb->prefix);

	$roles = get_usermeta( $user, $root_prefix . $blog . '_capabilities' );

	if ( isset( $roles['subscriber'] ) )
		$role = __( 'Subscriber', 'buddypress' );
	elseif	( isset( $roles['contributor'] ) )
		$role = __( 'Contributor', 'buddypress' );
	elseif	( isset( $roles['author'] ) )
		$role = __( 'Author', 'buddypress' );
	elseif ( isset( $roles['editor'] ) )
		$role = __( 'Editor', 'buddypress' );
	elseif ( isset( $roles['administrator'] ) )
		$role = __( 'Admin', 'buddypress' );
	else
		return false;

	return $role;
}

#2 @r-a-y
14 years ago

  • Component set to Core
  • Resolution set to invalid
  • Status changed from new to closed

Blog roles were dropped in changeset [2394]. So this is no longer valid.

Note: See TracTickets for help on using tickets.