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 |
---|---|
1711 | * |
1712 | * @since 1.5.0 |
1713 | * |
1714 | * @param string $email Email address to filter. |
1715 | * @return string Filtered email address. |
1716 | */ |
1717 | function sanitize_email( $email ) { |
1718 | // Test for the minimum length the email can be |
1719 | if ( strlen( $email ) < 3 ) { |
1720 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
1721 | } |
1722 |
|
1723 | // Test for an @ character after the first position |
1724 | if ( strpos( $email, '@', 1 ) === false ) { |
1725 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
1726 | } |
1727 |
|
1728 | // Split out the local and domain parts |
1729 | list( $local, $domain ) = explode( '@', $email, 2 ); |
1730 |
|
1731 | // LOCAL PART |
1732 | // Test for invalid characters |
1733 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
1734 | if ( '' === $local ) { |
1735 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
1736 | } |
1737 |
|
1738 | // DOMAIN PART |
1739 | // Test for sequences of periods |
1740 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
1741 | if ( '' === $domain ) { |
1742 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
1743 | } |
1744 |
|
1745 | // Test for leading and trailing periods and whitespace |
1746 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
1747 | if ( '' === $domain ) { |
1748 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
1749 | } |
1750 |
|
1751 | // Split the domain into subs |
1752 | $subs = explode( '.', $domain ); |
1753 |
|
1754 | // Assume the domain will have at least two subs |
1755 | if ( 2 > count( $subs ) ) { |
1756 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
1757 | } |
1758 |
|
1759 | // Create an array that will contain valid subs |
1760 | $new_subs = array(); |
1761 |
|
1762 | // Loop through each sub |
1763 | foreach ( $subs as $sub ) { |
1764 | // Test for leading and trailing hyphens |
1765 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
Line | Code |
1769 |
|
1770 | // If there's anything left, add it to the valid subs |
1771 | if ( '' !== $sub ) { |
1772 | $new_subs[] = $sub; |
1773 | } |
1774 | } |
1775 |
|
1776 | // If there aren't 2 or more valid subs |
1777 | if ( 2 > count( $new_subs ) ) { |
1778 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
1779 | } |
1780 |
|
1781 | // Join valid subs into the new domain |
1782 | $domain = join( '.', $new_subs ); |
1783 |
|
1784 | // Put the email back together |
1785 | $email = $local . '@' . $domain; |
1786 |
|
1787 | // Congratulations your email made it! |
1788 | return apply_filters( 'sanitize_email', $email, $email, null ); |
1789 | } |
1790 |
|
1791 | /** |
1792 | * Determines the difference between two timestamps. |
1793 | * |
1794 | * The difference is returned in a human readable format such as "1 hour", |
1795 | * "5 mins", "2 days". |
1796 | * |
1797 | * @since 1.5.0 |