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 ); + } }