Created
January 14, 2016 19:32
-
-
Save kisabelle/88a3847bbb3aea991fb1 to your computer and use it in GitHub Desktop.
WordPress Change Default Display Name Publicy As First Name Last Name for all existing users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Sets the user's display name (always) to first name last name, when it's avail. | |
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); | |
$display_name = $user->first_name . " " . $user->last_name; | |
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) ); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment