WordPress.org

Make WordPress Core

Opened 5 years ago

Closed 4 years ago

Last modified 4 years ago

#16446 closed defect (bug) (duplicate)

Edgecase bug within wp_count_comments()

Reported by: ptahdunbar Owned by:
Milestone: Priority: normal
Severity: trivial Version: 3.0
Component: Administration Keywords:
Focuses: Cc:

Description

I'm getting the following error:

Notice: Undefined index: ignored in /Users/ptah/Sites/wordpress/wp.dev/wp-includes/comment.php on line 833

This happens because on line 826 of wp-includes/comments.php WordPress is running the following code:

$approved = array('0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed');
$known_types = array_keys( $approved );
foreach ( (array) $count as $row ) {
	// Don't count post-trashed toward totals
	if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] )
		$total += $row['num_comments'];
	if ( in_array( $row['comment_approved'], $known_types ) )
		$stats[$approved[$row['comment_approved']]] = $row['num_comments'];
}

The second if statement is where the offending code happens.

Sometimes comments have a comment_approved value of 'ignored' and because $known_types has integers within that array, 'ignored' gets converted into an integer resulting in in_array returning true when it should be false.. thus comes our notice.

To fix this, in_array() needs to be running in strict mode so theirs no conversions.

Attachments (1)

ticket.16446.diff (586 bytes) - added by ptahdunbar 5 years ago.

Download all attachments as: .zip

Change History (4)

@ptahdunbar5 years ago

comment:1 @markjaquith5 years ago

  • Milestone changed from Awaiting Review to Future Release

There are more issues than just this with custom comment_approved values. I'd like to work through them, as it can be handy to introduce new comment workflow situations.

comment:2 @solarissmoke4 years ago

  • Keywords has-patch removed
  • Resolution set to duplicate
  • Status changed from new to closed

comment:3 @nacin4 years ago

  • Milestone Future Release deleted
Note: See TracTickets for help on using tickets.