36
36
public function register_routes() {
38
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
40
'/' . $this->rest_base,
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(),
45
'schema' => array( $this, 'get_public_item_schema' ),
43
'methods' => WP_REST_Server::READABLE,
44
'callback' => array( $this, 'get_items' ),
45
'permission_callback' => array( $this, 'get_items_permissions_check' ),
46
'args' => $this->get_collection_params(),
48
'schema' => array( $this, 'get_public_item_schema' ),
48
register_rest_route( $this->namespace, '/' . $this->rest_base . '/(?P<status>[\w-]+)', array(
51
'description' => __( 'An alphanumeric identifier for the status.' ),
54
'/' . $this->rest_base . '/(?P<status>[\w-]+)',
56
'methods' => WP_REST_Server::READABLE,
57
'callback' => array( $this, 'get_item' ),
58
'permission_callback' => array( $this, 'get_item_permissions_check' ),
60
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
63
'schema' => array( $this, 'get_public_item_schema' ),
58
'description' => __( 'An alphanumeric identifier for the status.' ),
63
'methods' => WP_REST_Server::READABLE,
64
'callback' => array( $this, 'get_item' ),
65
'permission_callback' => array( $this, 'get_item_permissions_check' ),
67
'context' => $this->get_context_param( array( 'default' => 'view' ) ),
70
'schema' => array( $this, 'get_public_item_schema' ),
96
104
* @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
98
106
public function get_items( $request ) {
100
$statuses = get_post_stati( array( 'internal' => false ), 'object' );
108
$statuses = get_post_stati( array( 'internal' => false ), 'object' );
101
109
$statuses['trash'] = get_post_status_object( 'trash' );
103
111
foreach ( $statuses as $slug => $obj ) {
229
237
$context = ! empty( $request['context'] ) ? $request['context'] : 'view';
230
$data = $this->add_additional_fields_to_object( $data, $request );
231
$data = $this->filter_response_by_context( $data, $context );
238
$data = $this->add_additional_fields_to_object( $data, $request );
239
$data = $this->filter_response_by_context( $data, $context );
233
241
$response = rest_ensure_response( $data );
262
270
public function get_item_schema() {
264
'$schema' => 'http://json-schema.org/draft-04/schema#',
267
'properties' => array(
269
'description' => __( 'The title for the status.' ),
271
'context' => array( 'embed', 'view', 'edit' ),
275
'description' => __( 'Whether posts with this status should be private.' ),
277
'context' => array( 'edit' ),
280
'protected' => array(
281
'description' => __( 'Whether posts with this status should be protected.' ),
283
'context' => array( 'edit' ),
287
'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ),
289
'context' => array( 'view', 'edit' ),
292
'queryable' => array(
293
'description' => __( 'Whether posts with this status should be publicly-queryable.' ),
295
'context' => array( 'view', 'edit' ),
298
'show_in_list' => array(
299
'description' => __( 'Whether to include posts in the edit listing for their post type.' ),
301
'context' => array( 'edit' ),
305
'description' => __( 'An alphanumeric identifier for the status.' ),
307
'context' => array( 'embed', 'view', 'edit' ),
272
'$schema' => 'http://json-schema.org/draft-04/schema#',
275
'properties' => array(
277
'description' => __( 'The title for the status.' ),
279
'context' => array( 'embed', 'view', 'edit' ),
283
'description' => __( 'Whether posts with this status should be private.' ),
285
'context' => array( 'edit' ),
288
'protected' => array(
289
'description' => __( 'Whether posts with this status should be protected.' ),
291
'context' => array( 'edit' ),
295
'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ),
297
'context' => array( 'view', 'edit' ),
300
'queryable' => array(
301
'description' => __( 'Whether posts with this status should be publicly-queryable.' ),
303
'context' => array( 'view', 'edit' ),
306
'show_in_list' => array(
307
'description' => __( 'Whether to include posts in the edit listing for their post type.' ),
309
'context' => array( 'edit' ),
313
'description' => __( 'An alphanumeric identifier for the status.' ),
315
'context' => array( 'embed', 'view', 'edit' ),