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
1500  * @param boolean $deprecated Deprecated.
1501  * @return string|bool Either false or the valid email address.
1502  */
1503 function is_email( $email, $deprecated = false ) {
1504      if ( ! empty( $deprecated ) )
1505           _deprecated_argument( __FUNCTION__, '3.0' );
1506
1507      // Test for the minimum length the email can be
1508      if ( strlen( $email ) < 3 ) {
1509           return apply_filters( 'is_email', false, $email, 'email_too_short' );
1510      }
1511
1512      // Test for an @ character after the first position
1513      if ( strpos( $email, '@', 1 ) === false ) {
1514           return apply_filters( 'is_email', false, $email, 'email_no_at' );
1515      }
1516
1517      // Split out the local and domain parts
1518      list( $local, $domain ) = explode( '@', $email, 2 );
1519
1520      // LOCAL PART
1521      // Test for invalid characters
1522      if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
1523           return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
1524      }
1525
1526      // DOMAIN PART
1527      // Test for sequences of periods
1528      if ( preg_match( '/\.{2,}/', $domain ) ) {
1529           return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
1530      }
1531
1532      // Test for leading and trailing periods and whitespace
1533      if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
1534           return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
1535      }
1536
1537      // Split the domain into subs
1538      $subs = explode( '.', $domain );
1539
1540      // Assume the domain will have at least two subs
1541      if ( 2 > count( $subs ) ) {
1542           return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
1543      }
1544
1545      // Loop through each sub
1546      foreach ( $subs as $sub ) {
1547           // Test for leading and trailing hyphens and whitespace
1548           if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
1549                return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
1550           }
1551
1552           // Test for invalid characters
1553           if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {
1554                return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
1555           }
1556      }
1557
1558      // Congratulations your email made it!
1559      return apply_filters( 'is_email', $email, $email, null );
1560 }
1561
1562 /**
1563  * Convert to ASCII from email subjects.
1564  *
1565  * @since 1.2.0
1566  * @usedby wp_mail() handles charsets in email subjects
1567  *
1568  * @param string $string Subject line