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