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