WP hooks navigation: Home/browse • Actions index • Filters index
To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).
The best way to understand what a hook does is to look at where it occurs in the source code.
do_action( "hook_name" )
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.
This hook occurs 8 times in this file.
Line | Code |
---|---|
1760 | * |
1761 | * @since 1.5.0 |
1762 | * |
1763 | * @param string $email Email address to filter. |
1764 | * @return string Filtered email address. |
1765 | */ |
1766 | function sanitize_email( $email ) { |
1767 | // Test for the minimum length the email can be |
1768 | if ( strlen( $email ) < 3 ) { |
1769 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
1770 | } |
1771 |
|
1772 | // Test for an @ character after the first position |
1773 | if ( strpos( $email, '@', 1 ) === false ) { |
1774 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
1775 | } |
1776 |
|
1777 | // Split out the local and domain parts |
1778 | list( $local, $domain ) = explode( '@', $email, 2 ); |
1779 |
|
1780 | // LOCAL PART |
1781 | // Test for invalid characters |
1782 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
1783 | if ( '' === $local ) { |
1784 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
1785 | } |
1786 |
|
1787 | // DOMAIN PART |
1788 | // Test for sequences of periods |
1789 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
1790 | if ( '' === $domain ) { |
1791 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
1792 | } |
1793 |
|
1794 | // Test for leading and trailing periods and whitespace |
1795 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
1796 | if ( '' === $domain ) { |
1797 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
1798 | } |
1799 |
|
1800 | // Split the domain into subs |
1801 | $subs = explode( '.', $domain ); |
1802 |
|
1803 | // Assume the domain will have at least two subs |
1804 | if ( 2 > count( $subs ) ) { |
1805 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
1806 | } |
1807 |
|
1808 | // Create an array that will contain valid subs |
1809 | $new_subs = array(); |
1810 |
|
1811 | // Loop through each sub |
1812 | foreach ( $subs as $sub ) { |
1813 | // Test for leading and trailing hyphens |
1814 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
Line | Code |
1818 |
|
1819 | // If there's anything left, add it to the valid subs |
1820 | if ( '' !== $sub ) { |
1821 | $new_subs[] = $sub; |
1822 | } |
1823 | } |
1824 |
|
1825 | // If there aren't 2 or more valid subs |
1826 | if ( 2 > count( $new_subs ) ) { |
1827 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
1828 | } |
1829 |
|
1830 | // Join valid subs into the new domain |
1831 | $domain = join( '.', $new_subs ); |
1832 |
|
1833 | // Put the email back together |
1834 | $email = $local . '@' . $domain; |
1835 |
|
1836 | // Congratulations your email made it! |
1837 | return apply_filters( 'sanitize_email', $email, $email, null ); |
1838 | } |
1839 |
|
1840 | /** |
1841 | * Determines the difference between two timestamps. |
1842 | * |
1843 | * The difference is returned in a human readable format such as "1 hour", |
1844 | * "5 mins", "2 days". |
1845 | * |
1846 | * @since 1.5.0 |