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 |
---|---|
2723 | * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits', |
2724 | * 'domain_no_periods', 'domain_no_valid_subs', or no context. |
2725 | * |
2726 | * @since 2.8.0 |
2727 | * |
2728 | * @param string $email The sanitized email address. |
2729 | * @param string $email The email address, as provided to sanitize_email(). |
2730 | * @param string $message A message to pass to the user. |
2731 | */ |
2732 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
2733 | } |
2734 |
|
2735 | // Test for an @ character after the first position |
2736 | if ( strpos( $email, '@', 1 ) === false ) { |
2737 | /** This filter is documented in wp-includes/formatting.php */ |
2738 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
2739 | } |
2740 |
|
2741 | // Split out the local and domain parts |
2742 | list( $local, $domain ) = explode( '@', $email, 2 ); |
2743 |
|
2744 | // LOCAL PART |
2745 | // Test for invalid characters |
2746 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
2747 | if ( '' === $local ) { |
2748 | /** This filter is documented in wp-includes/formatting.php */ |
2749 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
2750 | } |
2751 |
|
2752 | // DOMAIN PART |
2753 | // Test for sequences of periods |
2754 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
2755 | if ( '' === $domain ) { |
2756 | /** This filter is documented in wp-includes/formatting.php */ |
2757 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
2758 | } |
2759 |
|
2760 | // Test for leading and trailing periods and whitespace |
2761 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
2762 | if ( '' === $domain ) { |
2763 | /** This filter is documented in wp-includes/formatting.php */ |
2764 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
2765 | } |
2766 |
|
2767 | // Split the domain into subs |
2768 | $subs = explode( '.', $domain ); |
2769 |
|
2770 | // Assume the domain will have at least two subs |
2771 | if ( 2 > count( $subs ) ) { |
2772 | /** This filter is documented in wp-includes/formatting.php */ |
2773 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
2774 | } |
2775 |
|
2776 | // Create an array that will contain valid subs |
2777 | $new_subs = array(); |
2778 |
|
2779 | // Loop through each sub |
2780 | foreach ( $subs as $sub ) { |
2781 | // Test for leading and trailing hyphens |
2782 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
Line | Code |
2787 | // If there's anything left, add it to the valid subs |
2788 | if ( '' !== $sub ) { |
2789 | $new_subs[] = $sub; |
2790 | } |
2791 | } |
2792 |
|
2793 | // If there aren't 2 or more valid subs |
2794 | if ( 2 > count( $new_subs ) ) { |
2795 | /** This filter is documented in wp-includes/formatting.php */ |
2796 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
2797 | } |
2798 |
|
2799 | // Join valid subs into the new domain |
2800 | $domain = join( '.', $new_subs ); |
2801 |
|
2802 | // Put the email back together |
2803 | $email = $local . '@' . $domain; |
2804 |
|
2805 | // Congratulations your email made it! |
2806 | /** This filter is documented in wp-includes/formatting.php */ |
2807 | return apply_filters( 'sanitize_email', $email, $email, null ); |
2808 | } |
2809 |
|
2810 | /** |
2811 | * Determines the difference between two timestamps. |
2812 | * |
2813 | * The difference is returned in a human readable format such as "1 hour", |
2814 | * "5 mins", "2 days". |
2815 | * |
2816 | * @since 1.5.0 |