REST API: Introduce selective link embedding.

Previously the _embed flag would embed all embeddable links in a response even if only a subset of the links were necessary. Now, a list of link relations can be passed in the _embed parameter to restrict the list of embedded objects.

Props rheinardkorf, adamsilverstein, jnylen0, cklosows, chrisvanpatten, TimothyBlynJacobs.
Fixes #39696.


git-svn-id: https://develop.svn.wordpress.org/trunk@47224 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs
2020-02-09 20:52:06 +00:00
parent c647007a82
commit 98e5dd52de
4 changed files with 126 additions and 6 deletions
+22
View File
@@ -1571,3 +1571,25 @@ function rest_preload_api_request( $memo, $path ) {
return $memo;
}
/**
* Parses the "_embed" parameter into the list of resources to embed.
*
* @since 5.4.0
*
* @param string|array $embed Raw "_embed" parameter value.
* @return true|string[] Either true to embed all embeds, or a list of relations to embed.
*/
function rest_parse_embed_param( $embed ) {
if ( ! $embed || 'true' === $embed || '1' === $embed ) {
return true;
}
$rels = wp_parse_list( $embed );
if ( ! $rels ) {
return true;
}
return $rels;
}