WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 5 months ago

#28488 new defect (bug)

get_post_type_object on CPT in _count_posts_cache_key after a wp_insert_post returns null

Reported by: barrykooij Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.9.1
Component: Posts, Post Types Keywords: has-patch
Focuses: Cc:
PR Number:

Description

After running a wp_insert_post in one of my plugins I got the following notices because get_post_type_object in _count_posts_cache_key returns null. I've added a simple not equals null check to the function to prevent these notices.

Backtrace:

Backtrace from warning 'Trying to get property of non-object' at /vagrant/latest/wp-includes/post.php 2188:

/vagrant/latest/wp-includes/post.php 5484 calling _count_posts_cache_key()
calling _transition_post_status()
/vagrant/latest/wp-includes/plugin.php 470 calling call_user_func_array()
/vagrant/latest/wp-includes/post.php 3665 calling do_action()
/vagrant/latest/wp-includes/post.php 3200 calling wp_transition_post_status()
/vagrant/latest/wp-content/plugins/my-plugin/core/classes/class-connection-manager-core.php 34 calling wp_insert_post()
/vagrant/latest/wp-content/plugins/my-plugin/core/classes/class-connection-manager-core.php 271 calling add()
/vagrant/latest/wp-content/plugins/my-plugin/core/classes/class-admin-menu.php 117 calling save()
calling handle_post()
/vagrant/latest/wp-includes/plugin.php 470 calling call_user_func_array()
/vagrant/latest/wp-admin/admin.php 144 calling do_action()

Backtrace from warning 'Trying to get property of non-object' at /vagrant/latest/wp-includes/post.php 2188:

/vagrant/latest/wp-includes/post.php 5484 calling _count_posts_cache_key()
calling _transition_post_status()
/vagrant/latest/wp-includes/plugin.php 470 calling call_user_func_array()
/vagrant/latest/wp-includes/post.php 3665 calling do_action()
/vagrant/latest/wp-includes/post.php 3200 calling wp_transition_post_status()
/vagrant/latest/wp-content/plugins/my-plugin/core/classes/class-connection-manager-core.php 34 calling wp_insert_post()
/vagrant/latest/wp-content/plugins/my-plugin/core/classes/class-connection-manager-core.php 271 calling add()
/vagrant/latest/wp-content/plugins/my-plugin/core/classes/class-admin-menu.php 117 calling save()
calling handle_post()
/vagrant/latest/wp-includes/plugin.php 470 calling call_user_func_array()
/vagrant/latest/wp-admin/admin.php 144 calling do_action()

Backtrace from warning 'Cannot modify header information - headers already sent' at /vagrant/latest/wp-includes/pluggable.php 1121:

/vagrant/latest/wp-includes/pluggable.php 1121 calling header()
/vagrant/latest/wp-content/plugins/my-plugin/core/classes/class-admin-menu.php 119 calling wp_redirect()
calling handle_post()
/vagrant/latest/wp-includes/plugin.php 470 calling call_user_func_array()
/vagrant/latest/wp-admin/admin.php 144 calling do_action()

Attachments (1)

post.php.diff (606 bytes) - added by barrykooij 5 years ago.

Download all attachments as: .zip

Change History (8)

@barrykooij
5 years ago

#1 @figureone
5 years ago

I'm getting this too; the patch looks fine.

#2 @p51labs
5 years ago

I am getting this as well. it really should check to see if anything was returned before it checks for an attribute. Any chance of this getting into 4.0?

This ticket was mentioned in IRC in #wordpress-dev by barrykooij. View the logs.


5 years ago

#4 @barrykooij
5 years ago

What would need to be done to get this merged into core?

#5 @ocean90
5 years ago

_count_posts_cache_key() is fixed with [29318]. Seems like only wp_count_posts() is missing.

#6 @DrewAPicture
5 years ago

  • Component changed from General to Posts, Post Types

#7 @chriscct7
4 years ago

  • Keywords has-patch added
Note: See TracTickets for help on using tickets.