Opened 2 years ago

Last modified 13 days ago

#16956 new defect (bug)

Comments Being Pulled from Non-Existent Post Types

Reported by: sterlo Owned by:
Priority: normal Milestone: 3.6
Component: Post Types Version: 3.1
Severity: normal Keywords: has-patch
Cc: boonebgorges@…, mitcho@…

Description

Originally on: #10461

I'm running standard LAMP on the latest trunk.

Just viewing the dashboard with no plugins activated:

Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 918 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 918 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 918 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 918 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 918 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 918 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 919 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 Notice: Trying to get property of non-object in /Users/grok/Projects/Local Development/wordpress/trunk/wp-includes/capabilities.php on line 922 

It's not recognizing "$post_type->cap" as valid.

And...here's why - I added this (/wp-includes/capabilities.php):

 918 echo "POST TYPE: Y U NO OBJECT?\n";
 919 var_dump($post_type);

And got:

POST TYPE: Y U NO OBJECT?
NULL

So in this context...the post type is null and the code was not expecting that.

Opening the actual $post object:

stdClass Object
(
    [ID] => 60
    [post_author] => 1
    [post_date] => 2011-01-28 19:46:23
    [post_date_gmt] => 2011-01-28 19:46:23
    [post_content] => CONTENT!
    [post_title] => I have it all!
    [post_excerpt] => 
    [post_status] => publish
    [comment_status] => open
    [ping_status] => open
    [post_password] => 
    [post_name] => i-have-it-all
    [to_ping] => 
    [pinged] => 
    [post_modified] => 2011-01-28 19:46:28
    [post_modified_gmt] => 2011-01-28 19:46:28
    [post_content_filtered] => 
    [post_parent] => 0
    [guid] => http://dev.wordpress.local/?post_type=staff_listing&p=60
    [menu_order] => 0
    [post_type] => staff_listing
    [post_mime_type] => 
    [comment_count] => 6
    [ancestors] => Array
        (
        )

    [filter] => raw
)

I think the problem might be custom post types or custom taxonomies...

So my custom post type in another plugin is creating: "?post_type=staff_listing".
And this post does show "[post_type] => staff_listing". BUT the plugin that had created these comments...is de-activated.

Activating the plugin resolves this issue.

So, whats a viable solution? Telling a developer to clean up after the plugin (removing content just because of deactivation), OR having WordPress not pull data (e.g. comments) that are assigned to other data (e.g. post types) that don't exist?

Old Code: Give me all comments.

New Code: Give me all comments that are tied to existing objects.

Attachments (2)

16956.diff (1.6 KB) - added by mitchoyoshitaka 9 months ago.
Patch v1
16956.2.diff (1.6 KB) - added by mitchoyoshitaka 2 weeks ago.
Patch v1 (fixed patchrot, 2013 May 9)

Download all attachments as: .zip

Change History (15)

  • Keywords dev-feedback added

comment:2   dd322 years ago

  • Component changed from General to Warnings/Notices
  • Keywords dev-feedback removed
  • Type changed from enhancement to defect (bug)

Closed #17839 as duplicate.

Noticed in the recent comments widget:

( ! ) Notice: Trying to get property of non-object in C:\www\wordpress-commit\wp-includes\capabilities.php on line 929
Call Stack
#	Time	Memory	Function	Location
1	0.0005	360328	{main}( )	..\index.php:0
2	0.3960	24624984	wp_dashboard( )	..\index.php:63
3	0.3960	24625272	do_meta_boxes( string(9), string(6), string(0) )	..\dashboard.php:221
4	0.8141	25014760	call_user_func ( string(28), string(0), array(4) )	..\template.php:970
5	0.8141	25014776	wp_dashboard_recent_comments( string(0), array(4) )	..\template.php:0
6	0.8171	25271192	current_user_can( string(9), string(3) )	..\dashboard.php:632
7	0.8171	25271784	call_user_func_array ( array(2), array(2) )	..\capabilities.php:1047
8	0.8171	25272048	WP_User->has_cap( string(9), string(3) )	..\capabilities.php:0
9	0.8172	25272448	call_user_func_array ( string(12), array(3) )	..\capabilities.php:729
10	0.8172	25272736	map_meta_cap( string(9), string(1), string(3) )	..\capabilities.php:0

Turns out, that it's a comment on a custom post type that's no longer registered.

As a result $post_type = get_post_type_object( $post->post_type ); fails to return a valid post type object (however, get_post() can still return the cpt) which results in the code operating on a null object.

  • Cc boonebgorges@… added

Since the problem is related to map_meta_cap(), maybe it's best not to mess with the query but instead to solve the problem at the level of caps. Maybe when get_post_type_object( $post->post_type ) returns null, add 'do_not_allow' to $caps and bail?

Maybe when get_post_type_object( $post->post_type ) returns null, add 'do_not_allow' to $caps and bail?

At the very least, we should be checking for a null value there, yes.

Patch v1

  • Cc mitcho@… added
  • Keywords has-patch added

Still an issue in trunk (3.5 alpha); attached patch based on boone and nacin's discussion. Patch fixes notices on my local trunk which were due to sterlo's initial situation (data from stray custom post types).

#22719 was marked as a duplicate.

#22934 was marked as a duplicate.

  • Component changed from Warnings/Notices to Post Types

It is not so easy to apply a patch dating of 2 years ...

  • Milestone changed from Awaiting Review to 3.6

Patch v1 (fixed patchrot, 2013 May 9)

Replying to ddavout:

It is not so easy to apply a patch dating of 2 years ...

Not sure which patch you were trying (mine was not 2 years old) but it might not have applied cleanly. I went ahead and updated it against trunk.

comment:12 follow-up: ↓ 13   sterlo2 weeks ago

It's ALIVE!!!!

http://i.imgur.com/bhNML.gif

comment:13 in reply to: ↑ 12   mitchoyoshitaka13 days ago

Replying to sterlo:

It's ALIVE!!!!

Rumors of this ticket's death (or maybe my death) have been greatly exaggerated.

Note: See TracTickets for help on using tickets.