Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellenmace/497569bd0db68a3e8bba22874538db38 to your computer and use it in GitHub Desktop.
Save kellenmace/497569bd0db68a3e8bba22874538db38 to your computer and use it in GitHub Desktop.
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