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
2873            * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
2874            * 'domain_no_periods', 'sub_hyphen_limits', 'sub_invalid_chars', or no specific context.
2875            *
2876            * @since 2.8.0
2877            *
2878            * @param bool   $is_email Whether the email address has passed the is_email() checks. Default false.
2879            * @param string $email    The email address being checked.
2880            * @param string $context  Context under which the email was tested.
2881            */
2882           return apply_filters( 'is_email', false, $email, 'email_too_short' );
2883      }
2884
2885      // Test for an @ character after the first position
2886      if ( strpos( $email, '@', 1 ) === false ) {
2887           /** This filter is documented in wp-includes/formatting.php */
2888           return apply_filters( 'is_email', false, $email, 'email_no_at' );
2889      }
2890
2891      // Split out the local and domain parts
2892      list( $local, $domain ) = explode( '@', $email, 2 );
2893
2894      // LOCAL PART
2895      // Test for invalid characters
2896      if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
2897           /** This filter is documented in wp-includes/formatting.php */
2898           return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
2899      }
2900
2901      // DOMAIN PART
2902      // Test for sequences of periods
2903      if ( preg_match( '/\.{2,}/', $domain ) ) {
2904           /** This filter is documented in wp-includes/formatting.php */
2905           return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
2906      }
2907
2908      // Test for leading and trailing periods and whitespace
2909      if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
2910           /** This filter is documented in wp-includes/formatting.php */
2911           return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
2912      }
2913
2914      // Split the domain into subs
2915      $subs = explode( '.', $domain );
2916
2917      // Assume the domain will have at least two subs
2918      if ( 2 > count( $subs ) ) {
2919           /** This filter is documented in wp-includes/formatting.php */
2920           return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
2921      }
2922
2923      // Loop through each sub
2924      foreach ( $subs as $sub ) {
2925           // Test for leading and trailing hyphens and whitespace
2926           if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
2927                /** This filter is documented in wp-includes/formatting.php */
2928                return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
2929           }
2930
2931           // Test for invalid characters
2932           if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {
2933                /** This filter is documented in wp-includes/formatting.php */
2934                return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
2935           }
2936      }
2937
2938      // Congratulations your email made it!
2939      /** This filter is documented in wp-includes/formatting.php */
2940      return apply_filters( 'is_email', $email, $email, null );
2941 }
2942
2943 /**
2944  * Convert to ASCII from email subjects.
2945  *
2946  * @since 1.2.0
2947  *
2948  * @param string $string Subject line
2949  * @return string Converted string to ASCII