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
3562            * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
3563            * 'domain_no_periods', 'sub_hyphen_limits', 'sub_invalid_chars', or no specific context.
3564            *
3565            * @since 2.8.0
3566            *
3567            * @param string|false $is_email The email address if successfully passed the is_email() checks, false otherwise.
3568            * @param string       $email    The email address being checked.
3569            * @param string       $context  Context under which the email was tested.
3570            */
3571           return apply_filters( 'is_email', false, $email, 'email_too_short' );
3572      }
3573
3574      // Test for an @ character after the first position.
3575      if ( strpos( $email, '@', 1 ) === false ) {
3576           /** This filter is documented in wp-includes/formatting.php */
3577           return apply_filters( 'is_email', false, $email, 'email_no_at' );
3578      }
3579
3580      // Split out the local and domain parts.
3581      list( $local, $domain ) = explode( '@', $email, 2 );
3582
3583      /*
3584       * LOCAL PART
3585       * Test for invalid characters.
3586       */
3587      if ( ! preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
3588           /** This filter is documented in wp-includes/formatting.php */
3589           return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
3590      }
3591
3592      /*
3593       * DOMAIN PART
3594       * Test for sequences of periods.
3595       */
3596      if ( preg_match( '/\.{2,}/', $domain ) ) {
3597           /** This filter is documented in wp-includes/formatting.php */
3598           return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
3599      }
3600
3601      // Test for leading and trailing periods and whitespace.
3602      if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
3603           /** This filter is documented in wp-includes/formatting.php */
3604           return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
3605      }
3606
3607      // Split the domain into subs.
3608      $subs = explode( '.', $domain );
3609
3610      // Assume the domain will have at least two subs.
3611      if ( 2 > count( $subs ) ) {
3612           /** This filter is documented in wp-includes/formatting.php */
3613           return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
3614      }
3615
3616      // Loop through each sub.
3617      foreach ( $subs as $sub ) {
3618           // Test for leading and trailing hyphens and whitespace.
3619           if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
3620                /** This filter is documented in wp-includes/formatting.php */
3621                return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
3622           }
3623
3624           // Test for invalid characters.
3625           if ( ! preg_match( '/^[a-z0-9-]+$/i', $sub ) ) {
3626                /** This filter is documented in wp-includes/formatting.php */
3627                return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
3628           }
3629      }
3630
3631      // Congratulations, your email made it!
3632      /** This filter is documented in wp-includes/formatting.php */
3633      return apply_filters( 'is_email', $email, $email, null );
3634 }
3635
3636 /**
3637  * Converts to ASCII from email subjects.
3638  *
3639  * @since 1.2.0
3640  *
3641  * @param string $subject Subject line.
3642  * @return string Converted string to ASCII.