diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php index d249ab81f5..e0cdc79a2f 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php @@ -1908,7 +1908,7 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { $schema['properties']['format'] = array( 'description' => __( 'The format for the object.' ), 'type' => 'string', - 'enum' => $supports_formats ? array_values( $supports_formats[0] ) : array(), + 'enum' => array_merge( array( 'standard' ), $supports_formats ? array_values( $supports_formats[0] ) : array() ), 'context' => array( 'view', 'edit' ), ); break; diff --git a/tests/phpunit/tests/rest-api/rest-posts-controller.php b/tests/phpunit/tests/rest-api/rest-posts-controller.php index 0e738c394d..70db2e2bd3 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -1287,6 +1287,22 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->assertEquals( 'gallery', get_post_format( $new_post->ID ) ); } + public function test_create_post_with_standard_format() { + wp_set_current_user( self::$editor_id ); + + $request = new WP_REST_Request( 'POST', '/wp/v2/posts' ); + $params = $this->set_post_data( array( + 'format' => 'standard', + ) ); + $request->set_body_params( $params ); + $response = $this->server->dispatch( $request ); + + $data = $response->get_data(); + $new_post = get_post( $data['id'] ); + $this->assertEquals( 'standard', $data['format'] ); + $this->assertFalse( get_post_format( $new_post->ID ) ); + } + public function test_create_post_with_invalid_format() { wp_set_current_user( self::$editor_id ); @@ -1753,6 +1769,22 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->assertEquals( 'gallery', get_post_format( $new_post->ID ) ); } + public function test_update_post_with_standard_format() { + wp_set_current_user( self::$editor_id ); + + $request = new WP_REST_Request( 'PUT', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); + $params = $this->set_post_data( array( + 'format' => 'standard', + ) ); + $request->set_body_params( $params ); + $response = $this->server->dispatch( $request ); + + $data = $response->get_data(); + $new_post = get_post( $data['id'] ); + $this->assertEquals( 'standard', $data['format'] ); + $this->assertFalse( get_post_format( $new_post->ID ) ); + } + public function test_update_post_with_invalid_format() { wp_set_current_user( self::$editor_id );