Make WordPress Core


Ignore:
Timestamp:
11/18/2016 06:11:49 PM (8 years ago)
Author:
rachelbaker
Message:

REST API: Allow parent property to be explicitly set to 0 when creating or updating a Post.

Props lucasstark, danielbachhuber.
Fixes #38852.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r39278 r39289  
    992992
    993993        // Parent.
    994         if ( ! empty( $schema['properties']['parent'] ) && ! empty( $request['parent'] ) ) {
    995             $parent = get_post( (int) $request['parent'] );
    996 
    997             if ( empty( $parent ) ) {
    998                 return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post parent ID.' ), array( 'status' => 400 ) );
    999             }
    1000 
    1001             $prepared_post->post_parent = (int) $parent->ID;
     994        if ( ! empty( $schema['properties']['parent'] ) && isset( $request['parent'] ) ) {
     995            if ( 0 === (int) $request['parent'] ) {
     996                $prepared_post->post_parent = 0;
     997            } else {
     998                $parent = get_post( (int) $request['parent'] );
     999                if ( empty( $parent ) ) {
     1000                    return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post parent ID.' ), array( 'status' => 400 ) );
     1001                }
     1002                $prepared_post->post_parent = (int) $parent->ID;
     1003            }
    10021004        }
    10031005
Note: See TracChangeset for help on using the changeset viewer.