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 |
---|---|
2009 | * |
2010 | * @since 1.5.0 |
2011 | * |
2012 | * @param string $email Email address to filter. |
2013 | * @return string Filtered email address. |
2014 | */ |
2015 | function sanitize_email( $email ) { |
2016 | // Test for the minimum length the email can be |
2017 | if ( strlen( $email ) < 3 ) { |
2018 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
2019 | } |
2020 |
|
2021 | // Test for an @ character after the first position |
2022 | if ( strpos( $email, '@', 1 ) === false ) { |
2023 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
2024 | } |
2025 |
|
2026 | // Split out the local and domain parts |
2027 | list( $local, $domain ) = explode( '@', $email, 2 ); |
2028 |
|
2029 | // LOCAL PART |
2030 | // Test for invalid characters |
2031 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
2032 | if ( '' === $local ) { |
2033 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
2034 | } |
2035 |
|
2036 | // DOMAIN PART |
2037 | // Test for sequences of periods |
2038 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
2039 | if ( '' === $domain ) { |
2040 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
2041 | } |
2042 |
|
2043 | // Test for leading and trailing periods and whitespace |
2044 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
2045 | if ( '' === $domain ) { |
2046 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
2047 | } |
2048 |
|
2049 | // Split the domain into subs |
2050 | $subs = explode( '.', $domain ); |
2051 |
|
2052 | // Assume the domain will have at least two subs |
2053 | if ( 2 > count( $subs ) ) { |
2054 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
2055 | } |
2056 |
|
2057 | // Create an array that will contain valid subs |
2058 | $new_subs = array(); |
2059 |
|
2060 | // Loop through each sub |
2061 | foreach ( $subs as $sub ) { |
2062 | // Test for leading and trailing hyphens |
2063 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
Line | Code |
2067 |
|
2068 | // If there's anything left, add it to the valid subs |
2069 | if ( '' !== $sub ) { |
2070 | $new_subs[] = $sub; |
2071 | } |
2072 | } |
2073 |
|
2074 | // If there aren't 2 or more valid subs |
2075 | if ( 2 > count( $new_subs ) ) { |
2076 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
2077 | } |
2078 |
|
2079 | // Join valid subs into the new domain |
2080 | $domain = join( '.', $new_subs ); |
2081 |
|
2082 | // Put the email back together |
2083 | $email = $local . '@' . $domain; |
2084 |
|
2085 | // Congratulations your email made it! |
2086 | return apply_filters( 'sanitize_email', $email, $email, null ); |
2087 | } |
2088 |
|
2089 | /** |
2090 | * Determines the difference between two timestamps. |
2091 | * |
2092 | * The difference is returned in a human readable format such as "1 hour", |
2093 | * "5 mins", "2 days". |
2094 | * |
2095 | * @since 1.5.0 |