REST API: Allow sending an empty array to delete multi meta keys.

Previously, only `null` was supported.

Fixes #50790.
Props chrisvanpatten.


git-svn-id: https://develop.svn.wordpress.org/trunk@49966 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs
2021-01-17 00:49:39 +00:00
parent 994e657e74
commit 244e4d4e63
2 changed files with 30 additions and 3 deletions

View File

@@ -1027,6 +1027,31 @@ class WP_Test_REST_Post_Meta_Fields extends WP_Test_REST_TestCase {
$this->assertSame( $post_original->post_content, $post_updated->post_content );
}
/**
* @ticket 50790
*/
public function test_remove_multi_value_with_empty_array() {
add_post_meta( self::$post_id, 'test_multi', 'val1' );
$values = get_post_meta( self::$post_id, 'test_multi', false );
$this->assertSame( array( 'val1' ), $values );
$this->grant_write_permission();
$data = array(
'meta' => array(
'test_multi' => array(),
),
);
$request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
$request->set_body_params( $data );
$response = rest_get_server()->dispatch( $request );
$this->assertSame( 200, $response->get_status() );
$meta = get_post_meta( self::$post_id, 'test_multi', false );
$this->assertEmpty( $meta );
}
public function test_remove_multi_value_db_error() {
add_post_meta( self::$post_id, 'test_multi', 'val1' );
$values = get_post_meta( self::$post_id, 'test_multi', false );