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 |
---|---|
1977 | * |
1978 | * @since 1.5.0 |
1979 | * |
1980 | * @param string $email Email address to filter. |
1981 | * @return string Filtered email address. |
1982 | */ |
1983 | function sanitize_email( $email ) { |
1984 | // Test for the minimum length the email can be |
1985 | if ( strlen( $email ) < 3 ) { |
1986 | return apply_filters( 'sanitize_email', '', $email, 'email_too_short' ); |
1987 | } |
1988 |
|
1989 | // Test for an @ character after the first position |
1990 | if ( strpos( $email, '@', 1 ) === false ) { |
1991 | return apply_filters( 'sanitize_email', '', $email, 'email_no_at' ); |
1992 | } |
1993 |
|
1994 | // Split out the local and domain parts |
1995 | list( $local, $domain ) = explode( '@', $email, 2 ); |
1996 |
|
1997 | // LOCAL PART |
1998 | // Test for invalid characters |
1999 | $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local ); |
2000 | if ( '' === $local ) { |
2001 | return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' ); |
2002 | } |
2003 |
|
2004 | // DOMAIN PART |
2005 | // Test for sequences of periods |
2006 | $domain = preg_replace( '/\.{2,}/', '', $domain ); |
2007 | if ( '' === $domain ) { |
2008 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' ); |
2009 | } |
2010 |
|
2011 | // Test for leading and trailing periods and whitespace |
2012 | $domain = trim( $domain, " \t\n\r\0\x0B." ); |
2013 | if ( '' === $domain ) { |
2014 | return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' ); |
2015 | } |
2016 |
|
2017 | // Split the domain into subs |
2018 | $subs = explode( '.', $domain ); |
2019 |
|
2020 | // Assume the domain will have at least two subs |
2021 | if ( 2 > count( $subs ) ) { |
2022 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' ); |
2023 | } |
2024 |
|
2025 | // Create an array that will contain valid subs |
2026 | $new_subs = array(); |
2027 |
|
2028 | // Loop through each sub |
2029 | foreach ( $subs as $sub ) { |
2030 | // Test for leading and trailing hyphens |
2031 | $sub = trim( $sub, " \t\n\r\0\x0B-" ); |
Line | Code |
2035 |
|
2036 | // If there's anything left, add it to the valid subs |
2037 | if ( '' !== $sub ) { |
2038 | $new_subs[] = $sub; |
2039 | } |
2040 | } |
2041 |
|
2042 | // If there aren't 2 or more valid subs |
2043 | if ( 2 > count( $new_subs ) ) { |
2044 | return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' ); |
2045 | } |
2046 |
|
2047 | // Join valid subs into the new domain |
2048 | $domain = join( '.', $new_subs ); |
2049 |
|
2050 | // Put the email back together |
2051 | $email = $local . '@' . $domain; |
2052 |
|
2053 | // Congratulations your email made it! |
2054 | return apply_filters( 'sanitize_email', $email, $email, null ); |
2055 | } |
2056 |
|
2057 | /** |
2058 | * Determines the difference between two timestamps. |
2059 | * |
2060 | * The difference is returned in a human readable format such as "1 hour", |
2061 | * "5 mins", "2 days". |
2062 | * |
2063 | * @since 1.5.0 |