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 |
---|---|
2375 | * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits', |
2376 | * 'domain_no_periods', 'domain_no_valid_subs', or no context. |
2377 | * |
2378 | * @since 2.8.0 |
2379 | * |
2380 | * @param string $email The sanitized email address. |
2381 | * @param string $email The email address, as provided to sanitize_email(). |
2382 | * @param string $message A message to pass to the user. |
2383 | */ |
2384 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
2385 | } |
2386 |
|
2387 | // Test for an @ character after the first position |
2388 | if ( strpos( $email, '@', 1 ) === false ) { |
2389 | /** This filter is documented in wp-includes/formatting.php */ |
2390 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
2391 | } |
2392 |
|
2393 | // Split out the local and domain parts |
2394 | list( $local, $domain ) = explode( '@', $email, 2 ); |
2395 |
|
2396 | // LOCAL PART |
2397 | // Test for invalid characters |
2398 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
2399 | if ( '' === $local ) { |
2400 | /** This filter is documented in wp-includes/formatting.php */ |
2401 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
2402 | } |
2403 |
|
2404 | // DOMAIN PART |
2405 | // Test for sequences of periods |
2406 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
2407 | if ( '' === $domain ) { |
2408 | /** This filter is documented in wp-includes/formatting.php */ |
2409 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
2410 | } |
2411 |
|
2412 | // Test for leading and trailing periods and whitespace |
2413 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
2414 | if ( '' === $domain ) { |
2415 | /** This filter is documented in wp-includes/formatting.php */ |
2416 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
2417 | } |
2418 |
|
2419 | // Split the domain into subs |
2420 | $subs = explode( '.', $domain ); |
2421 |
|
2422 | // Assume the domain will have at least two subs |
2423 | if ( 2 > count( $subs ) ) { |
2424 | /** This filter is documented in wp-includes/formatting.php */ |
2425 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
2426 | } |
2427 |
|
2428 | // Create an array that will contain valid subs |
2429 | $new_subs = array(); |
2430 |
|
2431 | // Loop through each sub |
2432 | foreach ( $subs as $sub ) { |
2433 | // Test for leading and trailing hyphens |
2434 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
Line | Code |
2439 | // If there's anything left, add it to the valid subs |
2440 | if ( '' !== $sub ) { |
2441 | $new_subs[] = $sub; |
2442 | } |
2443 | } |
2444 |
|
2445 | // If there aren't 2 or more valid subs |
2446 | if ( 2 > count( $new_subs ) ) { |
2447 | /** This filter is documented in wp-includes/formatting.php */ |
2448 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
2449 | } |
2450 |
|
2451 | // Join valid subs into the new domain |
2452 | $domain = join( '.', $new_subs ); |
2453 |
|
2454 | // Put the email back together |
2455 | $email = $local . '@' . $domain; |
2456 |
|
2457 | // Congratulations your email made it! |
2458 | /** This filter is documented in wp-includes/formatting.php */ |
2459 | return apply_filters( 'sanitize_email', $email, $email, null ); |
2460 | } |
2461 |
|
2462 | /** |
2463 | * Determines the difference between two timestamps. |
2464 | * |
2465 | * The difference is returned in a human readable format such as "1 hour", |
2466 | * "5 mins", "2 days". |
2467 | * |
2468 | * @since 1.5.0 |