[wp-trac] [WordPress Trac] #55877: wp_insert_post() should check that a post type exists before using it

WordPress Trac noreply at wordpress.org
Mon May 30 16:17:25 UTC 2022


#55877: wp_insert_post() should check that a post type exists before using it
-------------------------------+-----------------------------
 Reporter:  Chouby             |      Owner:  (none)
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  5.1
 Severity:  normal             |   Keywords:
  Focuses:                     |
-------------------------------+-----------------------------
 In #27335 it was accepted that `wp_insert_post()` can insert a post from
 an unknown post type - although not consistent with `wp_insert_term()`
 which returns a `WP_Error` for an invalid taxonomy but that's another
 issue.

 Later, [changeset:"42380"] introduced some usage of the post type object
 inside `wp_insert_post()`, still without checking that the post type
 exists.

 Thus writing a test including:
 {{{#!php
 <?php
 $args = array(
         'post_title'  => 'My post',
         'post_type'   => 'unregistered',
         'post_status' => 'pending'
 )
 $post_id = wp_insert_post( $args );
 }}}
 will fire the error `Trying to get property 'cap' of non-object`.

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


More information about the wp-trac mailing list