Changeset 39191
- Timestamp:
- 11/10/2016 02:20:09 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-types-controller.php
r39106 r39191 149 149 $taxonomies = wp_list_filter( get_object_taxonomies( $post_type->name, 'objects' ), array( 'show_in_rest' => true ) ); 150 150 $taxonomies = wp_list_pluck( $taxonomies, 'name' ); 151 $base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name; 151 152 $data = array( 152 153 'capabilities' => $post_type->cap, … … 157 158 'slug' => $post_type->name, 158 159 'taxonomies' => array_values( $taxonomies ), 160 'rest_base' => $base, 159 161 ); 160 162 $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; … … 164 166 // Wrap the data in a response object. 165 167 $response = rest_ensure_response( $data ); 166 167 $base = ! empty( $post_type->rest_base ) ? $post_type->rest_base : $post_type->name;168 168 169 169 $response->add_links( array( … … 252 252 'readonly' => true, 253 253 ), 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 ), 254 260 ), 255 261 ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
r39106 r39191 178 178 */ 179 179 public function prepare_item_for_response( $taxonomy, $request ) { 180 180 $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name; 181 181 $data = array( 182 182 'name' => $taxonomy->label, … … 188 188 'show_cloud' => $taxonomy->show_tagcloud, 189 189 'hierarchical' => $taxonomy->hierarchical, 190 'rest_base' => $base, 190 191 ); 191 192 … … 197 198 $response = rest_ensure_response( $data ); 198 199 199 $base = ! empty( $taxonomy->rest_base ) ? $taxonomy->rest_base : $taxonomy->name;200 200 $response->add_links( array( 201 201 'collection' => array( … … 286 286 'readonly' => true, 287 287 ), 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 ), 288 294 ), 289 295 ); -
trunk/tests/phpunit/tests/rest-api/rest-post-types-controller.php
r39097 r39191 120 120 $data = $response->get_data(); 121 121 $properties = $data['schema']['properties']; 122 $this->assertEquals( 7, count( $properties ) );122 $this->assertEquals( 8, count( $properties ) ); 123 123 $this->assertArrayHasKey( 'capabilities', $properties ); 124 124 $this->assertArrayHasKey( 'description', $properties ); … … 128 128 $this->assertArrayHasKey( 'slug', $properties ); 129 129 $this->assertArrayHasKey( 'taxonomies', $properties ); 130 $this->assertArrayHasKey( 'rest_base', $properties ); 130 131 } 131 132 … … 171 172 $this->assertEquals( $post_type_obj->description, $data['description'] ); 172 173 $this->assertEquals( $post_type_obj->hierarchical, $data['hierarchical'] ); 174 $this->assertEquals( $post_type_obj->rest_base, $data['rest_base'] ); 173 175 174 176 $links = test_rest_expand_compact_links( $links ); -
trunk/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php
r38832 r39191 46 46 $this->assertEquals( 'post_tag', $data['post_tag']['slug'] ); 47 47 $this->assertEquals( false, $data['post_tag']['hierarchical'] ); 48 $this->assertEquals( 'tags', $data['post_tag']['rest_base'] ); 48 49 } 49 50 … … 135 136 $data = $response->get_data(); 136 137 $properties = $data['schema']['properties']; 137 $this->assertEquals( 8, count( $properties ) );138 $this->assertEquals( 9, count( $properties ) ); 138 139 $this->assertArrayHasKey( 'capabilities', $properties ); 139 140 $this->assertArrayHasKey( 'description', $properties ); … … 144 145 $this->assertArrayHasKey( 'show_cloud', $properties ); 145 146 $this->assertArrayHasKey( 'types', $properties ); 147 $this->assertArrayHasKey( 'rest_base', $properties ); 146 148 } 147 149 … … 169 171 $this->assertEquals( $tax_obj->description, $data['description'] ); 170 172 $this->assertEquals( $tax_obj->hierarchical, $data['hierarchical'] ); 173 $this->assertEquals( $tax_obj->rest_base, $data['rest_base'] ); 171 174 $this->assertEquals( rest_url( 'wp/v2/taxonomies' ), $links['collection'][0]['href'] ); 172 175 $this->assertArrayHasKey( 'https://api.w.org/items', $links );
Note: See TracChangeset
for help on using the changeset viewer.