- Timestamp:
- 11/14/2016 04:35:35 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php
r39179 r39222 85 85 } 86 86 87 return (object)$response;87 return $response; 88 88 } 89 89 … … 134 134 if ( is_null( $request[ $name ] ) ) { 135 135 $result = $this->delete_meta_value( $object_id, $name ); 136 } elseif ( $args['single'] ) { 137 $result = $this->update_meta_value( $object_id, $name, $request[ $name ] ); 136 if ( is_wp_error( $result ) ) { 137 return $result; 138 } 139 continue; 140 } 141 142 $is_valid = rest_validate_value_from_schema( $request[ $name ], $args['schema'], 'meta.' . $name ); 143 if ( is_wp_error( $is_valid ) ) { 144 $is_valid->add_data( array( 'status' => 400 ) ); 145 return $is_valid; 146 } 147 148 $value = rest_sanitize_value_from_schema( $request[ $name ], $args['schema'] ); 149 150 if ( $args['single'] ) { 151 $result = $this->update_meta_value( $object_id, $name, $value ); 138 152 } else { 139 $result = $this->update_multi_meta_value( $object_id, $name, $ request[ $name ]);153 $result = $this->update_multi_meta_value( $object_id, $name, $value ); 140 154 } 141 155 … … 320 334 'name' => $name, 321 335 'single' => $args['single'], 336 'type' => ! empty( $args['type'] ) ? $args['type'] : null, 322 337 'schema' => array(), 323 338 'prepare_callback' => array( $this, 'prepare_value' ), … … 325 340 326 341 $default_schema = array( 327 'type' => null,342 'type' => $default_args['type'], 328 343 'description' => empty( $args['description'] ) ? '' : $args['description'], 329 344 'default' => isset( $args['default'] ) ? $args['default'] : null, … … 333 348 $rest_args['schema'] = array_merge( $default_schema, $rest_args['schema'] ); 334 349 335 if ( empty( $rest_args['schema']['type'] ) ) { 336 // Skip over meta fields that don't have a defined type. 337 if ( empty( $args['type'] ) ) { 338 continue; 339 } 340 341 if ( $rest_args['single'] ) { 342 $rest_args['schema']['type'] = $args['type']; 343 } else { 344 $rest_args['schema']['type'] = 'array'; 345 $rest_args['schema']['items'] = array( 346 'type' => $args['type'], 347 ); 348 } 350 $type = ! empty( $rest_args['type'] ) ? $rest_args['type'] : null; 351 $type = ! empty( $rest_args['schema']['type'] ) ? $rest_args['schema']['type'] : $type; 352 353 if ( ! in_array( $type, array( 'string', 'boolean', 'integer', 'number' ) ) ) { 354 continue; 355 } 356 357 if ( empty( $rest_args['single'] ) ) { 358 $rest_args['schema']['items'] = array( 359 'type' => $rest_args['type'], 360 ); 361 $rest_args['schema']['type'] = 'array'; 349 362 } 350 363
Note: See TracChangeset
for help on using the changeset viewer.