Make WordPress Core

Opened 7 years ago

Closed 7 years ago

Last modified 7 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:


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 7 years ago.

Download all attachments as: .zip

Change History (4)

#1 @markjaquith
7 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.

#2 @solarissmoke
7 years ago

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

#3 @nacin
7 years ago

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