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.

  • Action hooks look like this: do_action( "hook_name" )
  • Filter hooks look like this: apply_filters( "hook_name", "what_to_filter" ).

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