is_email( string $email, bool $deprecated = false ): string|false
- Since
- 0.71
- Source
wp-includes/formatting.php:3542
Description
Does not grok i18n domains. Not RFC compliant.
Compatibility
- WordPress
- since 0.71
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$emailstring- Email address to verify.
$deprecatedbooloptional- Deprecated.Default:
false
Return value
string|false- Valid email address on success, false on failure.
Performance profile
How much work a call to is_email() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Light
- Scaling
- Scales with input
- Instructions
- 14–53
- Plugin surface
- 1 hook
- Called by
- 25
Touches nothing outside its own arguments.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 111.
Third-party callbacks on 'is_email' run inside this call, and their cost is not bounded by anything here.
25 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly
Further down the call graph this can also reach query, option, cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 6 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost is_email() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
empty($deprecated) | 14–18 | apply_filters() |
!empty($deprecated) | 18–22 | _deprecated_argument(), apply_filters() |
empty($deprecated) | 28–33 | explode(), apply_filters() |
!empty($deprecated) | 32–37 | _deprecated_argument(), explode(), apply_filters() |
empty($deprecated) && $local && !$domain && $domain === false | 41–49 | explode(), explode(), apply_filters() |
!empty($deprecated) && $local && !$domain && $domain === false | 45–53 | _deprecated_argument(), explode(), explode(), apply_filters() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 111 | 14–53 | 11 | |
| 8.5 | 111 | 14–53 | 11 | |
| 8.4 | 111 | 14–53 | 11 | 18 fewer instructions than PHP 8.3 |
| 8.3 | 129 | 14–71 | 11 | |
| 8.2 | 129 | 14–71 | 11 | |
| 8.1 | 129 | 14–71 | 11 | |
| 7.4 | 129 | 14–71 | 11 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 9
9 hooks fire while is_email() runs, in this order:
- apply_filters( is_email )filterline 3562 (+20 into the body)
Filters whether an email address is valid.
- apply_filters( is_email )filterline 3568 (+26 into the body)
Filters whether an email address is valid.
- apply_filters( is_email )filterline 3580 (+38 into the body)
Filters whether an email address is valid.
- apply_filters( is_email )filterline 3589 (+47 into the body)
Filters whether an email address is valid.
- apply_filters( is_email )filterline 3595 (+53 into the body)
Filters whether an email address is valid.
- apply_filters( is_email )filterline 3604 (+62 into the body)
Filters whether an email address is valid.
- apply_filters( is_email )filterline 3612 (+70 into the body)
Filters whether an email address is valid.
- apply_filters( is_email )filterline 3618 (+76 into the body)
Filters whether an email address is valid.
- apply_filters( is_email )filterline 3624 (+82 into the body)
Filters whether an email address is valid.
Uses · 2
- _deprecated_argument()Marks a function argument as deprecated and inform when it has been used.
- apply_filters()Calls the callback functions that have been added to a filter hook.
Used by · 25
- WP_Recovery_Mode_Email_Service::get_recovery_mode_email_address()Gets the email address to send the recovery mode link to.
- _wp_personal_data_handle_actions()Handle list table actions.
- edit_user()Edit user settings based on contents of $_POST
- get_user_id_from_string()Get a numeric user ID from either an email address or a login.
- newblog_notify_siteadmin()Notifies the network admin that a new site has been activated.
- newuser_notify_siteadmin()Notifies the network admin that a new user has been activated.
- populate_network()Populate network settings.
- register_new_user()Handles registering a new user.
- render_block_core_social_link()Renders the `core/social-link` block on server.
- rest_validate_value_from_schema()Validate a value based on a schema.
- sanitize_option()Sanitizes various option values based on the nature of the option.
- send_confirmation_on_profile_email()Sends a confirmation request email when a change of user email address is attempted.
Show all 25
- update_network_option_new_admin_email()Sends a confirmation request email when a change of network admin email address is attempted.
- update_option_new_admin_email()Sends a confirmation request email when a change of site admin email address is attempted.
- validate_email()Deprecated functionality to validate an email address.
- wp_ajax_wp_privacy_erase_personal_data()Handles erasing personal data via AJAX.
- wp_ajax_wp_privacy_export_personal_data()Handles exporting a user's personal data via AJAX.
- wp_authenticate_application_password()Authenticates the user using an application password.
- wp_authenticate_email_password()Authenticates a user using the email and password.
- wp_create_user_request()Creates and logs a user request to perform a specific action.
- wp_handle_comment_submission()Handles the submission of a comment, usually posted to wp-comments-post.php via a comment form.
- wp_mail()Sends an email, similar to PHP's mail function.
- wp_privacy_generate_personal_data_export_file()Generate the personal data export file.
- wp_xmlrpc_server::wp_newComment()Creates a new comment.
- wpmu_validate_user_signup()Sanitizes and validates data required for a user sign-up.
Source code
function is_email( $email, $deprecated = false ) { if ( ! empty( $deprecated ) ) { _deprecated_argument( __FUNCTION__, '3.0.0' ); } // Test for the minimum length the email can be. if ( strlen( $email ) < 6 ) { /** * Filters whether an email address is valid. * * This filter is evaluated under several different contexts, such as 'email_too_short', * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits', * 'domain_no_periods', 'sub_hyphen_limits', 'sub_invalid_chars', or no specific context. * * @since 2.8.0 * * @param string|false $is_email The email address if successfully passed the is_email() checks, false otherwise. * @param string $email The email address being checked. * @param string $context Context under which the email was tested. */ return apply_filters( 'is_email', false, $email, 'email_too_short' ); } // Test for an @ character after the first position. if ( false === strpos( $email, '@', 1 ) ) { /** This filter is documented in wp-includes/formatting.php */ return apply_filters( 'is_email', false, $email, 'email_no_at' ); } // Split out the local and domain parts. list( $local, $domain ) = explode( '@', $email, 2 ); /* * LOCAL PART * Test for invalid characters. */ if ( ! preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) { /** This filter is documented in wp-includes/formatting.php */ return apply_filters( 'is_email', false, $email, 'local_invalid_chars' ); } /* * DOMAIN PART * Test for sequences of periods. */ if ( preg_match( '/\.{2,}/', $domain ) ) { /** This filter is documented in wp-includes/formatting.php */ return apply_filters( 'is_email', false, $email, 'domain_period_sequence' ); } // Test for leading and trailing periods and whitespace. if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) { /** This filter is documented in wp-includes/formatting.php */ return apply_filters( 'is_email', false, $email, 'domain_period_limits' ); } // Split the domain into subs. $subs = explode( '.', $domain ); // Assume the domain will have at least two subs. if ( 2 > count( $subs ) ) { /** This filter is documented in wp-includes/formatting.php */ return apply_filters( 'is_email', false, $email, 'domain_no_periods' ); } // Loop through each sub. foreach ( $subs as $sub ) { // Test for leading and trailing hyphens and whitespace. if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) { /** This filter is documented in wp-includes/formatting.php */ return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' ); } // Test for invalid characters. if ( ! preg_match( '/^[a-z0-9-]+$/i', $sub ) ) { /** This filter is documented in wp-includes/formatting.php */ return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' ); } }Changelog
Introduced in 0.71. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/formatting.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.