Changeset 49966
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php
r49927 r49966 146 146 } 147 147 148 $value = $meta[ $name ]; 149 148 150 /* 149 151 * A null value means reset the field, which is essentially deleting it 150 152 * from the database and then relying on the default value. 153 * 154 * Non-single meta can also be removed by passing an empty array. 151 155 */ 152 if ( is_null( $ meta[ $name] ) ) {156 if ( is_null( $value ) || ( array() === $value && ! $args['single'] ) ) { 153 157 $args = $this->get_registered_fields()[ $meta_key ]; 154 158 … … 172 176 continue; 173 177 } 174 175 $value = $meta[ $name ];176 178 177 179 if ( ! $args['single'] && is_array( $value ) && count( array_filter( $value, 'is_null' ) ) ) { -
trunk/tests/phpunit/tests/rest-api/rest-post-meta-fields.php
r49603 r49966 1026 1026 $post_updated = get_post( self::$post_id ); 1027 1027 $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 ); 1028 1053 } 1029 1054
Note: See TracChangeset
for help on using the changeset viewer.