Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: sanitize_email

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 8 times in this file.

Line Code
3708            * 'email_no_at', 'local_invalid_chars', 'domain_period_sequence', 'domain_period_limits',
3709            * 'domain_no_periods', 'domain_no_valid_subs', or no context.
3710            *
3711            * @since 2.8.0
3712            *
3713            * @param string $sanitized_email The sanitized email address.
3714            * @param string $email           The email address, as provided to sanitize_email().
3715            * @param string|null $message    A message to pass to the user. null if email is sanitized.
3716            */
3717           return apply_filters( 'sanitize_email', '', $email, 'email_too_short' );
3718      }
3719
3720      // Test for an @ character after the first position.
3721      if ( strpos( $email, '@', 1 ) === false ) {
3722           /** This filter is documented in wp-includes/formatting.php */
3723           return apply_filters( 'sanitize_email', '', $email, 'email_no_at' );
3724      }
3725
3726      // Split out the local and domain parts.
3727      list( $local, $domain ) = explode( '@', $email, 2 );
3728
3729      // LOCAL PART
3730      // Test for invalid characters.
3731      $local = preg_replace( '/[^a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.-]/', '', $local );
3732      if ( '' === $local ) {
3733           /** This filter is documented in wp-includes/formatting.php */
3734           return apply_filters( 'sanitize_email', '', $email, 'local_invalid_chars' );
3735      }
3736
3737      // DOMAIN PART
3738      // Test for sequences of periods.
3739      $domain = preg_replace( '/\.{2,}/', '', $domain );
3740      if ( '' === $domain ) {
3741           /** This filter is documented in wp-includes/formatting.php */
3742           return apply_filters( 'sanitize_email', '', $email, 'domain_period_sequence' );
3743      }
3744
3745      // Test for leading and trailing periods and whitespace.
3746      $domain = trim( $domain, " \t\n\r\0\x0B." );
3747      if ( '' === $domain ) {
3748           /** This filter is documented in wp-includes/formatting.php */
3749           return apply_filters( 'sanitize_email', '', $email, 'domain_period_limits' );
3750      }
3751
3752      // Split the domain into subs.
3753      $subs = explode( '.', $domain );
3754
3755      // Assume the domain will have at least two subs.
3756      if ( 2 > count( $subs ) ) {
3757           /** This filter is documented in wp-includes/formatting.php */
3758           return apply_filters( 'sanitize_email', '', $email, 'domain_no_periods' );
3759      }
3760
3761      // Create an array that will contain valid subs.
3762      $new_subs = array();
3763
3764      // Loop through each sub.
3765      foreach ( $subs as $sub ) {
3766           // Test for leading and trailing hyphens.
3767           $sub = trim( $sub, " \t\n\r\0\x0B-" );
 
Line Code
3772           // If there's anything left, add it to the valid subs.
3773           if ( '' !== $sub ) {
3774                $new_subs[] = $sub;
3775           }
3776      }
3777
3778      // If there aren't 2 or more valid subs.
3779      if ( 2 > count( $new_subs ) ) {
3780           /** This filter is documented in wp-includes/formatting.php */
3781           return apply_filters( 'sanitize_email', '', $email, 'domain_no_valid_subs' );
3782      }
3783
3784      // Join valid subs into the new domain.
3785      $domain = implode( '.', $new_subs );
3786
3787      // Put the email back together.
3788      $sanitized_email = $local . '@' . $domain;
3789
3790      // Congratulations, your email made it!
3791      /** This filter is documented in wp-includes/formatting.php */
3792      return apply_filters( 'sanitize_email', $sanitized_email, $email, null );
3793 }
3794
3795 /**
3796  * Determines the difference between two timestamps.
3797  *
3798  * The difference is returned in a human readable format such as "1 hour",
3799  * "5 mins", "2 days".
3800  *
3801  * @since 1.5.0