WordPress Plugin to change Display name as first name and capital letter of second name



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) );
}
}

?>

Done with the help of following threads:
1. http://stackoverflow.com/questions/9326315/wordpress-change-default-display-name-publicy-as-for-all-existing-users
2. http://wordpress.org/support/topic/change-default-display-name-1

Leave a Reply