Make WordPress Core

Ticket #52787: 52787.diff

File 52787.diff, 1.6 KB (added by goaroundagain, 4 years ago)
  • src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php

    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 { 
    232232                        );
    233233                }
    234234
     235                if ( null === get_metadata_raw( $meta_type,  $object_id, wp_slash( $meta_key ) ) ) {
     236                        return true;
     237                }
     238
    235239                if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $meta_key ) ) ) {
    236240                        return new WP_Error(
    237241                                'rest_meta_database_error',
  • tests/phpunit/tests/rest-api/rest-post-meta-fields.php

    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 { 
    10521052                $this->assertEmpty( $meta );
    10531053        }
    10541054
     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
    10551071        public function test_remove_multi_value_db_error() {
    10561072                add_post_meta( self::$post_id, 'test_multi', 'val1' );
    10571073                $values = get_post_meta( self::$post_id, 'test_multi', false );