Changeset 57611
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php
r56075 r57611 142 142 public function update_value( $meta, $object_id ) { 143 143 $fields = $this->get_registered_fields(); 144 $error = new WP_Error(); 144 145 145 146 foreach ( $fields as $meta_key => $args ) { … … 164 165 165 166 if ( is_wp_error( rest_validate_value_from_schema( $current, $args['schema'] ) ) ) { 166 return new WP_Error(167 $error->add( 167 168 'rest_invalid_stored_value', 168 169 /* translators: %s: Custom field key. */ … … 170 171 array( 'status' => 500 ) 171 172 ); 173 continue; 172 174 } 173 175 } … … 175 177 $result = $this->delete_meta_value( $object_id, $meta_key, $name ); 176 178 if ( is_wp_error( $result ) ) { 177 return $result;179 $error->merge_from( $result ); 178 180 } 179 181 continue; … … 181 183 182 184 if ( ! $args['single'] && is_array( $value ) && count( array_filter( $value, 'is_null' ) ) ) { 183 return new WP_Error(185 $error->add( 184 186 'rest_invalid_stored_value', 185 187 /* translators: %s: Custom field key. */ … … 187 189 array( 'status' => 500 ) 188 190 ); 191 continue; 189 192 } 190 193 … … 192 195 if ( is_wp_error( $is_valid ) ) { 193 196 $is_valid->add_data( array( 'status' => 400 ) ); 194 return $is_valid; 197 $error->merge_from( $is_valid ); 198 continue; 195 199 } 196 200 … … 204 208 205 209 if ( is_wp_error( $result ) ) { 206 return $result; 207 } 210 $error->merge_from( $result ); 211 continue; 212 } 213 } 214 215 if ( $error->has_errors() ) { 216 return $error; 208 217 } 209 218 -
trunk/tests/phpunit/tests/rest-api/rest-post-meta-fields.php
r56745 r57611 3097 3097 3098 3098 /** 3099 * @ticket 48823 3100 */ 3101 public function test_multiple_errors_are_returned_at_once() { 3102 $this->grant_write_permission(); 3103 register_post_meta( 3104 'post', 3105 'error_1', 3106 array( 3107 'single' => true, 3108 'show_in_rest' => array( 3109 'schema' => array( 3110 'enum' => array( 'a', 'b' ), 3111 ), 3112 ), 3113 ) 3114 ); 3115 register_post_meta( 3116 'post', 3117 'error_2', 3118 array( 3119 'single' => true, 3120 'show_in_rest' => array( 3121 'schema' => array( 3122 'minLength' => 1, 3123 ), 3124 ), 3125 ) 3126 ); 3127 3128 $request = new WP_REST_Request( 'PUT', '/wp/v2/posts/' . self::$post_id ); 3129 $request->set_body_params( 3130 array( 3131 'meta' => array( 3132 'error_1' => 'c', 3133 'error_2' => '', 3134 ), 3135 ) 3136 ); 3137 $response = rest_do_request( $request ); 3138 $error = $response->as_error(); 3139 $this->assertWPError( $error ); 3140 $this->assertContains( 'meta.error_1 is not one of a and b.', $error->get_error_messages() ); 3141 $this->assertContains( 'meta.error_2 must be at least 1 character long.', $error->get_error_messages() ); 3142 } 3143 3144 /** 3099 3145 * Internal function used to disable an insert query which 3100 3146 * will trigger a wpdb error for testing purposes.
Note: See TracChangeset
for help on using the changeset viewer.