~canonical-sysadmins/wordpress/5.1

« back to all changes in this revision

Viewing changes to wp-includes/rest-api/endpoints/class-wp-rest-post-statuses-controller.php

  • Committer: Barry Price
  • Date: 2019-02-22 03:51:26 UTC
  • mfrom: (1.2.12 upstream)
  • Revision ID: barry.price@canonical.com-20190222035126-o28k38qs8jfyjsxt
Merge WP5.1 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
         */
36
36
        public function register_routes() {
37
37
 
38
 
                register_rest_route( $this->namespace, '/' . $this->rest_base, array(
 
38
                register_rest_route(
 
39
                        $this->namespace,
 
40
                        '/' . $this->rest_base,
39
41
                        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
 
                ) );
 
42
                                array(
 
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(),
 
47
                                ),
 
48
                                'schema' => array( $this, 'get_public_item_schema' ),
 
49
                        )
 
50
                );
47
51
 
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
 
                        ),
 
52
                register_rest_route(
 
53
                        $this->namespace,
 
54
                        '/' . $this->rest_base . '/(?P<status>[\w-]+)',
55
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
 
                ) );
 
56
                                'args'   => array(
 
57
                                        'status' => array(
 
58
                                                'description' => __( 'An alphanumeric identifier for the status.' ),
 
59
                                                'type'        => 'string',
 
60
                                        ),
 
61
                                ),
 
62
                                array(
 
63
                                        'methods'             => WP_REST_Server::READABLE,
 
64
                                        'callback'            => array( $this, 'get_item' ),
 
65
                                        'permission_callback' => array( $this, 'get_item_permissions_check' ),
 
66
                                        'args'                => array(
 
67
                                                'context' => $this->get_context_param( array( 'default' => 'view' ) ),
 
68
                                        ),
 
69
                                ),
 
70
                                'schema' => array( $this, 'get_public_item_schema' ),
 
71
                        )
 
72
                );
65
73
        }
66
74
 
67
75
        /**
96
104
         * @return WP_Error|WP_REST_Response Response object on success, or WP_Error object on failure.
97
105
         */
98
106
        public function get_items( $request ) {
99
 
                $data = array();
100
 
                $statuses = get_post_stati( array( 'internal' => false ), 'object' );
 
107
                $data              = array();
 
108
                $statuses          = get_post_stati( array( 'internal' => false ), 'object' );
101
109
                $statuses['trash'] = get_post_status_object( 'trash' );
102
110
 
103
111
                foreach ( $statuses as $slug => $obj ) {
107
115
                                continue;
108
116
                        }
109
117
 
110
 
                        $status = $this->prepare_item_for_response( $obj, $request );
 
118
                        $status             = $this->prepare_item_for_response( $obj, $request );
111
119
                        $data[ $obj->name ] = $this->prepare_response_for_collection( $status );
112
120
                }
113
121
 
227
235
                }
228
236
 
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 );
232
240
 
233
241
                $response = rest_ensure_response( $data );
234
242
 
261
269
         */
262
270
        public function get_item_schema() {
263
271
                $schema = array(
264
 
                        '$schema'              => 'http://json-schema.org/draft-04/schema#',
265
 
                        'title'                => 'status',
266
 
                        'type'                 => 'object',
267
 
                        'properties'           => array(
268
 
                                'name'             => array(
269
 
                                        'description'  => __( 'The title for the status.' ),
270
 
                                        'type'         => 'string',
271
 
                                        'context'      => array( 'embed', 'view', 'edit' ),
272
 
                                        'readonly'     => true,
273
 
                                ),
274
 
                                'private'          => array(
275
 
                                        'description'  => __( 'Whether posts with this status should be private.' ),
276
 
                                        'type'         => 'boolean',
277
 
                                        'context'      => array( 'edit' ),
278
 
                                        'readonly'     => true,
279
 
                                ),
280
 
                                'protected'        => array(
281
 
                                        'description'  => __( 'Whether posts with this status should be protected.' ),
282
 
                                        'type'         => 'boolean',
283
 
                                        'context'      => array( 'edit' ),
284
 
                                        'readonly'     => true,
285
 
                                ),
286
 
                                'public'           => array(
287
 
                                        'description'  => __( 'Whether posts of this status should be shown in the front end of the site.' ),
288
 
                                        'type'         => 'boolean',
289
 
                                        'context'      => array( 'view', 'edit' ),
290
 
                                        'readonly'     => true,
291
 
                                ),
292
 
                                'queryable'        => array(
293
 
                                        'description'  => __( 'Whether posts with this status should be publicly-queryable.' ),
294
 
                                        'type'         => 'boolean',
295
 
                                        'context'      => array( 'view', 'edit' ),
296
 
                                        'readonly'     => true,
297
 
                                ),
298
 
                                'show_in_list'     => array(
299
 
                                        'description'  => __( 'Whether to include posts in the edit listing for their post type.' ),
300
 
                                        'type'         => 'boolean',
301
 
                                        'context'      => array( 'edit' ),
302
 
                                        'readonly'     => true,
303
 
                                ),
304
 
                                'slug'             => array(
305
 
                                        'description'  => __( 'An alphanumeric identifier for the status.' ),
306
 
                                        'type'         => 'string',
307
 
                                        'context'      => array( 'embed', 'view', 'edit' ),
308
 
                                        'readonly'     => true,
 
272
                        '$schema'    => 'http://json-schema.org/draft-04/schema#',
 
273
                        'title'      => 'status',
 
274
                        'type'       => 'object',
 
275
                        'properties' => array(
 
276
                                'name'         => array(
 
277
                                        'description' => __( 'The title for the status.' ),
 
278
                                        'type'        => 'string',
 
279
                                        'context'     => array( 'embed', 'view', 'edit' ),
 
280
                                        'readonly'    => true,
 
281
                                ),
 
282
                                'private'      => array(
 
283
                                        'description' => __( 'Whether posts with this status should be private.' ),
 
284
                                        'type'        => 'boolean',
 
285
                                        'context'     => array( 'edit' ),
 
286
                                        'readonly'    => true,
 
287
                                ),
 
288
                                'protected'    => array(
 
289
                                        'description' => __( 'Whether posts with this status should be protected.' ),
 
290
                                        'type'        => 'boolean',
 
291
                                        'context'     => array( 'edit' ),
 
292
                                        'readonly'    => true,
 
293
                                ),
 
294
                                'public'       => array(
 
295
                                        'description' => __( 'Whether posts of this status should be shown in the front end of the site.' ),
 
296
                                        'type'        => 'boolean',
 
297
                                        'context'     => array( 'view', 'edit' ),
 
298
                                        'readonly'    => true,
 
299
                                ),
 
300
                                'queryable'    => array(
 
301
                                        'description' => __( 'Whether posts with this status should be publicly-queryable.' ),
 
302
                                        'type'        => 'boolean',
 
303
                                        'context'     => array( 'view', 'edit' ),
 
304
                                        'readonly'    => true,
 
305
                                ),
 
306
                                'show_in_list' => array(
 
307
                                        'description' => __( 'Whether to include posts in the edit listing for their post type.' ),
 
308
                                        'type'        => 'boolean',
 
309
                                        'context'     => array( 'edit' ),
 
310
                                        'readonly'    => true,
 
311
                                ),
 
312
                                'slug'         => array(
 
313
                                        'description' => __( 'An alphanumeric identifier for the status.' ),
 
314
                                        'type'        => 'string',
 
315
                                        'context'     => array( 'embed', 'view', 'edit' ),
 
316
                                        'readonly'    => true,
309
317
                                ),
310
318
                        ),
311
319
                );