36
36
public function register_routes() {
38
register_rest_route( $this->namespace, '/' . $this->rest_base, array(
40
'methods' => WP_REST_Server::READABLE,
41
'callback' => array( $this, 'get_item' ),
43
'permission_callback' => array( $this, 'get_item_permissions_check' ),
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' ),
51
'schema' => array( $this, 'get_public_item_schema' ),
40
'/' . $this->rest_base,
43
'methods' => WP_REST_Server::READABLE,
44
'callback' => array( $this, 'get_item' ),
46
'permission_callback' => array( $this, 'get_item_permissions_check' ),
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' ),
54
'schema' => array( $this, 'get_public_item_schema' ),
139
143
public function update_item( $request ) {
140
144
$options = $this->get_registered_options();
142
$params = $request->get_params();
146
$params = $request->get_params();
144
148
foreach ( $options as $name => $args ) {
145
149
if ( ! array_key_exists( $name, $params ) ) {
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 )
232
238
'default' => isset( $args['default'] ) ? $args['default'] : null,
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;
238
244
// Skip over settings that don't have a defined type in the schema.
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' ),