• I have a little problem. I would like to show in my comments nickname of user and its full name. Something like this:

    Nickname (@First_name Last_name)
    or just
    Nickname (@Full_name)

    Is it possible? I dont know what to edit, please help me

    Thank you very much

Viewing 1 replies (of 1 total)
  • Thread Starter eldenroot

    (@eldenroot)

    OK, I found this – it shows first name and first letter of last name… please can you edit this and add there the nickname and show full name instead of first letter?

    /*
    Plugin Name: Substitute Displayname
    Version: 0.1
    Description: Substitutes a default Display name for new registrants and existing users.
    Author: Author name
    */
    ?>
    /* Version check */
    global $wp_version;
    $exit_msg='Substitute Author requires WordPress 2.5 or newer. Please update!';
    if (version_compare($wp_version,"2.5","<")) {
    exit ($exit_msg);
    }
    function sd_new_login_filter ($login) {
    /* Don't do anything to login, just see if already in database.*/
    global $wpdb, $sd_is_new_login;
    
    $id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_login = '$login'");
    $sd_is_new_login = (isset($id)) ? false : true;
    return $login;
    }
    
    function sd_substitute_displayname_filter ($display_name) {
    global $sd_is_new_login;
    
    if ($sd_is_new_login){
    $first_letter = substr($_POST['last_name'], 0, 1);
    $display_name = $_POST['first_name']." ".$first_letter;
    }
    return $display_name;
    }
    add_filter('pre_user_login', 'sd_new_login_filter');
    add_filter('pre_user_display_name', 'sd_substitute_displayname_filter');
    add_action ('admin_head','make_display_name_f_name_last_name');
    function make_display_name_f_name_last_name(){
    
    $users = get_users(array('fields'=>'all'));
    
    foreach($users as $user){
    $user = get_userdata($user->ID);
    $firstletter = substr($user->last_name, 0, 1);
    $display_name = $user->first_name . " " . $firstletter;
    
    if($display_name!=' ') wp_update_user( array ('ID' => $user->ID, 'display_name' => $display_name) );
    else wp_update_user( array ('ID' => $user->ID, 'display_name' => $user->display_login) );
    
    if($user->display_name == '')
    wp_update_user( array ('ID' => $user->ID, 'display_name' => $user->display_login) );
    }
    }
    
    ?
Viewing 1 replies (of 1 total)
  • The topic ‘Show full name in comments with nickname together’ is closed to new replies.