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

Previously, only `null` was supported.

Fixes #50790.
Props chrisvanpatten.


git-svn-id: https://develop.svn.wordpress.org/trunk@49966 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Timothy Jacobs
2021-01-17 00:49:39 +00:00
parent 994e657e74
commit 244e4d4e63
2 changed files with 30 additions and 3 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',