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 5b6cafdbc4..30651d0538 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 @@ -1989,17 +1989,13 @@ class WP_REST_Posts_Controller extends WP_REST_Controller { break; case 'post-formats': - $supports_formats = get_theme_support( 'post-formats' ); - - // Force to an array. Supports formats can return true even if empty in some cases. - $supports_formats = is_array( $supports_formats ) ? array_values( $supports_formats[0] ) : array(); - - $supported_formats = array_merge( array( 'standard' ), $supports_formats ); + // Get the native post formats and remove the array keys. + $formats = array_values( get_post_format_slugs() ); $schema['properties']['format'] = array( 'description' => __( 'The format for the object.' ), 'type' => 'string', - 'enum' => $supported_formats, + 'enum' => $formats, '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 b5c18a0ade..503010f0f8 100644 --- a/tests/phpunit/tests/rest-api/rest-posts-controller.php +++ b/tests/phpunit/tests/rest-api/rest-posts-controller.php @@ -914,20 +914,12 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te $this->assertEquals( $post2, $data[0]['id'] ); } - public function test_get_items_no_supported_post_formats() { - // This causes get_theme_support( 'post-formats' ) to return `true` (not an array) - add_theme_support( 'post-formats' ); - + public function test_get_items_all_post_formats() { $request = new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ); $response = $this->server->dispatch( $request ); $data = $response->get_data(); - // Set the expected state back for the rest of the tests. - global $_wp_theme_features; - unset( $_wp_theme_features['post-formats'] ); - add_theme_support( 'post-formats', array( 'post', 'gallery' ) ); - - $formats = array( 'standard' ); + $formats = array_values( get_post_format_slugs() ); $this->assertEquals( $formats, $data['schema']['properties']['format']['enum'] ); } @@ -1575,8 +1567,10 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te ) ); $request->set_body_params( $params ); $response = $this->server->dispatch( $request ); + $this->assertEquals( 201, $response->get_status() ); - $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); + $data = $response->get_data(); + $this->assertEquals( 'link', $data['format'] ); } public function test_create_update_post_with_featured_media() { @@ -2073,8 +2067,10 @@ class WP_Test_REST_Posts_Controller extends WP_Test_REST_Post_Type_Controller_Te ) ); $request->set_body_params( $params ); $response = $this->server->dispatch( $request ); + $this->assertEquals( 200, $response->get_status() ); - $this->assertErrorResponse( 'rest_invalid_param', $response, 400 ); + $data = $response->get_data(); + $this->assertEquals( 'link', $data['format'] ); } public function test_update_post_ignore_readonly() {