Make WordPress Core


Ignore:
Timestamp:
02/09/2020 08:52:06 PM (5 years ago)
Author:
TimothyBlynJacobs
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r47219 r47224  
    15721572    return $memo;
    15731573}
     1574
     1575/**
     1576 * Parses the "_embed" parameter into the list of resources to embed.
     1577 *
     1578 * @since 5.4.0
     1579 *
     1580 * @param string|array $embed Raw "_embed" parameter value.
     1581 * @return true|string[] Either true to embed all embeds, or a list of relations to embed.
     1582 */
     1583function rest_parse_embed_param( $embed ) {
     1584    if ( ! $embed || 'true' === $embed || '1' === $embed ) {
     1585        return true;
     1586    }
     1587
     1588    $rels = wp_parse_list( $embed );
     1589
     1590    if ( ! $rels ) {
     1591        return true;
     1592    }
     1593
     1594    return $rels;
     1595}
Note: See TracChangeset for help on using the changeset viewer.