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 |
|---|---|
| 3668 | * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits', |
| 3669 | * 'domain_no_periods', 'domain_no_valid_subs', or no context. |
| 3670 | * |
| 3671 | * @since 2.8.0 |
| 3672 | * |
| 3673 | * @param string $sanitized_email The sanitized email address. |
| 3674 | * @param string $email The email address, as provided to sanitize_email(). |
| 3675 | * @param string|null $message A message to pass to the user. null if email is sanitized. |
| 3676 | */ |
| 3677 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
| 3678 | } |
| 3679 | |
| 3680 | // Test for an @ character after the first position. |
| 3681 | if ( strpos( $email, '@', 1 ) === false ) { |
| 3682 | /** This filter is documented in wp-includes/formatting.php */ |
| 3683 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
| 3684 | } |
| 3685 | |
| 3686 | // Split out the local and domain parts. |
| 3687 | list( $local, $domain ) = explode( '@', $email, 2 ); |
| 3688 | |
| 3689 | // LOCAL PART |
| 3690 | // Test for invalid characters. |
| 3691 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
| 3692 | if ( '' === $local ) { |
| 3693 | /** This filter is documented in wp-includes/formatting.php */ |
| 3694 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
| 3695 | } |
| 3696 | |
| 3697 | // DOMAIN PART |
| 3698 | // Test for sequences of periods. |
| 3699 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
| 3700 | if ( '' === $domain ) { |
| 3701 | /** This filter is documented in wp-includes/formatting.php */ |
| 3702 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
| 3703 | } |
| 3704 | |
| 3705 | // Test for leading and trailing periods and whitespace. |
| 3706 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
| 3707 | if ( '' === $domain ) { |
| 3708 | /** This filter is documented in wp-includes/formatting.php */ |
| 3709 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
| 3710 | } |
| 3711 | |
| 3712 | // Split the domain into subs. |
| 3713 | $subs = explode( '.', $domain ); |
| 3714 | |
| 3715 | // Assume the domain will have at least two subs. |
| 3716 | if ( 2 > count( $subs ) ) { |
| 3717 | /** This filter is documented in wp-includes/formatting.php */ |
| 3718 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
| 3719 | } |
| 3720 | |
| 3721 | // Create an array that will contain valid subs. |
| 3722 | $new_subs = array(); |
| 3723 | |
| 3724 | // Loop through each sub. |
| 3725 | foreach ( $subs as $sub ) { |
| 3726 | // Test for leading and trailing hyphens. |
| 3727 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
| Line | Code |
| 3732 | // If there's anything left, add it to the valid subs. |
| 3733 | if ( '' !== $sub ) { |
| 3734 | $new_subs[] = $sub; |
| 3735 | } |
| 3736 | } |
| 3737 | |
| 3738 | // If there aren't 2 or more valid subs. |
| 3739 | if ( 2 > count( $new_subs ) ) { |
| 3740 | /** This filter is documented in wp-includes/formatting.php */ |
| 3741 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
| 3742 | } |
| 3743 | |
| 3744 | // Join valid subs into the new domain. |
| 3745 | $domain = implode( '.', $new_subs ); |
| 3746 | |
| 3747 | // Put the email back together. |
| 3748 | $sanitized_email = $local . '@' . $domain; |
| 3749 | |
| 3750 | // Congratulations, your email made it! |
| 3751 | /** This filter is documented in wp-includes/formatting.php */ |
| 3752 | return apply_filters( 'sanitize_email', $sanitized_email, $email, null ); |
| 3753 | } |
| 3754 | |
| 3755 | /** |
| 3756 | * Determines the difference between two timestamps. |
| 3757 | * |
| 3758 | * The difference is returned in a human readable format such as "1 hour", |
| 3759 | * "5 mins", "2 days". |
| 3760 | * |
| 3761 | * @since 1.5.0 |