REST API: Special case the “standard” post format to always be allowed.

Fixes #38916.

git-svn-id: https://develop.svn.wordpress.org/trunk@39353 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe Hoyle 2016-11-24 00:07:50 +00:00
parent 7dc75c29f6
commit a1c2caa4e3
2 changed files with 33 additions and 1 deletions

View File

@ -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;

View File

@ -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 );