[wp-trac] [WordPress Trac] #48653: PHP Notices when requesting a post with an unregistered status

WordPress Trac noreply at wordpress.org
Fri Nov 15 11:07:37 UTC 2019


#48653: PHP Notices when requesting a post with an unregistered status
--------------------------+-----------------------------
 Reporter:  roytanck      |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Plugins can register new post statuses using {{{register_post_status}}}.
 When such a plugin is then disabled, it is possible that posts remain in
 the database with a post status that is no longer registered. In such
 cases, {{{get_post_status_object}}} will return {{{null}}}. This return
 value is not handled correctly in {{{map_meta_cap}}} and the WP_Query
 class, causing PHP notices.

 Step to reproduce:
 * Set WP_DEBUG to true in wp-config.php.
 * Create posts with {{{post_status}}} that is not native to WordPress (I
 use "bogus"). The quickest way to fake this is to edit the database
 directly.
 * Request the post using the REST API, or by calling its guid/permalink in
 the browser.
 * PHP Notices will be shown, saying something like "Notice: Trying to get
 property 'public' of non-object".

 This can be fixed by adding some defensive programming in the map_meta_cap
 function, and the WP_Query class. I'll attach a patch that suggests a way
 to do this.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/48653>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list