- Timestamp:
- 10/05/2017 12:18:44 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php
r41731 r41758 120 120 */ 121 121 protected function prepare_value( $value, $schema ) { 122 // If the value is not a scalar, it's not possible to cast it to anything. 123 if ( ! is_scalar( $value ) ) { 122 // If the value is not valid by the schema, set the value to null. Null 123 // values are specifcally non-destructive so this will not cause overwriting 124 // the current invalid value to null. 125 if ( is_wp_error( rest_validate_value_from_schema( $value, $schema ) ) ) { 124 126 return null; 125 127 } 126 127 switch ( $schema['type'] ) { 128 case 'string': 129 return (string) $value; 130 case 'integer': 131 return (int) $value; 132 case 'number': 133 return (float) $value; 134 case 'boolean': 135 return (bool) $value; 136 default: 137 return null; 138 } 128 return rest_sanitize_value_from_schema( $value, $schema ); 139 129 } 140 130 … … 149 139 public function update_item( $request ) { 150 140 $options = $this->get_registered_options(); 141 151 142 $params = $request->get_params(); 152 143 … … 188 179 * To protect clients from accidentally including the null 189 180 * values from a response object in a request, we do not allow 190 * options with non-scalar valuesto be updated to null.181 * options with values that don't pass validation to be updated to null. 191 182 * Without this added protection a client could mistakenly 192 * delete all options that have non-scalarvalues from the183 * delete all options that have invalid values from the 193 184 * database. 194 185 */ 195 if ( ! is_scalar( get_option( $args['option_name'], false) ) ) {186 if ( is_wp_error( rest_validate_value_from_schema( get_option( $args['option_name'], false ), $args['schema'] ) ) ) { 196 187 return new WP_Error( 197 188 'rest_invalid_stored_value', sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 ) … … 254 245 * to be updated with arbitrary values that we can't do decent sanitizing for. 255 246 */ 256 if ( ! in_array( $rest_args['schema']['type'], array( 'number', 'integer', 'string', 'boolean' ), true ) ) {247 if ( ! in_array( $rest_args['schema']['type'], array( 'number', 'integer', 'string', 'boolean', 'array', 'object' ), true ) ) { 257 248 continue; 258 249 }
Note: See TracChangeset
for help on using the changeset viewer.