Make WordPress Core


Ignore:
Timestamp:
11/01/2021 03:26:06 AM (3 years ago)
Author:
TimothyBlynJacobs
Message:

REST API: Support custom namespaces for taxonomies.

While a taxonomy can define a custom route by using the rest_base argument, a namespace of wp/v2 was assumed. This commit introduces support for a rest_namespace argument.

A new rest_get_route_for_taxonomy_items function has been introduced and the rest_get_route_for_term function updated to facilitate getting the correct route for taxonomies.

For maximum compatibility sticking with the default wp/v2 namespace is recommended until the API functions see wider use.

Props spacedmonkey.
Fixes #54267.
See [51962].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-terms-controller.php

    r51962 r51964  
    5858    public function __construct( $taxonomy ) {
    5959        $this->taxonomy  = $taxonomy;
    60         $this->namespace = 'wp/v2';
    6160        $tax_obj         = get_taxonomy( $taxonomy );
    6261        $this->rest_base = ! empty( $tax_obj->rest_base ) ? $tax_obj->rest_base : $tax_obj->name;
     62        $this->namespace = ! empty( $tax_obj->rest_namespace ) ? $tax_obj->rest_namespace : 'wp/v2';
    6363
    6464        $this->meta = new WP_REST_Term_Meta_Fields( $taxonomy );
Note: See TracChangeset for help on using the changeset viewer.