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 |
|---|---|
| 1560 | * |
| 1561 | * @since 1.5.0 |
| 1562 | * |
| 1563 | * @param string $email Email address to filter. |
| 1564 | * @return string Filtered email address. |
| 1565 | */ |
| 1566 | function sanitize_email( $email ) { |
| 1567 | // Test for the minimum length the email can be |
| 1568 | if ( strlen( $email ) < 3 ) { |
| 1569 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
| 1570 | } |
| 1571 | |
| 1572 | // Test for an @ character after the first position |
| 1573 | if ( strpos( $email, '@', 1 ) === false ) { |
| 1574 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
| 1575 | } |
| 1576 | |
| 1577 | // Split out the local and domain parts |
| 1578 | list( $local, $domain ) = explode( '@', $email, 2 ); |
| 1579 | |
| 1580 | // LOCAL PART |
| 1581 | // Test for invalid characters |
| 1582 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
| 1583 | if ( '' === $local ) { |
| 1584 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
| 1585 | } |
| 1586 | |
| 1587 | // DOMAIN PART |
| 1588 | // Test for sequences of periods |
| 1589 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
| 1590 | if ( '' === $domain ) { |
| 1591 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
| 1592 | } |
| 1593 | |
| 1594 | // Test for leading and trailing periods and whitespace |
| 1595 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
| 1596 | if ( '' === $domain ) { |
| 1597 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
| 1598 | } |
| 1599 | |
| 1600 | // Split the domain into subs |
| 1601 | $subs = explode( '.', $domain ); |
| 1602 | |
| 1603 | // Assume the domain will have at least two subs |
| 1604 | if ( 2 > count( $subs ) ) { |
| 1605 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
| 1606 | } |
| 1607 | |
| 1608 | // Create an array that will contain valid subs |
| 1609 | $new_subs = array(); |
| 1610 | |
| 1611 | // Loop through each sub |
| 1612 | foreach ( $subs as $sub ) { |
| 1613 | // Test for leading and trailing hyphens |
| 1614 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
| Line | Code |
| 1618 | |
| 1619 | // If there's anything left, add it to the valid subs |
| 1620 | if ( '' !== $sub ) { |
| 1621 | $new_subs[] = $sub; |
| 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | // If there aren't 2 or more valid subs |
| 1626 | if ( 2 > count( $new_subs ) ) { |
| 1627 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
| 1628 | } |
| 1629 | |
| 1630 | // Join valid subs into the new domain |
| 1631 | $domain = join( '.', $new_subs ); |
| 1632 | |
| 1633 | // Put the email back together |
| 1634 | $email = $local . '@' . $domain; |
| 1635 | |
| 1636 | // Congratulations your email made it! |
| 1637 | return apply_filters( 'sanitize_email', $email, $email, null ); |
| 1638 | } |
| 1639 | |
| 1640 | /** |
| 1641 | * Determines the difference between two timestamps. |
| 1642 | * |
| 1643 | * The difference is returned in a human readable format such as "1 hour", |
| 1644 | * "5 mins", "2 days". |
| 1645 | * |
| 1646 | * @since 1.5.0 |