Title: get_user_id_from_string
Published: April 25, 2014
Last modified: February 24, 2026

---

# get_user_id_from_string( string $email_or_login ): int

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#wp--skip-link--target)

This function has been deprecated since 3.6.0. Use [get_user_by()](https://developer.wordpress.org/reference/functions/get_user_by/)
instead.

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

## 󠀁[Description](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#description)󠁿

A numeric string is considered to be an existing user ID and is simply returned 
as such.

### 󠀁[See also](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#see-also)󠁿

 * [get_user_by()](https://developer.wordpress.org/reference/functions/get_user_by/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#parameters)󠁿

 `$email_or_login`stringrequired

Either an email address or a login.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#return)󠁿

 int

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#source)󠁿

    ```php
    function get_user_id_from_string( $email_or_login ) {
    	_deprecated_function( __FUNCTION__, '3.6.0', 'get_user_by()' );

    	if ( is_email( $email_or_login ) )
    		$user = get_user_by( 'email', $email_or_login );
    	elseif ( is_numeric( $email_or_login ) )
    		return $email_or_login;
    	else
    		$user = get_user_by( 'login', $email_or_login );

    	if ( $user )
    		return $user->ID;
    	return 0;
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/ms-deprecated.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/ms-deprecated.php#L342)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/ms-deprecated.php#L342-L355)

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#related)󠁿

| Uses | Description | 
| [is_email()](https://developer.wordpress.org/reference/functions/is_email/)`wp-includes/formatting.php` |

Verifies that an email is valid.

  | 
| [get_user_by()](https://developer.wordpress.org/reference/functions/get_user_by/)`wp-includes/pluggable.php` |

Retrieves user info by a given field.

  | 
| [_deprecated_function()](https://developer.wordpress.org/reference/functions/_deprecated_function/)`wp-includes/functions.php` |

Marks a function as deprecated and inform when it has been used.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_user_id_from_string/?output_format=md#changelog)󠁿

| Version | Description | 
| [3.6.0](https://developer.wordpress.org/reference/since/3.6.0/) | Deprecated. Use [get_user_by()](https://developer.wordpress.org/reference/functions/get_user_by/)  | 
| [MU (3.0.0)](https://developer.wordpress.org/reference/since/mu.3.0.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_user_id_from_string%2F)
before being able to contribute a note or feedback.