Nickname, Display Name – Public Name

This topic contains 8 reply and 2 voices, and was last updated by strangerrj 11 years ago
Viewing 8 Posts - 1 through 8 (of 8 total)
Author Posts
April 8, 2013 at 5:46 pm 1927
strangerrj Hi guys, I have to say that is not the nickname in the profile of the Public Name / Display Name of the user. Where can this be changed. As with everywhere eg. author postlink the display name.   Thank you cheers
April 8, 2013 at 7:40 pm 1937
Tareq Hasan Tareq Hasan

Sorry, I didn’t understand your question.

April 8, 2013 at 7:42 pm 1939
strangerrj strangerrj

Ok, in the profile, you can select the display name not the one that is shown to the public.

 

This is not the nickname.

 

In the free version it is installed. Nick and DisplayName.

 

Cheers

April 8, 2013 at 7:45 pm 1941
strangerrj strangerrj
Here is the code excerpt from the free version:
<tr>
<th><label for=”nickname”><?php _e( ‘Nickname’ ); ?> <span class=”description”><?php _e( ‘(required)’ ); ?></span></label></th>
<td><input type=”text” name=”nickname” id=”nickname” value=”<?php echo esc_attr( $profileuser->nickname ) ?>” class=”regular-text” /></td>
</tr>
<tr>
<th><label for=”display_name”><?php _e( ‘Display to Public as’ ) ?></label></th>
<td>
<select name=”display_name” id=”display_name”>
<?php
                                    $public_display = array();
                                    $public_display[‘display_username’] = $profileuser->user_login;
                                    $public_display[‘display_nickname’] = $profileuser->nickname;
                                    if ( !empty( $profileuser->first_name ) )
                                        $public_display[‘display_firstname’] = $profileuser->first_name;
                                    if ( !empty( $profileuser->last_name ) )
                                        $public_display[‘display_lastname’] = $profileuser->last_name;
                                    if ( !empty( $profileuser->first_name ) && !empty( $profileuser->last_name ) ) {
                                        $public_display[‘display_firstlast’] = $profileuser->first_name . ‘ ‘ . $profileuser->last_name;
                                        $public_display[‘display_lastfirst’] = $profileuser->last_name . ‘ ‘ . $profileuser->first_name;
                                    }
                                    if ( !in_array( $profileuser->display_name, $public_display ) ) // Only add this if it isn’t duplicated elsewhere
                                        $public_display = array(‘display_displayname’ => $profileuser->display_name) + $public_display;
                                    $public_display = array_map( ‘trim’, $public_display );
                                    $public_display = array_unique( $public_display );
                                    foreach ($public_display as $id => $item) {
                                        ?>
<option id=”<?php echo $id; ?>” value=”<?php echo esc_attr( $item ); ?><?php selected( $profileuser->display_name, $item ); ?>><?php echo $item; ?></option>
<?php
                                    }
                                    ?>
</select>
</td>
</tr>
April 9, 2013 at 9:48 am 1956
strangerrj strangerrj

Where can I find the form element button “Display Name”?

 

Thanks and greetings

April 9, 2013 at 9:55 am 1958
Tareq Hasan Tareq Hasan

The display name is not available in the form, but in can be done. Wait for a while, I’ll give you a code snippet that might solve your problem.

April 9, 2013 at 9:56 am 1959
strangerrj strangerrj

Ah ok. Thanks.

April 9, 2013 at 2:15 pm 1965
Tareq Hasan Tareq Hasan

Add a Action Hook field in your form and give the hook name as wpuf_user_display_name. Now insert this code in your themes functions.php

[php]
function wpuf_user_display_name() {
?>
<div class="wpuf-label">
<label for="user_display_name"><?php _e( ‘Display to Public as’ ) ?></label>
</div>

<div class="wpuf-fields">
<select name="user_display_name" id="user_display_name">
<?php
$profileuser = wp_get_current_user();
$public_display = array();
$public_display[‘display_username’] = $profileuser->user_login;
$public_display[‘display_nickname’] = $profileuser->nickname;

if ( !empty( $profileuser->first_name ) )
$public_display[‘display_firstname’] = $profileuser->first_name;

if ( !empty( $profileuser->last_name ) )
$public_display[‘display_lastname’] = $profileuser->last_name;

if ( !empty( $profileuser->first_name ) && !empty( $profileuser->last_name ) ) {
$public_display[‘display_firstlast’] = $profileuser->first_name . ‘ ‘ . $profileuser->last_name;
$public_display[‘display_lastfirst’] = $profileuser->last_name . ‘ ‘ . $profileuser->first_name;
}

if ( !in_array( $profileuser->display_name, $public_display ) ) {
$public_display = array(‘display_displayname’ => $profileuser->display_name) + $public_display;
}

$public_display = array_map( ‘trim’, $public_display );
$public_display = array_unique( $public_display );

foreach ($public_display as $id => $item) {
?>
<option id="<?php echo $id; ?>" value="<?php echo esc_attr( $item ); ?>"<?php selected( $profileuser->display_name, $item ); ?>><?php echo $item; ?></option>
<?php
}
?>
</select>
</div>
<?php
}

add_action(‘wpuf_user_display_name’, ‘wpuf_user_display_name’ );

function wpufe_save_display_name( $user_id ) {
if ( isset( $_POST[‘user_display_name’] ) ) {
wp_update_user( array( ‘ID’ => $user_id, ‘display_name’ => $_POST[‘user_display_name’] ) );
}
}

add_action( ‘wpuf_update_profile’, ‘wpufe_save_display_name’ );
[/php]

April 9, 2013 at 3:17 pm 1966
strangerrj strangerrj

Super, thank you very much. Works beautifully.

Greetings

Viewing 8 Posts - 1 through 8 (of 8 total)