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
3535            * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
3536            * 'domain_no_periods', 'sub_hyphen_limits', 'sub_invalid_chars', or no specific context.
3537            *
3538            * @since 2.8.0
3539            *
3540            * @param string|false $is_email The email address if successfully passed the is_email() checks, false otherwise.
3541            * @param string       $email    The email address being checked.
3542            * @param string       $context  Context under which the email was tested.
3543            */
3544           return apply_filters( 'is_email', false, $email, 'email_too_short' );
3545      }
3546
3547      // Test for an @ character after the first position.
3548      if ( strpos( $email, '@', 1 ) === false ) {
3549           /** This filter is documented in wp-includes/formatting.php */
3550           return apply_filters( 'is_email', false, $email, 'email_no_at' );
3551      }
3552
3553      // Split out the local and domain parts.
3554      list( $local, $domain ) = explode( '@', $email, 2 );
3555
3556      /*
3557       * LOCAL PART
3558       * Test for invalid characters.
3559       */
3560      if ( ! preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
3561           /** This filter is documented in wp-includes/formatting.php */
3562           return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
3563      }
3564
3565      /*
3566       * DOMAIN PART
3567       * Test for sequences of periods.
3568       */
3569      if ( preg_match( '/\.{2,}/', $domain ) ) {
3570           /** This filter is documented in wp-includes/formatting.php */
3571           return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
3572      }
3573
3574      // Test for leading and trailing periods and whitespace.
3575      if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
3576           /** This filter is documented in wp-includes/formatting.php */
3577           return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
3578      }
3579
3580      // Split the domain into subs.
3581      $subs = explode( '.', $domain );
3582
3583      // Assume the domain will have at least two subs.
3584      if ( 2 > count( $subs ) ) {
3585           /** This filter is documented in wp-includes/formatting.php */
3586           return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
3587      }
3588
3589      // Loop through each sub.
3590      foreach ( $subs as $sub ) {
3591           // Test for leading and trailing hyphens and whitespace.
3592           if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
3593                /** This filter is documented in wp-includes/formatting.php */
3594                return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
3595           }
3596
3597           // Test for invalid characters.
3598           if ( ! preg_match( '/^[a-z0-9-]+$/i', $sub ) ) {
3599                /** This filter is documented in wp-includes/formatting.php */
3600                return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
3601           }
3602      }
3603
3604      // Congratulations, your email made it!
3605      /** This filter is documented in wp-includes/formatting.php */
3606      return apply_filters( 'is_email', $email, $email, null );
3607 }
3608
3609 /**
3610  * Converts to ASCII from email subjects.
3611  *
3612  * @since 1.2.0
3613  *
3614  * @param string $subject Subject line.
3615  * @return string Converted string to ASCII.