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
1988            * 'domain_no_periods', 'sub_hyphen_limits', 'sub_invalid_chars', or no specific context.
1989            *
1990            * @since 2.8.0
1991            *
1992            * @param bool   $is_email Whether the email address has passed the is_email() checks. Default false.
1993            * @param string $email    The email address being checked.
1994            * @param string $message  An explanatory message to the user.
1995            * @param string $context  Context under which the email was tested.
1996            */
1997           return apply_filters( 'is_email', false, $email, 'email_too_short' );
1998      }
1999
2000      // Test for an @ character after the first position
2001      if ( strpos( $email, '@', 1 ) === false ) {
2002           /** This filter is documented in wp-includes/formatting.php */
2003           return apply_filters( 'is_email', false, $email, 'email_no_at' );
2004      }
2005
2006      // Split out the local and domain parts
2007      list( $local, $domain ) = explode( '@', $email, 2 );
2008
2009      // LOCAL PART
2010      // Test for invalid characters
2011      if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
2012           /** This filter is documented in wp-includes/formatting.php */
2013           return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
2014      }
2015
2016      // DOMAIN PART
2017      // Test for sequences of periods
2018      if ( preg_match( '/\.{2,}/', $domain ) ) {
2019           /** This filter is documented in wp-includes/formatting.php */
2020           return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
2021      }
2022
2023      // Test for leading and trailing periods and whitespace
2024      if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
2025           /** This filter is documented in wp-includes/formatting.php */
2026           return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
2027      }
2028
2029      // Split the domain into subs
2030      $subs = explode( '.', $domain );
2031
2032      // Assume the domain will have at least two subs
2033      if ( 2 > count( $subs ) ) {
2034           /** This filter is documented in wp-includes/formatting.php */
2035           return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
2036      }
2037
2038      // Loop through each sub
2039      foreach ( $subs as $sub ) {
2040           // Test for leading and trailing hyphens and whitespace
2041           if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
2042                /** This filter is documented in wp-includes/formatting.php */
2043                return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
2044           }
2045
2046           // Test for invalid characters
2047           if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {
2048                /** This filter is documented in wp-includes/formatting.php */
2049                return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
2050           }
2051      }
2052
2053      // Congratulations your email made it!
2054      /** This filter is documented in wp-includes/formatting.php */
2055      return apply_filters( 'is_email', $email, $email, null );
2056 }
2057
2058 /**
2059  * Convert to ASCII from email subjects.
2060  *
2061  * @since 1.2.0
2062  *
2063  * @param string $string Subject line
2064  * @return string Converted string to ASCII