diff -r 7b1b88e27a20 -r 48c4eec2b7e6 wp/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php --- a/wp/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php Thu Sep 29 08:06:27 2022 +0200 +++ b/wp/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php Fri Sep 05 18:40:08 2025 +0200 @@ -12,6 +12,7 @@ * * @since 4.7.0 */ +#[AllowDynamicProperties] abstract class WP_REST_Meta_Fields { /** @@ -140,6 +141,7 @@ */ public function update_value( $meta, $object_id ) { $fields = $this->get_registered_fields(); + $error = new WP_Error(); foreach ( $fields as $meta_key => $args ) { $name = $args['name']; @@ -162,35 +164,38 @@ $current = get_metadata( $this->get_meta_type(), $object_id, $meta_key, true ); if ( is_wp_error( rest_validate_value_from_schema( $current, $args['schema'] ) ) ) { - return new WP_Error( + $error->add( 'rest_invalid_stored_value', /* translators: %s: Custom field key. */ sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 ) ); + continue; } } $result = $this->delete_meta_value( $object_id, $meta_key, $name ); if ( is_wp_error( $result ) ) { - return $result; + $error->merge_from( $result ); } continue; } if ( ! $args['single'] && is_array( $value ) && count( array_filter( $value, 'is_null' ) ) ) { - return new WP_Error( + $error->add( 'rest_invalid_stored_value', /* translators: %s: Custom field key. */ sprintf( __( 'The %s property has an invalid stored value, and cannot be updated to null.' ), $name ), array( 'status' => 500 ) ); + continue; } $is_valid = rest_validate_value_from_schema( $value, $args['schema'], 'meta.' . $name ); if ( is_wp_error( $is_valid ) ) { $is_valid->add_data( array( 'status' => 400 ) ); - return $is_valid; + $error->merge_from( $is_valid ); + continue; } $value = rest_sanitize_value_from_schema( $value, $args['schema'] ); @@ -202,10 +207,15 @@ } if ( is_wp_error( $result ) ) { - return $result; + $error->merge_from( $result ); + continue; } } + if ( $error->has_errors() ) { + return $error; + } + return null; } @@ -367,6 +377,16 @@ protected function update_meta_value( $object_id, $meta_key, $name, $value ) { $meta_type = $this->get_meta_type(); + // Do the exact same check for a duplicate value as in update_metadata() to avoid update_metadata() returning false. + $old_value = get_metadata( $meta_type, $object_id, $meta_key ); + $subtype = get_object_subtype( $meta_type, $object_id ); + + if ( is_array( $old_value ) && 1 === count( $old_value ) + && $this->is_meta_value_same_as_stored_value( $meta_key, $subtype, $old_value[0], $value ) + ) { + return true; + } + if ( ! current_user_can( "edit_{$meta_type}_meta", $object_id, $meta_key ) ) { return new WP_Error( 'rest_cannot_update', @@ -379,16 +399,6 @@ ); } - // Do the exact same check for a duplicate value as in update_metadata() to avoid update_metadata() returning false. - $old_value = get_metadata( $meta_type, $object_id, $meta_key ); - $subtype = get_object_subtype( $meta_type, $object_id ); - - if ( is_array( $old_value ) && 1 === count( $old_value ) - && $this->is_meta_value_same_as_stored_value( $meta_key, $subtype, $old_value[0], $value ) - ) { - return true; - } - if ( ! update_metadata( $meta_type, $object_id, wp_slash( $meta_key ), wp_slash( $value ) ) ) { return new WP_Error( 'rest_meta_database_error',