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
This commit is contained in:
Boone Gorges 2015-06-04 17:28:07 +00:00
parent 6c51513a44
commit 9747d9f611
2 changed files with 16 additions and 1 deletions

View File

@ -1550,7 +1550,7 @@ function wp_notify_moderator($comment_id) {
$user = get_userdata( $post->post_author ); $user = get_userdata( $post->post_author );
// Send to the administration and to the post author if the author can modify the comment. // Send to the administration and to the post author if the author can modify the comment.
$emails = array( get_option( 'admin_email' ) ); $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' ) ) ) if ( 0 !== strcasecmp( $user->user_email, get_option( 'admin_email' ) ) )
$emails[] = $user->user_email; $emails[] = $user->user_email;
} }

View File

@ -148,4 +148,19 @@ class Tests_Comment extends WP_UnitTestCase {
unset( $_SERVER['REMOTE_ADDR'] ); 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 ) );
}
} }