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

Props lucasstark, danielbachhuber.
Fixes #38852.

git-svn-id: https://develop.svn.wordpress.org/trunk@39289 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Rachel Baker
2016-11-18 18:11:49 +00:00
parent ff38fc46e4
commit 659822098a
2 changed files with 44 additions and 7 deletions
@@ -991,14 +991,16 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
}
// 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 ) );
if ( ! empty( $schema['properties']['parent'] ) && isset( $request['parent'] ) ) {
if ( 0 === (int) $request['parent'] ) {
$prepared_post->post_parent = 0;
} else {
$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;
}
$prepared_post->post_parent = (int) $parent->ID;
}
// Menu order.