Opened 15 years ago
Closed 15 years ago
#1724 closed defect (bug) (no action required)
Hardcoded table prefix in get_blog_role_for_user
Reported by: | 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;
}
whoops, forgot to put that in a code block: