Make WordPress Core

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#22934 closed defect (bug) (duplicate)

Notice thrown on recent comment widget for comments on custom post type

Reported by: firebird75's profile firebird75 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;

Change History (4)

#1 @firebird75
12 years ago

  • Cc autremonde75@… added

#2 @SergeyBiryukov
12 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #16956.

#3 @ddavout
12 years ago

The fix is not a duplicate and seems easier to apply than the patch proposed 2 years ago in #16956.
Thanks to firebird75 ...

#4 @SergeyBiryukov
12 years ago

The ticket reports the same issue, so it's a duplicate.

The patch in #16956 was actually proposed 8 months ago.

Note: See TracTickets for help on using tickets.