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 |
---|---|
3511 | * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits', |
3512 | * 'domain_no_periods', 'domain_no_valid_subs', or no context. |
3513 | * |
3514 | * @since 2.8.0 |
3515 | * |
3516 | * @param string $sanitized_email The sanitized email address. |
3517 | * @param string $email The email address, as provided to sanitize_email(). |
3518 | * @param string|null $message A message to pass to the user. null if email is sanitized. |
3519 | */ |
3520 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
3521 | } |
3522 |
|
3523 | // Test for an @ character after the first position |
3524 | if ( strpos( $email, '@', 1 ) === false ) { |
3525 | /** This filter is documented in wp-includes/formatting.php */ |
3526 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
3527 | } |
3528 |
|
3529 | // Split out the local and domain parts |
3530 | list( $local, $domain ) = explode( '@', $email, 2 ); |
3531 |
|
3532 | // LOCAL PART |
3533 | // Test for invalid characters |
3534 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
3535 | if ( '' === $local ) { |
3536 | /** This filter is documented in wp-includes/formatting.php */ |
3537 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
3538 | } |
3539 |
|
3540 | // DOMAIN PART |
3541 | // Test for sequences of periods |
3542 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
3543 | if ( '' === $domain ) { |
3544 | /** This filter is documented in wp-includes/formatting.php */ |
3545 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
3546 | } |
3547 |
|
3548 | // Test for leading and trailing periods and whitespace |
3549 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
3550 | if ( '' === $domain ) { |
3551 | /** This filter is documented in wp-includes/formatting.php */ |
3552 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
3553 | } |
3554 |
|
3555 | // Split the domain into subs |
3556 | $subs = explode( '.', $domain ); |
3557 |
|
3558 | // Assume the domain will have at least two subs |
3559 | if ( 2 > count( $subs ) ) { |
3560 | /** This filter is documented in wp-includes/formatting.php */ |
3561 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
3562 | } |
3563 |
|
3564 | // Create an array that will contain valid subs |
3565 | $new_subs = array(); |
3566 |
|
3567 | // Loop through each sub |
3568 | foreach ( $subs as $sub ) { |
3569 | // Test for leading and trailing hyphens |
3570 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
Line | Code |
3575 | // If there's anything left, add it to the valid subs |
3576 | if ( '' !== $sub ) { |
3577 | $new_subs[] = $sub; |
3578 | } |
3579 | } |
3580 |
|
3581 | // If there aren't 2 or more valid subs |
3582 | if ( 2 > count( $new_subs ) ) { |
3583 | /** This filter is documented in wp-includes/formatting.php */ |
3584 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
3585 | } |
3586 |
|
3587 | // Join valid subs into the new domain |
3588 | $domain = join( '.', $new_subs ); |
3589 |
|
3590 | // Put the email back together |
3591 | $sanitized_email = $local . '@' . $domain; |
3592 |
|
3593 | // Congratulations your email made it! |
3594 | /** This filter is documented in wp-includes/formatting.php */ |
3595 | return apply_filters( 'sanitize_email', $sanitized_email, $email, null ); |
3596 | } |
3597 |
|
3598 | /** |
3599 | * Determines the difference between two timestamps. |
3600 | * |
3601 | * The difference is returned in a human readable format such as "1 hour", |
3602 | * "5 mins", "2 days". |
3603 | * |
3604 | * @since 1.5.0 |