Make WordPress Core


Ignore:
Timestamp:
01/17/2021 12:49:39 AM (6 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/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php

    r49927 r49966  
    146146                        }
    147147
     148                        $value = $meta[ $name ];
     149
    148150                        /*
    149151                         * A null value means reset the field, which is essentially deleting it
    150152                         * from the database and then relying on the default value.
     153                         *
     154                         * Non-single meta can also be removed by passing an empty array.
    151155                         */
    152                         if ( is_null( $meta[ $name ] ) ) {
     156                        if ( is_null( $value ) || ( array() === $value && ! $args['single'] ) ) {
    153157                                $args = $this->get_registered_fields()[ $meta_key ];
    154158
     
    172176                                continue;
    173177                        }
    174 
    175                         $value = $meta[ $name ];
    176178
    177179                        if ( ! $args['single'] && is_array( $value ) && count( array_filter( $value, 'is_null' ) ) ) {
Note: See TracChangeset for help on using the changeset viewer.