Make WordPress Core

Opened 9 months ago

Closed 9 months ago

Last modified 8 months ago

#24803 closed defect (bug) (fixed)

wp_counts_posts produces a notice if a non existant post type is specified

Reported by: creativeinfusion Owned by: nacin
Milestone: 3.7 Priority: normal
Severity: trivial Version: 3.0
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:


Calling wp_count_posts with a non existant post type and perm='readable' produces a notice.

wp_count_posts ('doesnotexist', 'readable') will generate

Notice: Trying to get property of non-object in wp-includes/post.php

Attachments (4)

24803.diff (747 bytes) - added by creativeinfusion 9 months ago.
24803.2.diff (1.4 KB) - added by johnpbloch 9 months ago.
24803.3.diff (395 bytes) - added by johnpbloch 9 months ago.
Updated patch with feedback from Aaron Campbell
24803.test.diff (756 bytes) - added by johnpbloch 9 months ago.
Unit test

Download all attachments as: .zip

Change History (12)

creativeinfusion9 months ago

comment:1 creativeinfusion9 months ago

  • Keywords has-patch added

johnpbloch9 months ago

johnpbloch9 months ago

Updated patch with feedback from Aaron Campbell

comment:2 johnpbloch9 months ago

Instead of checking the post type, it would make more sense for the function to simply return an empty object right away.

comment:3 nacin9 months ago

WP_Error might be better but this function has existed around too long, and it doesn't fail hard enough to justify a new return type.

comment:4 johnpbloch9 months ago

Yeah, the second patch returns WP_Error; if we want to do it that way, we can just use that patch. :D

comment:5 johnpbloch9 months ago

Except for the typo in the query. Fat fingers. 24803.3.diff is the patch, though. Unit tests are forthcoming.

johnpbloch9 months ago

Unit test

comment:6 nacin9 months ago

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

In 24826:

Return an empty stdClass from wp_count_posts() when a nonexistent post type is requested.

props johnpbloch.
fixes #24803.

comment:7 ocean908 months ago

  • Milestone changed from Awaiting Review to 3.7
Note: See TracTickets for help on using tickets.