Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Format WordPress User's "Display Name" to Full Name on Login
- * ------------------------------------------------------------------------------
- */
- add_action( 'wp_login', 'wpse_9326315_format_user_display_name_on_login' );
- function wpse_9326315_format_user_display_name_on_login( $username ) {
- $user = get_user_by( 'login', $username );
- $first_name = get_user_meta( $user->ID, 'first_name', true );
- $last_name = get_user_meta( $user->ID, 'last_name', true );
- $full_name = trim( $first_name . ' ' . $last_name );
- if ( ! empty( $full_name ) && ( $user->data->display_name != $full_name ) ) {
- $userdata = array(
- 'ID' => $user->ID,
- 'display_name' => $full_name,
- );
- wp_update_user( $userdata );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement