[wp-trac] [WordPress Trac] #16446: Edgecase bug within wp_count_comments()

WordPress Trac wp-trac at lists.automattic.com
Thu Feb 3 01:34:24 UTC 2011


#16446: Edgecase bug within wp_count_comments()
----------------------------+-----------------------------
 Reporter:  ptahdunbar      |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Administration  |    Version:  3.0
 Severity:  trivial         |   Keywords:  has-patch
----------------------------+-----------------------------
 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.

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/16446>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list