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 |
---|---|
2628 | * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits', |
2629 | * 'domain_no_periods', 'domain_no_valid_subs', or no context. |
2630 | * |
2631 | * @since 2.8.0 |
2632 | * |
2633 | * @param string $email The sanitized email address. |
2634 | * @param string $email The email address, as provided to sanitize_email(). |
2635 | * @param string $message A message to pass to the user. |
2636 | */ |
2637 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
2638 | } |
2639 |
|
2640 | // Test for an @ character after the first position |
2641 | if ( strpos( $email, '@', 1 ) === false ) { |
2642 | /** This filter is documented in wp-includes/formatting.php */ |
2643 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
2644 | } |
2645 |
|
2646 | // Split out the local and domain parts |
2647 | list( $local, $domain ) = explode( '@', $email, 2 ); |
2648 |
|
2649 | // LOCAL PART |
2650 | // Test for invalid characters |
2651 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
2652 | if ( '' === $local ) { |
2653 | /** This filter is documented in wp-includes/formatting.php */ |
2654 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
2655 | } |
2656 |
|
2657 | // DOMAIN PART |
2658 | // Test for sequences of periods |
2659 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
2660 | if ( '' === $domain ) { |
2661 | /** This filter is documented in wp-includes/formatting.php */ |
2662 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
2663 | } |
2664 |
|
2665 | // Test for leading and trailing periods and whitespace |
2666 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
2667 | if ( '' === $domain ) { |
2668 | /** This filter is documented in wp-includes/formatting.php */ |
2669 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
2670 | } |
2671 |
|
2672 | // Split the domain into subs |
2673 | $subs = explode( '.', $domain ); |
2674 |
|
2675 | // Assume the domain will have at least two subs |
2676 | if ( 2 > count( $subs ) ) { |
2677 | /** This filter is documented in wp-includes/formatting.php */ |
2678 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
2679 | } |
2680 |
|
2681 | // Create an array that will contain valid subs |
2682 | $new_subs = array(); |
2683 |
|
2684 | // Loop through each sub |
2685 | foreach ( $subs as $sub ) { |
2686 | // Test for leading and trailing hyphens |
2687 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
Line | Code |
2692 | // If there's anything left, add it to the valid subs |
2693 | if ( '' !== $sub ) { |
2694 | $new_subs[] = $sub; |
2695 | } |
2696 | } |
2697 |
|
2698 | // If there aren't 2 or more valid subs |
2699 | if ( 2 > count( $new_subs ) ) { |
2700 | /** This filter is documented in wp-includes/formatting.php */ |
2701 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
2702 | } |
2703 |
|
2704 | // Join valid subs into the new domain |
2705 | $domain = join( '.', $new_subs ); |
2706 |
|
2707 | // Put the email back together |
2708 | $email = $local . '@' . $domain; |
2709 |
|
2710 | // Congratulations your email made it! |
2711 | /** This filter is documented in wp-includes/formatting.php */ |
2712 | return apply_filters( 'sanitize_email', $email, $email, null ); |
2713 | } |
2714 |
|
2715 | /** |
2716 | * Determines the difference between two timestamps. |
2717 | * |
2718 | * The difference is returned in a human readable format such as "1 hour", |
2719 | * "5 mins", "2 days". |
2720 | * |
2721 | * @since 1.5.0 |