From 9747d9f6114c3a863d48050a506ecd94732f3e15 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Thu, 4 Jun 2015 17:28:07 +0000 Subject: [PATCH] In `wp_notify_moderator()`, don't throw notice when comment belongs to a post with no author. Props Oxymoron. Fixes #32566. git-svn-id: https://develop.svn.wordpress.org/trunk@32692 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/pluggable.php | 2 +- tests/phpunit/tests/comment.php | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/pluggable.php b/src/wp-includes/pluggable.php index fc0356aedf..a166ab017a 100644 --- a/src/wp-includes/pluggable.php +++ b/src/wp-includes/pluggable.php @@ -1550,7 +1550,7 @@ function wp_notify_moderator($comment_id) { $user = get_userdata( $post->post_author ); // Send to the administration and to the post author if the author can modify the comment. $emails = array( get_option( 'admin_email' ) ); - if ( user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { + if ( $user && user_can( $user->ID, 'edit_comment', $comment_id ) && ! empty( $user->user_email ) ) { if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) ) $emails[] = $user->user_email; } diff --git a/tests/phpunit/tests/comment.php b/tests/phpunit/tests/comment.php index 854619572d..b12474ebfb 100644 --- a/tests/phpunit/tests/comment.php +++ b/tests/phpunit/tests/comment.php @@ -148,4 +148,19 @@ class Tests_Comment extends WP_UnitTestCase { unset( $_SERVER['REMOTE_ADDR'] ); } } + + /** + * @ticket 32566 + */ + public function test_wp_notify_moderator_should_not_throw_notice_when_post_author_is_0() { + $p = $this->factory->post->create( array( + 'post_author' => 0, + ) ); + + $c = $this->factory->comment->create( array( + 'comment_post_ID' => $p, + ) ); + + $this->assertTrue( wp_notify_moderator( $c ) ); + } }