From ccb4c7c8b978087c5452a38bc63f487eeeb29dde Mon Sep 17 00:00:00 2001 From: Rachel Baker Date: Fri, 18 Nov 2016 18:12:31 +0000 Subject: [PATCH] REST API: Allow `parent` property to be explicitly set to `0` when creating or updating a Post. Props lucasstark, danielbachhuber. Fixes #38852. Built from https://develop.svn.wordpress.org/trunk@39289 git-svn-id: http://core.svn.wordpress.org/trunk@39229 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../endpoints/class-wp-rest-posts-controller.php | 16 +++++++++------- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index f4c4cc7879..3265691f7f 100644 --- a/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -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. diff --git a/wp-includes/version.php b/wp-includes/version.php index 18d4737f3d..d192da5b12 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-beta4-39288'; +$wp_version = '4.7-beta4-39289'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.