From a1c2caa4e36f23914f6c69bceec1f69663df5a37 Mon Sep 17 00:00:00 2001 From: Joe Hoyle Date: Thu, 24 Nov 2016 00:07:50 +0000 Subject: [PATCH] =?UTF-8?q?REST=20API:=20Special=20case=20the=20=E2=80=9Cs?= =?UTF-8?q?tandard=E2=80=9D=20post=20format=20to=20always=20be=20allowed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #38916. git-svn-id: https://develop.svn.wordpress.org/trunk@39353 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-rest-posts-controller.php | 2 +- .../tests/rest-api/rest-posts-controller.php | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) 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 );