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/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php

    r51397 r51964  
    220220        $data       = $response->get_data();
    221221        $properties = $data['schema']['properties'];
    222         $this->assertCount( 10, $properties );
     222        $this->assertCount( 11, $properties );
    223223        $this->assertArrayHasKey( 'capabilities', $properties );
    224224        $this->assertArrayHasKey( 'description', $properties );
     
    231231        $this->assertArrayHasKey( 'visibility', $properties );
    232232        $this->assertArrayHasKey( 'rest_base', $properties );
     233        $this->assertArrayHasKey( 'rest_namespace', $properties );
    233234    }
    234235
     
    253254        $this->assertSame( $tax_obj->hierarchical, $data['hierarchical'] );
    254255        $this->assertSame( $tax_obj->rest_base, $data['rest_base'] );
     256        $this->assertSame( $tax_obj->rest_namespace, $data['rest_namespace'] );
    255257        $this->assertSame( rest_url( 'wp/v2/taxonomies' ), $links['collection'][0]['href'] );
    256258        $this->assertArrayHasKey( 'https://api.w.org/items', $links );
Note: See TracChangeset for help on using the changeset viewer.