~canonical-sysadmins/wordpress/5.1

« back to all changes in this revision

Viewing changes to wp-includes/rest-api/endpoints/class-wp-rest-settings-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(
39
 
                        array(
40
 
                                'methods'             => WP_REST_Server::READABLE,
41
 
                                'callback'            => array( $this, 'get_item' ),
42
 
                                'args'                => array(),
43
 
                                'permission_callback' => array( $this, 'get_item_permissions_check' ),
44
 
                        ),
45
 
                        array(
46
 
                                'methods'             => WP_REST_Server::EDITABLE,
47
 
                                'callback'            => array( $this, 'update_item' ),
48
 
                                'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
49
 
                                'permission_callback' => array( $this, 'get_item_permissions_check' ),
50
 
                        ),
51
 
                        'schema' => array( $this, 'get_public_item_schema' ),
52
 
                ) );
 
38
                register_rest_route(
 
39
                        $this->namespace,
 
40
                        '/' . $this->rest_base,
 
41
                        array(
 
42
                                array(
 
43
                                        'methods'             => WP_REST_Server::READABLE,
 
44
                                        'callback'            => array( $this, 'get_item' ),
 
45
                                        'args'                => array(),
 
46
                                        'permission_callback' => array( $this, 'get_item_permissions_check' ),
 
47
                                ),
 
48
                                array(
 
49
                                        'methods'             => WP_REST_Server::EDITABLE,
 
50
                                        'callback'            => array( $this, 'update_item' ),
 
51
                                        'args'                => $this->get_endpoint_args_for_item_schema( WP_REST_Server::EDITABLE ),
 
52
                                        'permission_callback' => array( $this, 'get_item_permissions_check' ),
 
53
                                ),
 
54
                                'schema' => array( $this, 'get_public_item_schema' ),
 
55
                        )
 
56
                );
53
57
 
54
58
        }
55
59
 
139
143
        public function update_item( $request ) {
140
144
                $options = $this->get_registered_options();
141
145
 
142
 
                $params  = $request->get_params();
 
146
                $params = $request->get_params();
143
147
 
144
148
                foreach ( $options as $name => $args ) {
145
149
                        if ( ! array_key_exists( $name, $params ) ) {
185
189
                                 */
186
190
                                if ( is_wp_error( rest_validate_value_from_schema( get_option( $args['option_name'], false ), $args['schema'] ) ) ) {
187
191
                                        return new WP_Error(
188
 
                                                'rest_invalid_stored_value', sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 )
 
192
                                                'rest_invalid_stored_value',
 
193
                                                sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ),
 
194
                                                array( 'status' => 500 )
189
195
                                        );
190
196
                                }
191
197
 
232
238
                                'default'     => isset( $args['default'] ) ? $args['default'] : null,
233
239
                        );
234
240
 
235
 
                        $rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] );
 
241
                        $rest_args['schema']      = array_merge( $default_schema, $rest_args['schema'] );
236
242
                        $rest_args['option_name'] = $name;
237
243
 
238
244
                        // Skip over settings that don't have a defined type in the schema.
274
280
                );
275
281
 
276
282
                foreach ( $options as $option_name => $option ) {
277
 
                        $schema['properties'][ $option_name ] = $option['schema'];
 
283
                        $schema['properties'][ $option_name ]                = $option['schema'];
278
284
                        $schema['properties'][ $option_name ]['arg_options'] = array(
279
285
                                'sanitize_callback' => array( $this, 'sanitize_callback' ),
280
286
                        );