From 2e805b2b99fe9987f514d385a6c8b2b6c4809226 Mon Sep 17 00:00:00 2001 From: SirLouen Date: Thu, 7 Aug 2025 17:57:57 +0200 Subject: [PATCH] Refresh for 28618 --- src/wp-includes/pluggable.php | 11 +++++++++++ tests/phpunit/includes/functions.php | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index 1dbac5e1d707c..a977f9a4d0cdf 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -254,6 +254,17 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() require_once ABSPATH . WPINC . '/class-wp-phpmailer.php'; $phpmailer = new WP_PHPMailer( true ); + /** + * Filters the PHPMailer object. + * + * Allows plugins to override the PHPMailer class with one of their own if required. + * + * @since 6.9.0 + * + * @param object $phpmailer A PHPMailer (or compatible) class. + */ + $phpmailer = apply_filters( 'wp_phpmailer', $phpmailer ); + $phpmailer::$validator = static function ( $email ) { return (bool) is_email( $email ); }; diff --git a/tests/phpunit/includes/functions.php b/tests/phpunit/includes/functions.php index 516727380c109..fa26df40c40c3 100644 --- a/tests/phpunit/includes/functions.php +++ b/tests/phpunit/includes/functions.php @@ -363,3 +363,14 @@ function _unhook_font_registration() { remove_action( 'init', '_wp_register_default_font_collections' ); } tests_add_filter( 'init', '_unhook_font_registration', 1000 ); + +/** + * Ensure that PHPMailer is always a MockPHPMailer + * + * @param object $phpmailer The PHPMailer object. + * @return object The MockPHPMailer object. + */ +function _wp_phpmailer( $phpmailer ) { + return new MockPHPMailer(); +} +tests_add_filter( 'wp_phpmailer', '_wp_phpmailer' );