REST API: Support a broader range of JSON media types.

Previously, we only supported `application/json` which prevented using subtypes like `application/activity+json`. This allows for the REST API to `json_decode` the body of requests using a JSON subtype `Content-Type`. Additionally, `wp_die()` now properly sends the error as JSON when a JSON subtype is specified in the `Accept` header.

Props pfefferle.
Fixes #49404.


git-svn-id: https://develop.svn.wordpress.org/trunk@49329 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs
2020-10-27 16:42:38 +00:00
parent fce8f2bf4d
commit d56906f5b0
4 changed files with 139 additions and 7 deletions
+23
View File
@@ -1728,4 +1728,27 @@ class Tests_Functions extends WP_UnitTestCase {
array( '03:61:59', false ), // Out of bound.
);
}
/**
* @ticket 49404
* @dataProvider data_test_wp_is_json_media_type
*/
public function test_wp_is_json_media_type( $input, $expected ) {
$this->assertEquals( $expected, wp_is_json_media_type( $input ) );
}
public function data_test_wp_is_json_media_type() {
return array(
array( 'application/ld+json', true ),
array( 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', true ),
array( 'application/activity+json', true ),
array( 'application/json+oembed', true ),
array( 'application/json', true ),
array( 'application/nojson', false ),
array( 'application/no.json', false ),
array( 'text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8', false ),
array( 'application/activity+json, application/nojson', true ),
);
}
}