Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check if user exists by ID in WordPress
<?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
You can’t perform that action at this time.