#22934 closed defect (bug) (duplicate)
Notice thrown on recent comment widget for comments on custom post type
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Post Types | Version: | 3.5 |
| Severity: | normal | Keywords: | |
| Cc: | autremonde75@… |
Description
If a plugin creates a custom post type and some comments are posted for the custom post, then once the plugin is deactivated, this will generate a lot of notices in the recent comments widget on the dashboard :
"Notice: Trying to get property of non-object in /homepages/wp-includes/capabilities.php on line 1123
Notice: Trying to get property of non-object in /homepages/wp-includes/capabilities.php on line 1124
Notice: Trying to get property of non-object in /homepages/wp-includes/capabilities.php on line 1124
Notice: Trying to get property of non-object in /homepages/wp-includes/capabilities.php on line 1127
Notice: Trying to get property of non-object in /homepages/wp-includes/capabilities.php on line 1127"
Some robustness is required there :
if ( ! $post_type->map_meta_cap ) {
$caps[] = $post_type->cap->$cap;
// Prior to 3.1 we would re-call map_meta_cap here.
if ( 'read_post' == $cap )
$cap = $post_type->cap->$cap;
break;
}
$status_obj = get_post_status_object( $post->post_status );
if ( $status_obj->public ) {
$caps[] = $post_type->cap->read;
break;
}
Suggested fix :
if ( is_object($post_type) && ! $post_type->map_meta_cap ) {
$caps[] = $post_type->cap->$cap;
// Prior to 3.1 we would re-call map_meta_cap here.
if ( 'read_post' == $cap )
$cap = $post_type->cap->$cap;
break;
}
$status_obj = get_post_status_object( $post->post_status );
if ( $status_obj->public ) {
if (is_object($post_type))
$caps[] = $post_type->cap->read;
break;
}
Same on line 1181 :
case 'edit_comment': $comment = get_comment( $args[0] ); $post = get_post( $comment->comment_post_ID ); $post_type_object = get_post_type_object( $post->post_type ); if (is_object($post_type_object)) // Test added here $caps = map_meta_cap( $post_type_object->cap->edit_post, $user_id, $post->ID ); break;
Change History (4)
comment:1
firebird75 — 5 months ago
- Cc autremonde75@… added
comment:2
SergeyBiryukov — 5 months ago
- Milestone Awaiting Review deleted
- Resolution set to duplicate
- Status changed from new to closed
The fix is not a duplicate and seems easier to apply than the patch proposed 2 years ago in #16956.
Thanks to firebird75 ...
comment:4
SergeyBiryukov — 13 days ago
The ticket reports the same issue, so it's a duplicate.
The patch in #16956 was actually proposed 8 months ago.

Duplicate of #16956.