WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 3 years ago

#15215 closed defect (bug) (fixed)

wp_count_comments throws Error Notice for unknown comment_approved types

Reported by: batmoo Owned by: ryan
Milestone: 3.2 Priority: normal
Severity: normal Version: 3.0.1
Component: Comments Keywords: has-patch 3.2-early
Focuses: Cc:

Description

If you have any comments with a comment_approved value of an "unknown type" (i.e. anything other than '0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed'), wp_count_comments throws an error notice.

Notice: Undefined index: 'my-custom-approved' in /Users/moo/Sites/dev/WordPress/wp-includes/comment.php on line 858

Setting the in_array check to strict, fixes the error.

Attachments (2)

wp_count_comments.15215.diff (586 bytes) - added by batmoo 4 years ago.
3.1-wp_count_comments.patch (772 bytes) - added by tfnab 3 years ago.
Alternative way of fixing this; patch for 3.1 which has the same issue

Download all attachments as: .zip

Change History (10)

comment:1 batmoo4 years ago

  • Cc batmoo@… added
  • Keywords has-patch added

Patch sets in_array check on wp_count_comments to strict.

comment:2 dd323 years ago

  • Keywords 3.2-early added
  • Milestone changed from Awaiting Review to Future Release

comment:3 markjaquith3 years ago

Would really be nice to have full support for custom comment statuses. You can't really do it properly now.

comment:4 hakre3 years ago

+1 Patch looks good in my eyes, strict check is reasonable. Everything else can be done in an additional ticket if there really is a want for it.

tfnab3 years ago

Alternative way of fixing this; patch for 3.1 which has the same issue

comment:5 tfnab3 years ago

+1
Please re-consider fixing this ASAP, i.e. before 3.2, but maybe with another minor version number release, as this has me changing core to avoid the notices thrown, and it makes the update process much more annoying (but I want to stay updated in case of any security issues)!

Thank you.

I've added another patch that removes the unneccessary $known_types variable

comment:6 nacin3 years ago

Notices aren't enough for point releases. Especially for API usage that is technically unsupported.

comment:7 nacin3 years ago

  • Milestone changed from Future Release to 3.2

comment:8 ryan3 years ago

  • Owner set to ryan
  • Resolution set to fixed
  • Status changed from new to closed

In [17795]:

Fix notice thrown in wp_count_comments(). Props tfnab, batmoo. fixes #15215

Note: See TracTickets for help on using tickets.