Skip to:
Content

bbPress.org


Ignore:
Timestamp:
05/01/2012 10:08:50 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Add template tags and supporting functions to display user role in topics and replies. Fixes #1815. Props cnorris23 for original patch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-includes/bbp-user-functions.php

    r3856 r3860  
    14001400}
    14011401
     1402/**
     1403 * Return a user's main role
     1404 *
     1405 * @since bbPress (r3860)
     1406 *
     1407 * @param int $user_id
     1408 * @uses bbp_get_user_id() To get the user id
     1409 * @uses get_userdata() To get the user data
     1410 * @uses apply_filters() Calls 'bbp_get_user_role' with the
     1411 *                        role and user id
     1412 * @return string
     1413 */
     1414function bbp_get_user_role( $user_id = 0 ) {
     1415
     1416    // Validate user id
     1417    $user_id = bbp_get_user_id( $user_id, false, false );
     1418    if ( empty( $user_id ) )
     1419        return false;
     1420
     1421    // Get userdata
     1422    $user = get_userdata( $user_id );
     1423
     1424    // Get the user's main role
     1425    $role = isset( $user->roles ) ? array_shift( $user->roles ) : bbp_get_anonymous_role();
     1426
     1427    return apply_filters( 'bbp_get_user_role', $role, $user_id, $user );
     1428}
     1429
    14021430/** Premissions ***************************************************************/
    14031431
Note: See TracChangeset for help on using the changeset viewer.