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
3470            * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
3471            * 'domain_no_periods', 'sub_hyphen_limits', 'sub_invalid_chars', or no specific context.
3472            *
3473            * @since 2.8.0
3474            *
3475            * @param string|false $is_email The email address if successfully passed the is_email() checks, false otherwise.
3476            * @param string       $email    The email address being checked.
3477            * @param string       $context  Context under which the email was tested.
3478            */
3479           return apply_filters( 'is_email', false, $email, 'email_too_short' );
3480      }
3481
3482      // Test for an @ character after the first position.
3483      if ( strpos( $email, '@', 1 ) === false ) {
3484           /** This filter is documented in wp-includes/formatting.php */
3485           return apply_filters( 'is_email', false, $email, 'email_no_at' );
3486      }
3487
3488      // Split out the local and domain parts.
3489      list( $local, $domain ) = explode( '@', $email, 2 );
3490
3491      // LOCAL PART
3492      // Test for invalid characters.
3493      if ( ! preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
3494           /** This filter is documented in wp-includes/formatting.php */
3495           return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
3496      }
3497
3498      // DOMAIN PART
3499      // Test for sequences of periods.
3500      if ( preg_match( '/\.{2,}/', $domain ) ) {
3501           /** This filter is documented in wp-includes/formatting.php */
3502           return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
3503      }
3504
3505      // Test for leading and trailing periods and whitespace.
3506      if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
3507           /** This filter is documented in wp-includes/formatting.php */
3508           return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
3509      }
3510
3511      // Split the domain into subs.
3512      $subs = explode( '.', $domain );
3513
3514      // Assume the domain will have at least two subs.
3515      if ( 2 > count( $subs ) ) {
3516           /** This filter is documented in wp-includes/formatting.php */
3517           return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
3518      }
3519
3520      // Loop through each sub.
3521      foreach ( $subs as $sub ) {
3522           // Test for leading and trailing hyphens and whitespace.
3523           if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
3524                /** This filter is documented in wp-includes/formatting.php */
3525                return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
3526           }
3527
3528           // Test for invalid characters.
3529           if ( ! preg_match( '/^[a-z0-9-]+$/i', $sub ) ) {
3530                /** This filter is documented in wp-includes/formatting.php */
3531                return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
3532           }
3533      }
3534
3535      // Congratulations, your email made it!
3536      /** This filter is documented in wp-includes/formatting.php */
3537      return apply_filters( 'is_email', $email, $email, null );
3538 }
3539
3540 /**
3541  * Converts to ASCII from email subjects.
3542  *
3543  * @since 1.2.0
3544  *
3545  * @param string $string Subject line.
3546  * @return string Converted string to ASCII.