Created
August 26, 2016 15:24
-
-
Save kellenmace/497569bd0db68a3e8bba22874538db38 to your computer and use it in GitHub Desktop.
Check if user exists by ID in WordPress
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 | |
/** | |
* Does this user exist? | |
* | |
* @param int|string|WP_User $user_id User ID or object. | |
* @return bool Whether the user exists. | |
*/ | |
function km_does_user_exist( $user_id = '' ) { | |
if ( $user_id instanceof WP_User ) { | |
$user_id = $user_id->ID; | |
} | |
return (bool) get_user_by( 'id', $user_id ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment