Forked from kellenmace/get-users-first-last-name-wordpress.php
Created
December 1, 2016 23:28
-
-
Save monecchi/fdaaddfc5accec484508eed3208239de to your computer and use it in GitHub Desktop.
Get User's First and Last Name in WordPress
This file contains hidden or 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 | |
/** | |
* Get user's first and last name, else just their first name, else their | |
* display name. Defalts to the current user if $user_id is not provided. | |
* | |
* @param mixed $user_id The user ID or object. Default is current user. | |
* @return string The user's name. | |
*/ | |
function km_get_users_name( $user_id = null ) { | |
$user_info = $user_id ? new WP_User( $user_id ) : wp_get_current_user(); | |
if ( $user_info->first_name ) { | |
if ( $user_info->last_name ) { | |
return $user_info->first_name . ' ' . $user_info->last_name; | |
} | |
return $user_info->first_name; | |
} | |
return $user_info->display_name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment