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.