Passwords: Support the pre-4.3 behavior of wp_new_user_notification().

Hello, it's me again. A pluggable function named `wp_new_user_notification()`. A few months ago, after [33023], I have lost my second parameter `$plaintext_pass`. But thanks to [33620] I got a new one.
Bad idea - It hasn't had the same behavior as my previous parameter.
To solve that the second parameter got deprecated and reintroduced as the third parameter in [34116]. I was happy again, for a short time.
You remember my lost friend `$plaintext_pass`? No? Well, if its value was empty no notification was sent to the user. This behavior was still lost. And that's what this change is about: Don't notify a user if a plugin uses `wp_new_user_notification( $user_id )`.

You're asking if I'm happy now? Dunno, but maybe you have learned something about pluggable functions, have you?

Props danielbachhuber.
Fixes #34377.

git-svn-id: https://develop.svn.wordpress.org/trunk@35735 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dominik Schilling (ocean90) 2015-11-24 23:06:03 +00:00
parent 50c47fa78c
commit d1ec5b6ac3
2 changed files with 46 additions and 6 deletions

View File

@ -1737,8 +1737,7 @@ if ( !function_exists('wp_new_user_notification') ) :
* @param int $user_id User ID.
* @param null $deprecated Not used (argument deprecated).
* @param string $notify Optional. Type of notification that should happen. Accepts 'admin' or an empty
* string (admin only), or 'both' (admin and user). The empty string value was kept
* for backward-compatibility purposes with the renamed parameter. Default empty.
* string (admin only), or 'both' (admin and user). Default empty.
*/
function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) {
if ( $deprecated !== null ) {
@ -1758,7 +1757,8 @@ function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' )
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message);
if ( 'admin' === $notify || empty( $notify ) ) {
// `$deprecated was pre-4.3 `$plaintext_pass`. An empty `$plaintext_pass` didn't sent a user notifcation.
if ( 'admin' === $notify || ( empty( $deprecated ) && empty( $notify ) ) ) {
return;
}

View File

@ -1040,8 +1040,48 @@ class Tests_User extends WP_UnitTestCase {
* @ticket 33654
* @expectedDeprecated wp_new_user_notification
*/
function test_wp_new_user_notification_old_signature_throws_deprecated_warning() {
wp_new_user_notification( self::$author_id, 'this_is_deprecated' );
function test_wp_new_user_notification_old_signature_throws_deprecated_warning_but_sends() {
unset( $GLOBALS['phpmailer']->mock_sent );
$was_admin_email_sent = false;
$was_user_email_sent = false;
wp_new_user_notification( self::$contrib_id, 'this_is_a_test_password' );
/*
* Check to see if a notification email was sent to the
* post author `blackburn@battlefield3.com` and and site admin `admin@example.org`.
*/
if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) {
$was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
$was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' == $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] );
}
$this->assertTrue( $was_admin_email_sent );
$this->assertTrue( $was_user_email_sent );
}
/**
* Set up a user and try sending a notification using `wp_new_user_notification( $user );`.
*
* @ticket 34377
*/
function test_wp_new_user_notification_old_signature_no_password() {
unset( $GLOBALS['phpmailer']->mock_sent );
$was_admin_email_sent = false;
$was_user_email_sent = false;
wp_new_user_notification( self::$contrib_id );
/*
* Check to see if a notification email was sent to the
* post author `blackburn@battlefield3.com` and and site admin `admin@example.org`.
*/
if ( ! empty( $GLOBALS['phpmailer']->mock_sent ) ) {
$was_admin_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[0] ) && WP_TESTS_EMAIL == $GLOBALS['phpmailer']->mock_sent[0]['to'][0][0] );
$was_user_email_sent = ( isset( $GLOBALS['phpmailer']->mock_sent[1] ) && 'blackburn@battlefield3.com' == $GLOBALS['phpmailer']->mock_sent[1]['to'][0][0] );
}
$this->assertTrue( $was_admin_email_sent );
$this->assertFalse( $was_user_email_sent );
}
}