equal
deleted
inserted
replaced
266 * Updates multiple meta values for an object. |
266 * Updates multiple meta values for an object. |
267 * |
267 * |
268 * Alters the list of values in the database to match the list of provided values. |
268 * Alters the list of values in the database to match the list of provided values. |
269 * |
269 * |
270 * @since 4.7.0 |
270 * @since 4.7.0 |
|
271 * @since 6.7.0 Stores values into DB even if provided registered default value. |
271 * |
272 * |
272 * @param int $object_id Object ID to update. |
273 * @param int $object_id Object ID to update. |
273 * @param string $meta_key Key for the custom field. |
274 * @param string $meta_key Key for the custom field. |
274 * @param string $name Name for the field that is exposed in the REST API. |
275 * @param string $name Name for the field that is exposed in the REST API. |
275 * @param array $values List of values to update to. |
276 * @param array $values List of values to update to. |
288 'status' => rest_authorization_required_code(), |
289 'status' => rest_authorization_required_code(), |
289 ) |
290 ) |
290 ); |
291 ); |
291 } |
292 } |
292 |
293 |
293 $current_values = get_metadata( $meta_type, $object_id, $meta_key, false ); |
294 $current_values = get_metadata_raw( $meta_type, $object_id, $meta_key, false ); |
294 $subtype = get_object_subtype( $meta_type, $object_id ); |
295 $subtype = get_object_subtype( $meta_type, $object_id ); |
295 |
296 |
296 if ( ! is_array( $current_values ) ) { |
297 if ( ! is_array( $current_values ) ) { |
297 $current_values = array(); |
298 $current_values = array(); |
298 } |
299 } |
365 |
366 |
366 /** |
367 /** |
367 * Updates a meta value for an object. |
368 * Updates a meta value for an object. |
368 * |
369 * |
369 * @since 4.7.0 |
370 * @since 4.7.0 |
|
371 * @since 6.7.0 Stores values into DB even if provided registered default value. |
370 * |
372 * |
371 * @param int $object_id Object ID to update. |
373 * @param int $object_id Object ID to update. |
372 * @param string $meta_key Key for the custom field. |
374 * @param string $meta_key Key for the custom field. |
373 * @param string $name Name for the field that is exposed in the REST API. |
375 * @param string $name Name for the field that is exposed in the REST API. |
374 * @param mixed $value Updated value. |
376 * @param mixed $value Updated value. |
376 */ |
378 */ |
377 protected function update_meta_value( $object_id, $meta_key, $name, $value ) { |
379 protected function update_meta_value( $object_id, $meta_key, $name, $value ) { |
378 $meta_type = $this->get_meta_type(); |
380 $meta_type = $this->get_meta_type(); |
379 |
381 |
380 // Do the exact same check for a duplicate value as in update_metadata() to avoid update_metadata() returning false. |
382 // Do the exact same check for a duplicate value as in update_metadata() to avoid update_metadata() returning false. |
381 $old_value = get_metadata( $meta_type, $object_id, $meta_key ); |
383 $old_value = get_metadata_raw( $meta_type, $object_id, $meta_key ); |
382 $subtype = get_object_subtype( $meta_type, $object_id ); |
384 $subtype = get_object_subtype( $meta_type, $object_id ); |
383 |
385 |
384 if ( is_array( $old_value ) && 1 === count( $old_value ) |
386 if ( is_array( $old_value ) && 1 === count( $old_value ) |
385 && $this->is_meta_value_same_as_stored_value( $meta_key, $subtype, $old_value[0], $value ) |
387 && $this->is_meta_value_same_as_stored_value( $meta_key, $subtype, $old_value[0], $value ) |
386 ) { |
388 ) { |
474 'prepare_callback' => array( $this, 'prepare_value' ), |
476 'prepare_callback' => array( $this, 'prepare_value' ), |
475 ); |
477 ); |
476 |
478 |
477 $default_schema = array( |
479 $default_schema = array( |
478 'type' => $default_args['type'], |
480 'type' => $default_args['type'], |
|
481 'title' => empty( $args['label'] ) ? '' : $args['label'], |
479 'description' => empty( $args['description'] ) ? '' : $args['description'], |
482 'description' => empty( $args['description'] ) ? '' : $args['description'], |
480 'default' => isset( $args['default'] ) ? $args['default'] : null, |
483 'default' => isset( $args['default'] ) ? $args['default'] : null, |
481 ); |
484 ); |
482 |
485 |
483 $rest_args = array_merge( $default_args, $rest_args ); |
486 $rest_args = array_merge( $default_args, $rest_args ); |