Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#24803 closed defect (bug) (fixed)

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

Reported by: creativeinfusion's profile creativeinfusion Owned by: nacin's profile 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 11 years ago.
24803.2.diff (1.4 KB) - added by johnpbloch 11 years ago.
24803.3.diff (395 bytes) - added by johnpbloch 11 years ago.
Updated patch with feedback from Aaron Campbell
24803.test.diff (756 bytes) - added by johnpbloch 11 years ago.
Unit test

Download all attachments as: .zip

Change History (12)

#1 @creativeinfusion
11 years ago

  • Keywords has-patch added

11 years ago

11 years ago

Updated patch with feedback from Aaron Campbell

#2 @johnpbloch
11 years ago

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

#3 @nacin
11 years 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.

#4 @johnpbloch
11 years ago

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

#5 @johnpbloch
11 years ago

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

11 years ago

Unit test

#6 @nacin
11 years 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.

#7 @ocean90
11 years ago

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