Opened 16 years ago
Closed 16 years ago
#1724 closed defect (bug) (no action required)
Hardcoded table prefix in get_blog_role_for_user
| Reported by: |
|
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:
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; }