[wp-trac] [WordPress Trac] #38852: REST API Unable to Set Parent to 0

WordPress Trac noreply at wordpress.org
Fri Nov 18 17:27:16 UTC 2016


#38852: REST API Unable to Set Parent to 0
--------------------------+-----------------------------
 Reporter:  lucasstark    |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Inside of WP_Rest_Posts_Controller::prepare_item_for_database there is a
 problem around the parent property.

 The code checks if the parent is not empty, which, if you are trying to
 set the parent to 0 it will appear to be empty so the property is never
 setup for the database update.


 {{{
 // Parent.
                 if ( ! empty( $schema['properties']['parent'] ) && !
 empty( $request['parent'] ) ) {
                         $parent = get_post( (int) $request['parent'] );

                         if ( empty( $parent ) ) {
                                 return new WP_Error(
 'rest_post_invalid_id', __( 'Invalid post parent ID.' ), array( 'status'
 => 400 ) );
                         }

                         $prepared_post->post_parent = (int) $parent->ID;
                 }
 }}}

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


More information about the wp-trac mailing list