bbp_edit_user_display_name()

Drop down for selecting the user’s display name

Description

Source

File: bp-forums/users/template.php

1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
function bbp_edit_user_display_name() {
    $bbp            = bbpress();
    $public_display = array();
    $public_display['display_username'] = $bbp->displayed_user->user_login;
 
    if ( !empty( $bbp->displayed_user->nickname ) )
        $public_display['display_nickname']  = $bbp->displayed_user->nickname;
 
    if ( !empty( $bbp->displayed_user->first_name ) )
        $public_display['display_firstname'] = $bbp->displayed_user->first_name;
 
    if ( !empty( $bbp->displayed_user->last_name ) )
        $public_display['display_lastname']  = $bbp->displayed_user->last_name;
 
    if ( !empty( $bbp->displayed_user->first_name ) && !empty( $bbp->displayed_user->last_name ) ) {
        $public_display['display_firstlast'] = $bbp->displayed_user->first_name . ' ' . $bbp->displayed_user->last_name;
        $public_display['display_lastfirst'] = $bbp->displayed_user->last_name  . ' ' . $bbp->displayed_user->first_name;
    }
 
    if ( !in_array( $bbp->displayed_user->display_name, $public_display ) ) // Only add this if it isn't duplicated elsewhere
        $public_display = array( 'display_displayname' => $bbp->displayed_user->display_name ) + $public_display;
 
    $public_display = array_map( 'trim', $public_display );
    $public_display = array_unique( $public_display ); ?>
 
    <select name="display_name" id="display_name">
 
    <?php foreach ( $public_display as $id => $item ) : ?>
 
        <option id="<?php echo $id; ?>" value="<?php echo esc_attr( $item ); ?>"<?php selected( $bbp->displayed_user->display_name, $item ); ?>><?php echo $item; ?></option>
 
    <?php endforeach; ?>
 
    </select>
 
<?php
}

Changelog

Changelog
Version Description
bbPress (r2688) Introduced.

Questions?

We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.