Advertisements

get_user_id_from_string

Definition:
function get_user_id_from_string( $string ) {}

Get a numeric user ID from either an email address or a login.

Parameters

  • string $string

Source code

function get_user_id_from_string( $string ) {

	$user_id = 0;

	if ( is_email( $string ) ) {

		$user = get_user_by('email', $string);

		if ( $user )

			$user_id = $user->ID;

	} elseif ( is_numeric( $string ) ) {

		$user_id = $string;

	} else {

		$user = get_user_by('login', $string);

		if ( $user )

			$user_id = $user->ID;

	}



	return $user_id;

}

1897

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: