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 | 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)
Change History (6)
#3
@
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.
Related: #36208