#22934 closed defect (bug) (duplicate)
Notice thrown on recent comment widget for comments on custom post type
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Priority: | normal | |
| Severity: | normal | Version: | 3.5 |
| Component: | Posts, Post Types | Keywords: | |
| Focuses: | Cc: |
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;
Duplicate of #16956.