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 |
---|---|
3610 | * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits', |
3611 | * 'domain_no_periods', 'domain_no_valid_subs', or no context. |
3612 | * |
3613 | * @since 2.8.0 |
3614 | * |
3615 | * @param string $sanitized_email The sanitized email address. |
3616 | * @param string $email The email address, as provided to sanitize_email(). |
3617 | * @param string|null $message A message to pass to the user. null if email is sanitized. |
3618 | */ |
3619 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
3620 | } |
3621 |
|
3622 | // Test for an @ character after the first position. |
3623 | if ( strpos( $email, '@', 1 ) === false ) { |
3624 | /** This filter is documented in wp-includes/formatting.php */ |
3625 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
3626 | } |
3627 |
|
3628 | // Split out the local and domain parts. |
3629 | list( $local, $domain ) = explode( '@', $email, 2 ); |
3630 |
|
3631 | // LOCAL PART |
3632 | // Test for invalid characters. |
3633 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
3634 | if ( '' === $local ) { |
3635 | /** This filter is documented in wp-includes/formatting.php */ |
3636 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
3637 | } |
3638 |
|
3639 | // DOMAIN PART |
3640 | // Test for sequences of periods. |
3641 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
3642 | if ( '' === $domain ) { |
3643 | /** This filter is documented in wp-includes/formatting.php */ |
3644 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
3645 | } |
3646 |
|
3647 | // Test for leading and trailing periods and whitespace. |
3648 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
3649 | if ( '' === $domain ) { |
3650 | /** This filter is documented in wp-includes/formatting.php */ |
3651 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
3652 | } |
3653 |
|
3654 | // Split the domain into subs. |
3655 | $subs = explode( '.', $domain ); |
3656 |
|
3657 | // Assume the domain will have at least two subs. |
3658 | if ( 2 > count( $subs ) ) { |
3659 | /** This filter is documented in wp-includes/formatting.php */ |
3660 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
3661 | } |
3662 |
|
3663 | // Create an array that will contain valid subs. |
3664 | $new_subs = array(); |
3665 |
|
3666 | // Loop through each sub. |
3667 | foreach ( $subs as $sub ) { |
3668 | // Test for leading and trailing hyphens. |
3669 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
Line | Code |
3674 | // If there's anything left, add it to the valid subs. |
3675 | if ( '' !== $sub ) { |
3676 | $new_subs[] = $sub; |
3677 | } |
3678 | } |
3679 |
|
3680 | // If there aren't 2 or more valid subs. |
3681 | if ( 2 > count( $new_subs ) ) { |
3682 | /** This filter is documented in wp-includes/formatting.php */ |
3683 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
3684 | } |
3685 |
|
3686 | // Join valid subs into the new domain. |
3687 | $domain = join( '.', $new_subs ); |
3688 |
|
3689 | // Put the email back together. |
3690 | $sanitized_email = $local . '@' . $domain; |
3691 |
|
3692 | // Congratulations, your email made it! |
3693 | /** This filter is documented in wp-includes/formatting.php */ |
3694 | return apply_filters( 'sanitize_email', $sanitized_email, $email, null ); |
3695 | } |
3696 |
|
3697 | /** |
3698 | * Determines the difference between two timestamps. |
3699 | * |
3700 | * The difference is returned in a human readable format such as "1 hour", |
3701 | * "5 mins", "2 days". |
3702 | * |
3703 | * @since 1.5.0 |