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. Built from https://develop.svn.wordpress.org/trunk@47224 git-svn-id: http://core.svn.wordpress.org/trunk@47024 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user