diff --git a/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php b/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php
index 78cef6f910..dba39017c4 100644
a
|
b
|
abstract class WP_REST_Meta_Fields { |
232 | 232 | ); |
233 | 233 | } |
234 | 234 | |
| 235 | if ( null === get_metadata_raw( $meta_type, $object_id, wp_slash( $meta_key ) ) ) { |
| 236 | return true; |
| 237 | } |
| 238 | |
235 | 239 | if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $meta_key ) ) ) { |
236 | 240 | return new WP_Error( |
237 | 241 | 'rest_meta_database_error', |
diff --git a/tests/phpunit/tests/rest-api/rest-post-meta-fields.php b/tests/phpunit/tests/rest-api/rest-post-meta-fields.php
index 2b24cfc667..ddf87abaa1 100644
a
|
b
|
class WP_Test_REST_Post_Meta_Fields extends WP_Test_REST_TestCase { |
1052 | 1052 | $this->assertEmpty( $meta ); |
1053 | 1053 | } |
1054 | 1054 | |
| 1055 | public function test_delete_does_not_trigger_error_if_no_meta_values() { |
| 1056 | $this->grant_write_permission(); |
| 1057 | |
| 1058 | $data = array( |
| 1059 | 'meta' => array( |
| 1060 | 'test_multi' => array(), |
| 1061 | ), |
| 1062 | ); |
| 1063 | $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| 1064 | $request->set_body_params( $data ); |
| 1065 | |
| 1066 | $response = rest_get_server()->dispatch( $request ); |
| 1067 | |
| 1068 | $this->assertSame( 200, $response->get_status() ); |
| 1069 | } |
| 1070 | |
1055 | 1071 | public function test_remove_multi_value_db_error() { |
1056 | 1072 | add_post_meta( self::$post_id, 'test_multi', 'val1' ); |
1057 | 1073 | $values = get_post_meta( self::$post_id, 'test_multi', false ); |