[wp-trac] [WordPress Trac] #22934: Notice thrown on recent comment widget for comments on custom post type

WordPress Trac noreply at wordpress.org
Fri Dec 14 10:15:40 UTC 2012


#22934: Notice thrown on recent comment widget for comments on custom post type
-----------------------------+--------------------------
 Reporter:  firebird75       |       Type:  defect (bug)
   Status:  new              |   Priority:  normal
Milestone:  Awaiting Review  |  Component:  Post Types
  Version:  3.5              |   Severity:  normal
 Keywords:                   |
-----------------------------+--------------------------
 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;
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/22934>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list