Skip to:
Content

bbPress.org


Ignore:
Timestamp:
12/31/2012 01:21:33 PM (13 years ago)
Author:
johnjamesjacoby
Message:

Nicename Usage:

  • Introduce template tags for getting and displaying a user nicenames. Helpful for themes that want easier access to @mentions data.
  • Improve mention filters to use 'slug' instead of 'login.' Fixes possible mismatches when login and nicename are different.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/includes/users/template-tags.php

    r4617 r4672  
    241241
    242242        return apply_filters( 'bbp_get_user_profile_link', $user_link, $user_id );
     243    }
     244
     245/**
     246 * Output a users nicename to the screen
     247 *
     248 * @since bbPress (r4671)
     249 *
     250 * @param int $user_id User ID whose nicename to get
     251 * @param array $args before|after|user_id|force
     252 */
     253function bbp_user_nicename( $user_id = 0, $args = array() ) {
     254    echo bbp_get_user_nicename( $user_id, $args );
     255}
     256    /**
     257     * Return a users nicename to the screen
     258     *
     259     * @since bbPress (r4671)
     260     *
     261     * @param int $user_id User ID whose nicename to get
     262     * @param array $args before|after|user_id|force
     263     * @return string User nicename, maybe wrapped in before/after strings
     264     */
     265    function bbp_get_user_nicename( $user_id = 0, $args = array() ) {
     266
     267        // Bail if no user ID passed
     268        $user_id = bbp_get_user_id( $user_id, false, false );
     269        if ( empty( $user_id ) )
     270            return false;
     271
     272        // Parse default arguments
     273        $r = bbp_parse_args( $args, array(
     274            'user_id' => $user_id,
     275            'before'  => '',
     276            'after'   => '',
     277            'force'   => ''
     278        ), 'get_user_nicename' );
     279
     280        // Get the user data and nicename
     281        if ( empty( $r['force'] ) ) {
     282            $user     = get_userdata( $user_id );
     283            $nicename = $user->user_nicename;
     284
     285        // Force the nicename to something else
     286        } else {
     287            $nicename = (string) $r['force'];
     288        }
     289
     290        // Maybe wrap the nicename
     291        $retval = !empty( $nicename ) ? ( $r['before'] . $nicename . $r['after'] ) : '';
     292
     293        // Filter and return
     294        return (string) apply_filters( 'bbp_get_user_nicename', $retval, $user_id, $args );
    243295    }
    244296
     
    290342            // Get username if not passed
    291343            if ( empty( $user_nicename ) ) {
    292                 $user = get_userdata( $user_id );
    293                 if ( !empty( $user->user_nicename ) ) {
    294                     $user_nicename = $user->user_nicename;
    295                 }
     344                $user_nicename = bbp_get_user_nicename( $user_id );
    296345            }
    297346
Note: See TracChangeset for help on using the changeset viewer.