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
1813  * @param boolean $deprecated Deprecated.
1814  * @return string|bool Either false or the valid email address.
1815  */
1816 function is_email( $email, $deprecated = false ) {
1817      if ( ! empty( $deprecated ) )
1818           _deprecated_argument( __FUNCTION__, '3.0' );
1819
1820      // Test for the minimum length the email can be
1821      if ( strlen( $email ) < 3 ) {
1822           return apply_filters( 'is_email', false, $email, 'email_too_short' );
1823      }
1824
1825      // Test for an @ character after the first position
1826      if ( strpos( $email, '@', 1 ) === false ) {
1827           return apply_filters( 'is_email', false, $email, 'email_no_at' );
1828      }
1829
1830      // Split out the local and domain parts
1831      list( $local, $domain ) = explode( '@', $email, 2 );
1832
1833      // LOCAL PART
1834      // Test for invalid characters
1835      if ( !preg_match( '/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]+$/', $local ) ) {
1836           return apply_filters( 'is_email', false, $email, 'local_invalid_chars' );
1837      }
1838
1839      // DOMAIN PART
1840      // Test for sequences of periods
1841      if ( preg_match( '/\.{2,}/', $domain ) ) {
1842           return apply_filters( 'is_email', false, $email, 'domain_period_sequence' );
1843      }
1844
1845      // Test for leading and trailing periods and whitespace
1846      if ( trim( $domain, " \t\n\r\0\x0B." ) !== $domain ) {
1847           return apply_filters( 'is_email', false, $email, 'domain_period_limits' );
1848      }
1849
1850      // Split the domain into subs
1851      $subs = explode( '.', $domain );
1852
1853      // Assume the domain will have at least two subs
1854      if ( 2 > count( $subs ) ) {
1855           return apply_filters( 'is_email', false, $email, 'domain_no_periods' );
1856      }
1857
1858      // Loop through each sub
1859      foreach ( $subs as $sub ) {
1860           // Test for leading and trailing hyphens and whitespace
1861           if ( trim( $sub, " \t\n\r\0\x0B-" ) !== $sub ) {
1862                return apply_filters( 'is_email', false, $email, 'sub_hyphen_limits' );
1863           }
1864
1865           // Test for invalid characters
1866           if ( !preg_match('/^[a-z0-9-]+$/i', $sub ) ) {
1867                return apply_filters( 'is_email', false, $email, 'sub_invalid_chars' );
1868           }
1869      }
1870
1871      // Congratulations your email made it!
1872      return apply_filters( 'is_email', $email, $email, null );
1873 }
1874
1875 /**
1876  * Convert to ASCII from email subjects.
1877  *
1878  * @since 1.2.0
1879  *
1880  * @param string $string Subject line
1881  * @return string Converted string to ASCII