Make WordPress Core


Ignore:
Timestamp:
01/17/2021 12:49:39 AM (4 years ago)
Author:
TimothyBlynJacobs
Message:

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

Previously, only null was supported.

Fixes #50790.
Props chrisvanpatten.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-post-meta-fields.php

    r49603 r49966  
    10261026        $post_updated = get_post( self::$post_id );
    10271027        $this->assertSame( $post_original->post_content, $post_updated->post_content );
     1028    }
     1029
     1030    /**
     1031     * @ticket 50790
     1032     */
     1033    public function test_remove_multi_value_with_empty_array() {
     1034        add_post_meta( self::$post_id, 'test_multi', 'val1' );
     1035        $values = get_post_meta( self::$post_id, 'test_multi', false );
     1036        $this->assertSame( array( 'val1' ), $values );
     1037
     1038        $this->grant_write_permission();
     1039
     1040        $data    = array(
     1041            'meta' => array(
     1042                'test_multi' => array(),
     1043            ),
     1044        );
     1045        $request = new WP_REST_Request( 'POST', sprintf( '/wp/v2/posts/%d', self::$post_id ) );
     1046        $request->set_body_params( $data );
     1047
     1048        $response = rest_get_server()->dispatch( $request );
     1049        $this->assertSame( 200, $response->get_status() );
     1050
     1051        $meta = get_post_meta( self::$post_id, 'test_multi', false );
     1052        $this->assertEmpty( $meta );
    10281053    }
    10291054
Note: See TracChangeset for help on using the changeset viewer.