Make WordPress Core

Opened 5 years ago

Last modified 5 years ago

#47652 new defect (bug)

wp_dashboard_right_now() emits debug notices on unregistered core post types

Reported by: johnjamesjacoby's profile johnjamesjacoby Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords:
Focuses: administration Cc:

Description

When you unregister a core 'post' or 'page' post type (I know... I know...) if they have posts in the database, the dashboard "Right Now" widget will output a debug notice for each unregistered type:

Undefined property: stdClass::$publish; wp-admin/includes/dashboard.php:270

This is because the code inside of wp_dashboard_right_now() always expects a WP_Post_Status object as the return type of each wp_count_posts() key, however a stdClass return type is also possible when no registered type or status is currently registered at the time the widget is rendered.


Unregistering "built in" post types is normally considered to "void the warranty" and the unregister_post_type() function explicitly throws an error when you try, but the patch I'm about to attach is a small and bit of code hardening that prevents filling debug logs for those of us that frequently work with out-of-warranty installation types.

Attachments (1)

47652.patch (476 bytes) - added by johnjamesjacoby 5 years ago.
Add empty() checks to $num_posts variable to avoid debug notices

Download all attachments as: .zip

Change History (6)

#1 @SergeyBiryukov
5 years ago

  • Component changed from General to Posts, Post Types
  • Focuses administration added

@johnjamesjacoby
5 years ago

Add empty() checks to $num_posts variable to avoid debug notices

#3 @johnjamesjacoby
5 years ago

Attached patch very simply avoids debug notices by removing the assumption that $num_posts->publish will exist on a potential stdClass return type.

To paint my own bike-shed, this could be part of a bigger effort to support unregistering _built_in post types, but I don't think there is a ton of interest in that at the moment, so this is a small way to clean something up that (I think) should probably be done regardless.

#4 @pento
5 years ago

I'm honestly surprised that this is the only notice thrown when post or page is unregistered. 😄

I'm not wild about adding special handling for post types that shouldn't be unregistered, but I'd certainly be open to revisiting #33714, which would also fix this issue.

#5 @johnjamesjacoby
5 years ago

I'm honestly surprised that this is the only notice thrown when post or page is unregistered.

🤫

I will find more places if I keep lookin, buuuuuut… 😝

Last edited 5 years ago by johnjamesjacoby (previous) (diff)
Note: See TracTickets for help on using tickets.