Home Forums Plugin Support WP User Frontend Pro Nickname, Display Name – Public Name

This topic is: not resolved

This topic contains 8 replies, has 2 voices, and was last updated by  strangerrj 6 years, 1 month ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1927

    strangerrj
    Participant
    Post count: 82

    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

    #1937

    Tareq Hasan
    Keymaster
    Post count: 2831

    Sorry, I didn't understand your question.

    #1939

    strangerrj
    Participant
    Post count: 82

    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

    #1941

    strangerrj
    Participant
    Post count: 82
    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>
    #1956

    strangerrj
    Participant
    Post count: 82

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

     

    Thanks and greetings

    #1958

    Tareq Hasan
    Keymaster
    Post count: 2831

    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.

    #1959

    strangerrj
    Participant
    Post count: 82

    Ah ok. Thanks.

    #1965

    Tareq Hasan
    Keymaster
    Post count: 2831

    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]

    #1966

    strangerrj
    Participant
    Post count: 82

    Super, thank you very much. Works beautifully.

    Greetings

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Nickname, Display Name – Public Name’ is closed to new replies.