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 |
|---|---|
| 2041 | * |
| 2042 | * @since 1.5.0 |
| 2043 | * |
| 2044 | * @param string $email Email address to filter. |
| 2045 | * @return string Filtered email address. |
| 2046 | */ |
| 2047 | function sanitize_email( $email ) { |
| 2048 | // Test for the minimum length the email can be |
| 2049 | if ( strlen( $email ) < 3 ) { |
| 2050 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
| 2051 | } |
| 2052 | |
| 2053 | // Test for an @ character after the first position |
| 2054 | if ( strpos( $email, '@', 1 ) === false ) { |
| 2055 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
| 2056 | } |
| 2057 | |
| 2058 | // Split out the local and domain parts |
| 2059 | list( $local, $domain ) = explode( '@', $email, 2 ); |
| 2060 | |
| 2061 | // LOCAL PART |
| 2062 | // Test for invalid characters |
| 2063 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
| 2064 | if ( '' === $local ) { |
| 2065 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
| 2066 | } |
| 2067 | |
| 2068 | // DOMAIN PART |
| 2069 | // Test for sequences of periods |
| 2070 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
| 2071 | if ( '' === $domain ) { |
| 2072 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
| 2073 | } |
| 2074 | |
| 2075 | // Test for leading and trailing periods and whitespace |
| 2076 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
| 2077 | if ( '' === $domain ) { |
| 2078 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
| 2079 | } |
| 2080 | |
| 2081 | // Split the domain into subs |
| 2082 | $subs = explode( '.', $domain ); |
| 2083 | |
| 2084 | // Assume the domain will have at least two subs |
| 2085 | if ( 2 > count( $subs ) ) { |
| 2086 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
| 2087 | } |
| 2088 | |
| 2089 | // Create an array that will contain valid subs |
| 2090 | $new_subs = array(); |
| 2091 | |
| 2092 | // Loop through each sub |
| 2093 | foreach ( $subs as $sub ) { |
| 2094 | // Test for leading and trailing hyphens |
| 2095 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
| Line | Code |
| 2099 | |
| 2100 | // If there's anything left, add it to the valid subs |
| 2101 | if ( '' !== $sub ) { |
| 2102 | $new_subs[] = $sub; |
| 2103 | } |
| 2104 | } |
| 2105 | |
| 2106 | // If there aren't 2 or more valid subs |
| 2107 | if ( 2 > count( $new_subs ) ) { |
| 2108 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
| 2109 | } |
| 2110 | |
| 2111 | // Join valid subs into the new domain |
| 2112 | $domain = join( '.', $new_subs ); |
| 2113 | |
| 2114 | // Put the email back together |
| 2115 | $email = $local . '@' . $domain; |
| 2116 | |
| 2117 | // Congratulations your email made it! |
| 2118 | return apply_filters( 'sanitize_email', $email, $email, null ); |
| 2119 | } |
| 2120 | |
| 2121 | /** |
| 2122 | * Determines the difference between two timestamps. |
| 2123 | * |
| 2124 | * The difference is returned in a human readable format such as "1 hour", |
| 2125 | * "5 mins", "2 days". |
| 2126 | * |
| 2127 | * @since 1.5.0 |