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
This commit is contained in:
Rachel Baker 2016-11-18 18:12:31 +00:00
parent 735fa34d42
commit ccb4c7c8b9
2 changed files with 10 additions and 8 deletions

View File

@ -991,14 +991,16 @@ class WP_REST_Posts_Controller extends WP_REST_Controller {
} }
// Parent. // Parent.
if ( ! empty( $schema['properties']['parent'] ) && ! empty( $request['parent'] ) ) { if ( ! empty( $schema['properties']['parent'] ) && isset( $request['parent'] ) ) {
$parent = get_post( (int) $request['parent'] ); if ( 0 === (int) $request['parent'] ) {
$prepared_post->post_parent = 0;
if ( empty( $parent ) ) { } else {
return new WP_Error( 'rest_post_invalid_id', __( 'Invalid post parent ID.' ), array( 'status' => 400 ) ); $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. // Menu order.

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @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. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.