Skip to:
Content

bbPress.org

Changeset 4793


Ignore:
Timestamp:
03/07/2013 10:58:31 PM (8 years ago)
Author:
johnjamesjacoby
Message:

Introduce bbp_get_dynamic_role_name() to handle getting a translated role name from the dynamic roles array. Use this to return a more accurate display role in bbp_get_user_display_role(). Hat tip alex-ye. Fixes #2248.

Location:
trunk/includes
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/core/capabilities.php

    r4753 r4793  
    441441
    442442/**
     443 * Gets a translated role name from a role ID
     444 *
     445 * @since bbPress (r4792)
     446 *
     447 * @param string $role_id
     448 * @return string Translated role name
     449 */
     450function bbp_get_dynamic_role_name( $role_id = '' ) {
     451    $roles = bbp_get_dynamic_roles();
     452    $role  = isset( $roles[$role_id] ) ? $roles[$role_id]['name'] : '';
     453
     454    return apply_filters( 'bbp_get_dynamic_role_name', $role, $role_id, $roles );
     455}
     456
     457/**
    443458 * Removes the bbPress roles from the editable roles array
    444459 *
  • trunk/includes/users/template-tags.php

    r4783 r4793  
    483483        $user_id = bbp_get_user_id( $user_id, false, false );
    484484
    485         // Capes earn Vinz Clortho status
    486         if ( bbp_is_user_keymaster( $user_id ) ) {
    487             $role = __( 'Key Master', 'bbpress' );
    488 
    489         // Inactive
    490         } elseif ( bbp_is_user_inactive() ) {
     485        // User is not registered
     486        if ( empty( $user_id ) ) {
     487            $role = __( 'Guest', 'bbpress' );
     488
     489        // User is not active
     490        } elseif ( bbp_is_user_inactive( $user_id ) ) {
    491491            $role = __( 'Inactive', 'bbpress' );
    492492
    493         // User is not registered
    494         } elseif ( empty( $user_id ) ) {
    495             $role = __( 'Guest', 'bbpress' );
    496 
    497         // Moderator
    498         } elseif ( user_can( $user_id, 'moderate' ) ) {
    499             $role = __( 'Moderator', 'bbpress' );
    500 
    501         // Participant
    502         } elseif ( user_can( $user_id, 'participate' ) ) {
    503             $role = __( 'Participant', 'bbpress' );
    504 
    505         // Anyone else
     493        // User have a role
    506494        } else {
     495            $role_id = bbp_get_user_role( $user_id );
     496            $role    = bbp_get_dynamic_role_name( $role_id );
     497        }
     498
     499        // No role found so default to generic "Member"
     500        if ( empty( $role ) ) {
    507501            $role = __( 'Member', 'bbpress' );
    508502        }
Note: See TracChangeset for help on using the changeset viewer.