Changeset 42343 for trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
- Timestamp:
- 11/30/2017 11:09:33 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-taxonomies-controller.php
r41731 r42343 36 36 public function register_routes() { 37 37 38 register_rest_route( $this->namespace, '/' . $this->rest_base, array( 39 array( 40 'methods' => WP_REST_Server::READABLE, 41 'callback' => array( $this, 'get_items' ), 42 'permission_callback' => array( $this, 'get_items_permissions_check' ), 43 'args' => $this->get_collection_params(), 44 ), 45 'schema' => array( $this, 'get_public_item_schema' ), 46 ) ); 47 48 register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<taxonomy>[\w-]+)', array( 49 'args' => array( 50 'taxonomy' => array( 51 'description' => __( 'An alphanumeric identifier for the taxonomy.' ), 52 'type' => 'string', 53 ), 54 ), 55 array( 56 'methods' => WP_REST_Server::READABLE, 57 'callback' => array( $this, 'get_item' ), 58 'permission_callback' => array( $this, 'get_item_permissions_check' ), 59 'args' => array( 60 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 61 ), 62 ), 63 'schema' => array( $this, 'get_public_item_schema' ), 64 ) ); 38 register_rest_route( 39 $this->namespace, '/' . $this->rest_base, array( 40 array( 41 'methods' => WP_REST_Server::READABLE, 42 'callback' => array( $this, 'get_items' ), 43 'permission_callback' => array( $this, 'get_items_permissions_check' ), 44 'args' => $this->get_collection_params(), 45 ), 46 'schema' => array( $this, 'get_public_item_schema' ), 47 ) 48 ); 49 50 register_rest_route( 51 $this->namespace, '/' . $this->rest_base . '/(?P<taxonomy>[\w-]+)', array( 52 'args' => array( 53 'taxonomy' => array( 54 'description' => __( 'An alphanumeric identifier for the taxonomy.' ), 55 'type' => 'string', 56 ), 57 ), 58 array( 59 'methods' => WP_REST_Server::READABLE, 60 'callback' => array( $this, 'get_item' ), 61 'permission_callback' => array( $this, 'get_item_permissions_check' ), 62 'args' => array( 63 'context' => $this->get_context_param( array( 'default' => 'view' ) ), 64 ), 65 ), 66 'schema' => array( $this, 'get_public_item_schema' ), 67 ) 68 ); 65 69 } 66 70 … … 113 117 continue; 114 118 } 115 $tax = $this->prepare_item_for_response( $value, $request );116 $tax = $this->prepare_response_for_collection( $tax );119 $tax = $this->prepare_item_for_response( $value, $request ); 120 $tax = $this->prepare_response_for_collection( $tax ); 117 121 $data[ $tax_type ] = $tax; 118 122 } … … 191 195 192 196 $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; 193 $data = $this->add_additional_fields_to_object( $data, $request );194 $data = $this->filter_response_by_context( $data, $context );197 $data = $this->add_additional_fields_to_object( $data, $request ); 198 $data = $this->filter_response_by_context( $data, $context ); 195 199 196 200 // Wrap the data in a response object. 197 201 $response = rest_ensure_response( $data ); 198 202 199 $response->add_links( array( 200 'collection' => array( 201 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), 202 ), 203 'https://api.w.org/items' => array( 204 'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ), 205 ), 206 ) ); 203 $response->add_links( 204 array( 205 'collection' => array( 206 'href' => rest_url( sprintf( '%s/%s', $this->namespace, $this->rest_base ) ), 207 ), 208 'https://api.w.org/items' => array( 209 'href' => rest_url( sprintf( 'wp/v2/%s', $base ) ), 210 ), 211 ) 212 ); 207 213 208 214 /** … … 229 235 public function get_item_schema() { 230 236 $schema = array( 231 '$schema' => 'http://json-schema.org/draft-04/schema#',232 'title' => 'taxonomy',233 'type' => 'object',234 'properties' => array(235 'capabilities' => array(236 'description' => __( 'All capabilities used by the taxonomy.' ),237 'type' => 'object',238 'context' => array( 'edit' ),239 'readonly' => true,240 ), 241 'description' => array(242 'description' => __( 'A human-readable description of the taxonomy.' ),243 'type' => 'string',244 'context' => array( 'view', 'edit' ),245 'readonly' => true,246 ), 247 'hierarchical' => array(248 'description' => __( 'Whether or not the taxonomy should have children.' ),249 'type' => 'boolean',250 'context' => array( 'view', 'edit' ),251 'readonly' => true,252 ), 253 'labels' => array(254 'description' => __( 'Human-readable labels for the taxonomy for various contexts.' ),255 'type' => 'object',256 'context' => array( 'edit' ),257 'readonly' => true,258 ), 259 'name' => array(260 'description' => __( 'The title for the taxonomy.' ),261 'type' => 'string',262 'context' => array( 'view', 'edit', 'embed' ),263 'readonly' => true,264 ), 265 'slug' => array(266 'description' => __( 'An alphanumeric identifier for the taxonomy.' ),267 'type' => 'string',268 'context' => array( 'view', 'edit', 'embed' ),269 'readonly' => true,270 ), 271 'show_cloud' => array(272 'description' => __( 'Whether or not the term cloud should be displayed.' ),273 'type' => 'boolean',274 'context' => array( 'edit' ),275 'readonly' => true,276 ), 277 'types' => array(278 'description' => __( 'Types associated with the taxonomy.' ),279 'type' => 'array',280 'items' => array(237 '$schema' => 'http://json-schema.org/draft-04/schema#', 238 'title' => 'taxonomy', 239 'type' => 'object', 240 'properties' => array( 241 'capabilities' => array( 242 'description' => __( 'All capabilities used by the taxonomy.' ), 243 'type' => 'object', 244 'context' => array( 'edit' ), 245 'readonly' => true, 246 ), 247 'description' => array( 248 'description' => __( 'A human-readable description of the taxonomy.' ), 249 'type' => 'string', 250 'context' => array( 'view', 'edit' ), 251 'readonly' => true, 252 ), 253 'hierarchical' => array( 254 'description' => __( 'Whether or not the taxonomy should have children.' ), 255 'type' => 'boolean', 256 'context' => array( 'view', 'edit' ), 257 'readonly' => true, 258 ), 259 'labels' => array( 260 'description' => __( 'Human-readable labels for the taxonomy for various contexts.' ), 261 'type' => 'object', 262 'context' => array( 'edit' ), 263 'readonly' => true, 264 ), 265 'name' => array( 266 'description' => __( 'The title for the taxonomy.' ), 267 'type' => 'string', 268 'context' => array( 'view', 'edit', 'embed' ), 269 'readonly' => true, 270 ), 271 'slug' => array( 272 'description' => __( 'An alphanumeric identifier for the taxonomy.' ), 273 'type' => 'string', 274 'context' => array( 'view', 'edit', 'embed' ), 275 'readonly' => true, 276 ), 277 'show_cloud' => array( 278 'description' => __( 'Whether or not the term cloud should be displayed.' ), 279 'type' => 'boolean', 280 'context' => array( 'edit' ), 281 'readonly' => true, 282 ), 283 'types' => array( 284 'description' => __( 'Types associated with the taxonomy.' ), 285 'type' => 'array', 286 'items' => array( 281 287 'type' => 'string', 282 288 ), 283 'context' => array( 'view', 'edit' ),284 'readonly' => true,285 ), 286 'rest_base' => array(287 'description' => __( 'REST base route for the taxonomy.' ),288 'type' => 'string',289 'context' => array( 'view', 'edit', 'embed' ),290 'readonly' => true,289 'context' => array( 'view', 'edit' ), 290 'readonly' => true, 291 ), 292 'rest_base' => array( 293 'description' => __( 'REST base route for the taxonomy.' ), 294 'type' => 'string', 295 'context' => array( 'view', 'edit', 'embed' ), 296 'readonly' => true, 291 297 ), 292 298 ), … … 303 309 */ 304 310 public function get_collection_params() { 305 $new_params = array();311 $new_params = array(); 306 312 $new_params['context'] = $this->get_context_param( array( 'default' => 'view' ) ); 307 $new_params['type'] = array(308 'description' => __( 'Limit results to taxonomies associated with a specific post type.' ),309 'type' => 'string',313 $new_params['type'] = array( 314 'description' => __( 'Limit results to taxonomies associated with a specific post type.' ), 315 'type' => 'string', 310 316 ); 311 317 return $new_params;
Note: See TracChangeset
for help on using the changeset viewer.