Changeset 42343 for trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-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-post-statuses-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<status>[\w-]+)', array( 49 'args' => array( 50 'status' => array( 51 'description' => __( 'An alphanumeric identifier for the status.' ), 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<status>[\w-]+)', array( 52 'args' => array( 53 'status' => array( 54 'description' => __( 'An alphanumeric identifier for the status.' ), 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 … … 97 101 */ 98 102 public function get_items( $request ) { 99 $data = array();100 $statuses = get_post_stati( array( 'internal' => false ), 'object' );103 $data = array(); 104 $statuses = get_post_stati( array( 'internal' => false ), 'object' ); 101 105 $statuses['trash'] = get_post_status_object( 'trash' ); 102 106 … … 108 112 } 109 113 110 $status = $this->prepare_item_for_response( $obj, $request );114 $status = $this->prepare_item_for_response( $obj, $request ); 111 115 $data[ $obj->name ] = $this->prepare_response_for_collection( $status ); 112 116 } … … 207 211 208 212 $context = ! empty( $request['context'] ) ? $request['context'] : 'view'; 209 $data = $this->add_additional_fields_to_object( $data, $request );210 $data = $this->filter_response_by_context( $data, $context );213 $data = $this->add_additional_fields_to_object( $data, $request ); 214 $data = $this->filter_response_by_context( $data, $context ); 211 215 212 216 $response = rest_ensure_response( $data ); … … 241 245 public function get_item_schema() { 242 246 $schema = array( 243 '$schema' => 'http://json-schema.org/draft-04/schema#',244 'title' => 'status',245 'type' => 'object',246 'properties' => array(247 'name' => array(248 'description' => __( 'The title for the status.' ),249 'type' => 'string',250 'context' => array( 'embed', 'view', 'edit' ),251 'readonly' => true,252 ), 253 'private' => array(254 'description' => __( 'Whether posts with this status should be private.' ),255 'type' => 'boolean',256 'context' => array( 'edit' ),257 'readonly' => true,258 ), 259 'protected' => array(260 'description' => __( 'Whether posts with this status should be protected.' ),261 'type' => 'boolean',262 'context' => array( 'edit' ),263 'readonly' => true,264 ), 265 'public' => array(266 'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ),267 'type' => 'boolean',268 'context' => array( 'view', 'edit' ),269 'readonly' => true,270 ), 271 'queryable' => array(272 'description' => __( 'Whether posts with this status should be publicly-queryable.' ),273 'type' => 'boolean',274 'context' => array( 'view', 'edit' ),275 'readonly' => true,276 ), 277 'show_in_list' => array(278 'description' => __( 'Whether to include posts in the edit listing for their post type.' ),279 'type' => 'boolean',280 'context' => array( 'edit' ),281 'readonly' => true,282 ), 283 'slug' => array(284 'description' => __( 'An alphanumeric identifier for the status.' ),285 'type' => 'string',286 'context' => array( 'embed', 'view', 'edit' ),287 'readonly' => true,247 '$schema' => 'http://json-schema.org/draft-04/schema#', 248 'title' => 'status', 249 'type' => 'object', 250 'properties' => array( 251 'name' => array( 252 'description' => __( 'The title for the status.' ), 253 'type' => 'string', 254 'context' => array( 'embed', 'view', 'edit' ), 255 'readonly' => true, 256 ), 257 'private' => array( 258 'description' => __( 'Whether posts with this status should be private.' ), 259 'type' => 'boolean', 260 'context' => array( 'edit' ), 261 'readonly' => true, 262 ), 263 'protected' => array( 264 'description' => __( 'Whether posts with this status should be protected.' ), 265 'type' => 'boolean', 266 'context' => array( 'edit' ), 267 'readonly' => true, 268 ), 269 'public' => array( 270 'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ), 271 'type' => 'boolean', 272 'context' => array( 'view', 'edit' ), 273 'readonly' => true, 274 ), 275 'queryable' => array( 276 'description' => __( 'Whether posts with this status should be publicly-queryable.' ), 277 'type' => 'boolean', 278 'context' => array( 'view', 'edit' ), 279 'readonly' => true, 280 ), 281 'show_in_list' => array( 282 'description' => __( 'Whether to include posts in the edit listing for their post type.' ), 283 'type' => 'boolean', 284 'context' => array( 'edit' ), 285 'readonly' => true, 286 ), 287 'slug' => array( 288 'description' => __( 'An alphanumeric identifier for the status.' ), 289 'type' => 'string', 290 'context' => array( 'embed', 'view', 'edit' ), 291 'readonly' => true, 288 292 ), 289 293 ),
Note: See TracChangeset
for help on using the changeset viewer.