Skip to content

Allow PHPMailer class to be reliably overriden. Refresh for 28618 #9403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,17 @@
require_once ABSPATH . WPINC . '/class-wp-phpmailer.php';
$phpmailer = new WP_PHPMailer( true );

/**
* Filters the PHPMailer object.

Check failure on line 258 in src/wp-includes/pluggable.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Tabs must be used to indent lines; spaces are not allowed
*

Check failure on line 259 in src/wp-includes/pluggable.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Tabs must be used to indent lines; spaces are not allowed
* Allows plugins to override the PHPMailer class with one of their own if required.

Check failure on line 260 in src/wp-includes/pluggable.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Tabs must be used to indent lines; spaces are not allowed
*

Check failure on line 261 in src/wp-includes/pluggable.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Tabs must be used to indent lines; spaces are not allowed
* @since 6.9.0

Check failure on line 262 in src/wp-includes/pluggable.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Tabs must be used to indent lines; spaces are not allowed
*

Check failure on line 263 in src/wp-includes/pluggable.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Tabs must be used to indent lines; spaces are not allowed
* @param object $phpmailer A PHPMailer (or compatible) class.

Check failure on line 264 in src/wp-includes/pluggable.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Tabs must be used to indent lines; spaces are not allowed
*/

Check failure on line 265 in src/wp-includes/pluggable.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Tabs must be used to indent lines; spaces are not allowed
$phpmailer = apply_filters( 'wp_phpmailer', $phpmailer );

Check failure on line 266 in src/wp-includes/pluggable.php

View workflow job for this annotation

GitHub Actions / PHP coding standards / Run coding standards checks

Tabs must be used to indent lines; spaces are not allowed

$phpmailer::$validator = static function ( $email ) {
return (bool) is_email( $email );
};
Expand Down
11 changes: 11 additions & 0 deletions tests/phpunit/includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
Loading