Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: is_email

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 9 times in this file.

Line Code
3412            * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
3413            * 'domain_no_periods', 'sub_hyphen_limits', 'sub_invalid_chars', or no specific context.
3414            *
3415            * @since 2.8.0
3416            *
3417            * @param string|false $is_email The email address if successfully passed the is_email() checks, false otherwise.
3418            * @param string       $email    The email address being checked.
3419            * @param string       $context  Context under which the email was tested.
3420            */
3421           return apply_filters( 'is_email', false, $email, 'email_too_short' );
3422      }
3423
3424      // Test for an @ character after the first position.
3425      if ( strpos( $email, '@', 1 ) === false ) {
3426           /** This filter is documented in wp-includes/formatting.php */
3427           return apply_filters( 'is_email', false, $email, 'email_no_at' );
3428      }
3429
3430      // Split out the local and domain parts.
3431      list( $local, $domain ) = explode( '@', $email, 2 );
3432
3433      // LOCAL PART
3434      // Test for invalid characters.
3435      if ( ! preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
3436           /** This filter is documented in wp-includes/formatting.php */
3437           return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
3438      }
3439
3440      // DOMAIN PART
3441      // Test for sequences of periods.
3442      if ( preg_match( '/\.{2,}/', $domain ) ) {
3443           /** This filter is documented in wp-includes/formatting.php */
3444           return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
3445      }
3446
3447      // Test for leading and trailing periods and whitespace.
3448      if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
3449           /** This filter is documented in wp-includes/formatting.php */
3450           return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
3451      }
3452
3453      // Split the domain into subs.
3454      $subs = explode( '.', $domain );
3455
3456      // Assume the domain will have at least two subs.
3457      if ( 2 > count( $subs ) ) {
3458           /** This filter is documented in wp-includes/formatting.php */
3459           return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
3460      }
3461
3462      // Loop through each sub.
3463      foreach ( $subs as $sub ) {
3464           // Test for leading and trailing hyphens and whitespace.
3465           if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
3466                /** This filter is documented in wp-includes/formatting.php */
3467                return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
3468           }
3469
3470           // Test for invalid characters.
3471           if ( ! preg_match( '/^[a-z0-9-]+$/i', $sub ) ) {
3472                /** This filter is documented in wp-includes/formatting.php */
3473                return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
3474           }
3475      }
3476
3477      // Congratulations, your email made it!
3478      /** This filter is documented in wp-includes/formatting.php */
3479      return apply_filters( 'is_email', $email, $email, null );
3480 }
3481
3482 /**
3483  * Convert to ASCII from email subjects.
3484  *
3485  * @since 1.2.0
3486  *
3487  * @param string $string Subject line
3488  * @return string Converted string to ASCII