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..0953a9fd41 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 | /** |
| 1056 | * Ensure deleting non-existant meta data behaves gracefully. |
| 1057 | * |
| 1058 | * @ticket 52787 |
| 1059 | * @dataProvider data_delete_does_not_trigger_error_if_no_meta_values |
| 1060 | * |
| 1061 | * @param array|null $delete_value Value used to delete meta data. |
| 1062 | */ |
| 1063 | public function test_delete_does_not_trigger_error_if_no_meta_values( $delete_value ) { |
| 1064 | $this->grant_write_permission(); |
| 1065 | |
| 1066 | $data = array( |
| 1067 | 'meta' => array( |
| 1068 | 'test_multi' => $delete_value, |
| 1069 | ), |
| 1070 | ); |
| 1071 | $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) ); |
| 1072 | $request->set_body_params( $data ); |
| 1073 | |
| 1074 | $response = rest_get_server()->dispatch( $request ); |
| 1075 | |
| 1076 | $this->assertSame( 200, $response->get_status() ); |
| 1077 | } |
| 1078 | |
| 1079 | /** |
| 1080 | * Data provider for test_delete_does_not_trigger_error_if_no_meta_values(). |
| 1081 | * |
| 1082 | * @return array[] Array of test parameters. |
| 1083 | */ |
| 1084 | public function data_delete_does_not_trigger_error_if_no_meta_values() { |
| 1085 | return array( |
| 1086 | array( array() ), |
| 1087 | array( null ), |
| 1088 | ); |
| 1089 | } |
| 1090 | |
1055 | 1091 | public function test_remove_multi_value_db_error() { |
1056 | 1092 | add_post_meta( self::$post_id, 'test_multi', 'val1' ); |
1057 | 1093 | $values = get_post_meta( self::$post_id, 'test_multi', false ); |