Make WordPress Core


Ignore:
Timestamp:
11/10/2016 02:20:09 AM (8 years ago)
Author:
joehoyle
Message:

REST API: Add rest_base to response objects of wp/v2/taxonomies and wp/v2/types

Though we have the _links.collection available, having this value can be useful to know post type / taxonomy urls if you need to build them another way.

Props youknowriad, jnylen0.
Fixes #38607.

File:
1 edited

Legend:

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

    r39106 r39191  
    178178     */
    179179    public function prepare_item_for_response( $taxonomy, $request ) {
    180 
     180        $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
    181181        $data = array(
    182182            'name'         => $taxonomy->label,
     
    188188            'show_cloud'   => $taxonomy->show_tagcloud,
    189189            'hierarchical' => $taxonomy->hierarchical,
     190            'rest_base'    => $base,
    190191        );
    191192
     
    197198        $response = rest_ensure_response( $data );
    198199
    199         $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;
    200200        $response->add_links( array(
    201201            'collection'                => array(
     
    286286                    'readonly'     => true,
    287287                ),
     288                'rest_base'            => array(
     289                    'description'  => __( 'REST base route for the resource.' ),
     290                    'type'         => 'string',
     291                    'context'      => array( 'view', 'edit', 'embed' ),
     292                    'readonly'     => true,
     293                ),
    288294            ),
    289295        );
Note: See TracChangeset for help on using the changeset viewer.