#16446 closed defect (bug) (duplicate)
Edgecase bug within wp_count_comments()
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Administration | Version: | 3.0 |
| Severity: | trivial | Keywords: | |
| 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)
Change History (4)
ptahdunbar
— 2 years ago
comment:1
markjaquith
— 2 years ago
- Milestone changed from Awaiting Review to Future Release
comment:2
solarissmoke
— 2 years ago
- Keywords has-patch removed
- Resolution set to duplicate
- Status changed from new to closed
Note: See
TracTickets for help on using
tickets.
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.