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 |
|---|---|
| 2439 | * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits', |
| 2440 | * 'domain_no_periods', 'domain_no_valid_subs', or no context. |
| 2441 | * |
| 2442 | * @since 2.8.0 |
| 2443 | * |
| 2444 | * @param string $email The sanitized email address. |
| 2445 | * @param string $email The email address, as provided to sanitize_email(). |
| 2446 | * @param string $message A message to pass to the user. |
| 2447 | */ |
| 2448 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
| 2449 | } |
| 2450 | |
| 2451 | // Test for an @ character after the first position |
| 2452 | if ( strpos( $email, '@', 1 ) === false ) { |
| 2453 | /** This filter is documented in wp-includes/formatting.php */ |
| 2454 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
| 2455 | } |
| 2456 | |
| 2457 | // Split out the local and domain parts |
| 2458 | list( $local, $domain ) = explode( '@', $email, 2 ); |
| 2459 | |
| 2460 | // LOCAL PART |
| 2461 | // Test for invalid characters |
| 2462 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
| 2463 | if ( '' === $local ) { |
| 2464 | /** This filter is documented in wp-includes/formatting.php */ |
| 2465 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
| 2466 | } |
| 2467 | |
| 2468 | // DOMAIN PART |
| 2469 | // Test for sequences of periods |
| 2470 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
| 2471 | if ( '' === $domain ) { |
| 2472 | /** This filter is documented in wp-includes/formatting.php */ |
| 2473 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
| 2474 | } |
| 2475 | |
| 2476 | // Test for leading and trailing periods and whitespace |
| 2477 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
| 2478 | if ( '' === $domain ) { |
| 2479 | /** This filter is documented in wp-includes/formatting.php */ |
| 2480 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
| 2481 | } |
| 2482 | |
| 2483 | // Split the domain into subs |
| 2484 | $subs = explode( '.', $domain ); |
| 2485 | |
| 2486 | // Assume the domain will have at least two subs |
| 2487 | if ( 2 > count( $subs ) ) { |
| 2488 | /** This filter is documented in wp-includes/formatting.php */ |
| 2489 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
| 2490 | } |
| 2491 | |
| 2492 | // Create an array that will contain valid subs |
| 2493 | $new_subs = array(); |
| 2494 | |
| 2495 | // Loop through each sub |
| 2496 | foreach ( $subs as $sub ) { |
| 2497 | // Test for leading and trailing hyphens |
| 2498 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
| Line | Code |
| 2503 | // If there's anything left, add it to the valid subs |
| 2504 | if ( '' !== $sub ) { |
| 2505 | $new_subs[] = $sub; |
| 2506 | } |
| 2507 | } |
| 2508 | |
| 2509 | // If there aren't 2 or more valid subs |
| 2510 | if ( 2 > count( $new_subs ) ) { |
| 2511 | /** This filter is documented in wp-includes/formatting.php */ |
| 2512 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
| 2513 | } |
| 2514 | |
| 2515 | // Join valid subs into the new domain |
| 2516 | $domain = join( '.', $new_subs ); |
| 2517 | |
| 2518 | // Put the email back together |
| 2519 | $email = $local . '@' . $domain; |
| 2520 | |
| 2521 | // Congratulations your email made it! |
| 2522 | /** This filter is documented in wp-includes/formatting.php */ |
| 2523 | return apply_filters( 'sanitize_email', $email, $email, null ); |
| 2524 | } |
| 2525 | |
| 2526 | /** |
| 2527 | * Determines the difference between two timestamps. |
| 2528 | * |
| 2529 | * The difference is returned in a human readable format such as "1 hour", |
| 2530 | * "5 mins", "2 days". |
| 2531 | * |
| 2532 | * @since 1.5.0 |