mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 12:50:28 +00:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user