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

Previously, only `null` was supported.

Fixes #50790.
Props chrisvanpatten.

Built from https://develop.svn.wordpress.org/trunk@49966


git-svn-id: http://core.svn.wordpress.org/trunk@49667 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
TimothyBlynJacobs 2021-01-17 00:51:09 +00:00
parent ba0906799c
commit cc1c1b0b5d
2 changed files with 6 additions and 4 deletions

View File

@ -145,11 +145,15 @@ abstract class WP_REST_Meta_Fields {
continue;
}
$value = $meta[ $name ];
/*
* A null value means reset the field, which is essentially deleting it
* from the database and then relying on the default value.
*
* Non-single meta can also be removed by passing an empty array.
*/
if ( is_null( $meta[ $name ] ) ) {
if ( is_null( $value ) || ( array() === $value && ! $args['single'] ) ) {
$args = $this->get_registered_fields()[ $meta_key ];
if ( $args['single'] ) {
@ -172,8 +176,6 @@ abstract class WP_REST_Meta_Fields {
continue;
}
$value = $meta[ $name ];
if ( ! $args['single'] && is_array( $value ) && count( array_filter( $value, 'is_null' ) ) ) {
return new WP_Error(
'rest_invalid_stored_value',

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.7-alpha-49965';
$wp_version = '5.7-alpha-49966';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.