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 |
---|---|
2199 | * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits', |
2200 | * 'domain_no_periods', 'domain_no_valid_subs', or no context. |
2201 | * |
2202 | * @since 2.8.0 |
2203 | * |
2204 | * @param string $email The sanitized email address. |
2205 | * @param string $email The email address, as provided to sanitize_email(). |
2206 | * @param string $message A message to pass to the user. |
2207 | */ |
2208 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
2209 | } |
2210 |
|
2211 | // Test for an @ character after the first position |
2212 | if ( strpos( $email, '@', 1 ) === false ) { |
2213 | /** This filter is documented in wp-includes/formatting.php */ |
2214 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
2215 | } |
2216 |
|
2217 | // Split out the local and domain parts |
2218 | list( $local, $domain ) = explode( '@', $email, 2 ); |
2219 |
|
2220 | // LOCAL PART |
2221 | // Test for invalid characters |
2222 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
2223 | if ( '' === $local ) { |
2224 | /** This filter is documented in wp-includes/formatting.php */ |
2225 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
2226 | } |
2227 |
|
2228 | // DOMAIN PART |
2229 | // Test for sequences of periods |
2230 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
2231 | if ( '' === $domain ) { |
2232 | /** This filter is documented in wp-includes/formatting.php */ |
2233 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
2234 | } |
2235 |
|
2236 | // Test for leading and trailing periods and whitespace |
2237 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
2238 | if ( '' === $domain ) { |
2239 | /** This filter is documented in wp-includes/formatting.php */ |
2240 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
2241 | } |
2242 |
|
2243 | // Split the domain into subs |
2244 | $subs = explode( '.', $domain ); |
2245 |
|
2246 | // Assume the domain will have at least two subs |
2247 | if ( 2 > count( $subs ) ) { |
2248 | /** This filter is documented in wp-includes/formatting.php */ |
2249 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
2250 | } |
2251 |
|
2252 | // Create an array that will contain valid subs |
2253 | $new_subs = array(); |
2254 |
|
2255 | // Loop through each sub |
2256 | foreach ( $subs as $sub ) { |
2257 | // Test for leading and trailing hyphens |
2258 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
Line | Code |
2263 | // If there's anything left, add it to the valid subs |
2264 | if ( '' !== $sub ) { |
2265 | $new_subs[] = $sub; |
2266 | } |
2267 | } |
2268 |
|
2269 | // If there aren't 2 or more valid subs |
2270 | if ( 2 > count( $new_subs ) ) { |
2271 | /** This filter is documented in wp-includes/formatting.php */ |
2272 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
2273 | } |
2274 |
|
2275 | // Join valid subs into the new domain |
2276 | $domain = join( '.', $new_subs ); |
2277 |
|
2278 | // Put the email back together |
2279 | $email = $local . '@' . $domain; |
2280 |
|
2281 | // Congratulations your email made it! |
2282 | /** This filter is documented in wp-includes/formatting.php */ |
2283 | return apply_filters( 'sanitize_email', $email, $email, null ); |
2284 | } |
2285 |
|
2286 | /** |
2287 | * Determines the difference between two timestamps. |
2288 | * |
2289 | * The difference is returned in a human readable format such as "1 hour", |
2290 | * "5 mins", "2 days". |
2291 | * |
2292 | * @since 1.5.0 |