[buddypress-trac] [BuddyPress] #1724: Hardcoded table prefix in get_blog_role_for_user

buddypress-trac at lists.automattic.com buddypress-trac at lists.automattic.com
Fri Jan 29 00:15:35 UTC 2010


#1724: Hardcoded table prefix in get_blog_role_for_user
------------------------+---------------------------------------------------
Reporter:  garrettmoon  |       Owner:     
    Type:  defect       |      Status:  new
Priority:  minor        |   Milestone:     
Keywords:               |  
------------------------+---------------------------------------------------
 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( $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;
 }

-- 
Ticket URL: <http://trac.buddypress.org/ticket/1724>
BuddyPress <http://buddypress.org/>
BuddyPress


More information about the buddypress-trac mailing list