Make WordPress Core


Ignore:
Timestamp:
06/10/2026 03:04:54 PM (2 months ago)
Author:
dmsnell
Message:

General: Add support for unicode email addresses in is_email and sanitize_email

This adds support for the unicode address extensions in RFC 6530-3 and refactors the code so there are fewer long regexes and less duplication between sanitize_email and is_email. A new class, WP_Email_Address, provides the shared parts.

Opting out of unicode support is easy, default-filters.php adds unicode support by adding filters, which can be removed.

sanitize_email no longer does major changes like removing an entire subdomain from someone's address, it only cleans up things like soft hyphens and whitespace — changes that happen when coping an email address from text.

Developed in: https://github.com/WordPress/wordpress-develop/pull/5237
Discussed in: https://core.trac.wordpress.org/ticket/31992

Props agulbra, akirk, benniledl, dmsnell, ironprogrammer, justlevine, mdawaffe, mukeshpanchal27, SirLouen, tusharbharti.
Fixes #31992.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/default-filters.php

    r62428 r62482  
    8686        add_filter( $filter, 'sanitize_url' );
    8787        add_filter( $filter, 'wp_filter_kses' );
     88}
     89
     90// Email addresses: Allow unicode if and only if as the database can
     91// store them. This affects all addresses, including those entered
     92// into contact forms.
     93if ( 'utf8mb4' === $wpdb->charset ) {
     94        add_filter( 'is_email', 'wp_is_unicode_email', 10, 3 );
     95        add_filter( 'sanitize_email', 'wp_sanitize_unicode_email', 10, 3 );
     96} else {
     97        add_filter( 'is_email', 'wp_is_ascii_email', 10, 3 );
     98        add_filter( 'sanitize_email', 'wp_sanitize_ascii_email', 10, 3 );
    8899}
    89100
Note: See TracChangeset for help on using the changeset viewer.