Make WordPress Core


Ignore:
Timestamp:
02/16/2016 02:18:34 AM (6 years ago)
Author:
rmccue
Message:

REST API: Add support for CURIEs.

CURIEs are Compact URIs, which provide a more usable way to use
custom relations in the API. The wp CURIE is registered by default
for https://api.w.org/ URI relations.

Fixes #34729.
Props joehoyle.

File:
1 edited

Legend:

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

    r35671 r36533  
    257257        return $error;
    258258    }
     259
     260    /**
     261     * Get the CURIEs (compact URIs) used for relations.
     262     *
     263     * @return array
     264     */
     265    public function get_curies() {
     266        $curies = array(
     267            array(
     268                'name' => 'wp',
     269                'href' => 'https://api.w.org/{rel}',
     270                'templated' => true,
     271            ),
     272        );
     273
     274        /**
     275         * Filter extra CURIEs available on API responses.
     276         *
     277         * CURIEs allow a shortened version of URI relations. This allows a more
     278         * usable form for custom relations than using the full URI. These work
     279         * similarly to how XML namespaces work.
     280         *
     281         * Registered CURIES need to specify a name and URI template. This will
     282         * automatically transform URI relations into their shortened version.
     283         * The shortened relation follows the format `{name}:{rel}`. `{rel}` in
     284         * the URI template will be replaced with the `{rel}` part of the
     285         * shortened relation.
     286         *
     287         * For example, a CURIE with name `example` and URI template
     288         * `http://w.org/{rel}` would transform a `http://w.org/term` relation
     289         * into `example:term`.
     290         *
     291         * Well-behaved clients should expand and normalise these back to their
     292         * full URI relation, however some naive clients may not resolve these
     293         * correctly, so adding new CURIEs may break backwards compatibility.
     294         *
     295         * @param array $additional Additional CURIEs to register with the API.
     296         */
     297        $additional = apply_filters( 'rest_response_link_curies', array() );
     298        return array_merge( $curies, $additional );
     299    }
    259300}
Note: See TracChangeset for help on using the changeset viewer.