Make WordPress Core


Ignore:
Timestamp:
11/10/2016 02:20:09 AM (10 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-post-types-controller.php

    r39106 r39191  
    149149                $taxonomies = wp_list_filter( get_object_taxonomies( $post_type->name, 'objects' ), array( 'show_in_rest' => true ) );
    150150                $taxonomies = wp_list_pluck( $taxonomies, 'name' );
     151                $base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
    151152                $data = array(
    152153                        'capabilities' => $post_type->cap,
     
    157158                        'slug'         => $post_type->name,
    158159                        'taxonomies'   => array_values( $taxonomies ),
     160                        'rest_base'    => $base,
    159161                );
    160162                $context = ! empty( $request['context'] ) ? $request['context'] : 'view';
     
    164166                // Wrap the data in a response object.
    165167                $response = rest_ensure_response( $data );
    166 
    167                 $base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;
    168168
    169169                $response->add_links( array(
     
    252252                                        'readonly'     => true,
    253253                                ),
     254                                'rest_base'            => array(
     255                                        'description'  => __( 'REST base route for the resource.' ),
     256                                        'type'         => 'string',
     257                                        'context'      => array( 'view', 'edit', 'embed' ),
     258                                        'readonly'     => true,
     259                                ),
    254260                        ),
    255261                );
Note: See TracChangeset for help on using the changeset viewer.