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
1759  * @param boolean $deprecated Deprecated.
1760  * @return string|bool Either false or the valid email address.
1761  */
1762 function is_email( $email, $deprecated = false ) {
1763      if ( ! empty( $deprecated ) )
1764           _deprecated_argument( __FUNCTION__, '3.0' );
1765
1766      // Test for the minimum length the email can be
1767      if ( strlen( $email ) < 3 ) {
1768           return apply_filters( 'is_email', false, $email, 'email_too_short' );
1769      }
1770
1771      // Test for an @ character after the first position
1772      if ( strpos( $email, '@', 1 ) === false ) {
1773           return apply_filters( 'is_email', false, $email, 'email_no_at' );
1774      }
1775
1776      // Split out the local and domain parts
1777      list( $local, $domain ) = explode( '@', $email, 2 );
1778
1779      // LOCAL PART
1780      // Test for invalid characters
1781      if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
1782           return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
1783      }
1784
1785      // DOMAIN PART
1786      // Test for sequences of periods
1787      if ( preg_match( '/\.{2,}/', $domain ) ) {
1788           return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
1789      }
1790
1791      // Test for leading and trailing periods and whitespace
1792      if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
1793           return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
1794      }
1795
1796      // Split the domain into subs
1797      $subs = explode( '.', $domain );
1798
1799      // Assume the domain will have at least two subs
1800      if ( 2 > count( $subs ) ) {
1801           return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
1802      }
1803
1804      // Loop through each sub
1805      foreach ( $subs as $sub ) {
1806           // Test for leading and trailing hyphens and whitespace
1807           if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
1808                return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
1809           }
1810
1811           // Test for invalid characters
1812           if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {
1813                return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
1814           }
1815      }
1816
1817      // Congratulations your email made it!
1818      return apply_filters( 'is_email', $email, $email, null );
1819 }
1820
1821 /**
1822  * Convert to ASCII from email subjects.
1823  *
1824  * @since 1.2.0
1825  * @usedby wp_mail() handles charsets in email subjects
1826  *
1827  * @param string $string Subject line