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