From d1ec5b6ac3a207d89b93ef1b528c8f21df633496 Mon Sep 17 00:00:00 2001 From: "Dominik Schilling (ocean90)" Date: Tue, 24 Nov 2015 23:06:03 +0000 Subject: [PATCH] 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 --- src/wp-includes/pluggable.php | 8 +++---- tests/phpunit/tests/user.php | 44 +++++++++++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index ecacab460e..88d1440599 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -1458,7 +1458,7 @@ function wp_notify_postauthor( $comment_id, $deprecated = null ) { // we want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $comment_content = wp_specialchars_decode( $comment->comment_content ); - + switch ( $comment->comment_type ) { case 'trackback': $notify_message = sprintf( __( 'New trackback on your post "%s"' ), $post->post_title ) . "\r\n"; @@ -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; } diff --git a/tests/phpunit/tests/user.php b/tests/phpunit/tests/user.php index d122617be1..3644ffcb79 100644 --- a/tests/phpunit/tests/user.php +++ b/tests/phpunit/tests/user.php @@ -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 ); + } }