Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#50790 closed defect (bug) (fixed)

REST API: Allow sending empty array to remove all values for single = false meta

Reported by: chrisvanpatten's profile chrisvanpatten Owned by: timothyblynjacobs's profile TimothyBlynJacobs
Milestone: 5.7 Priority: normal
Severity: normal Version: 4.7
Component: REST API Keywords: good-first-bug has-patch has-unit-tests
Focuses: rest-api Cc:

Description

When sending an update to a piece of content via the REST API, meta registered with 'single' => false cannot be removed by sending an empty array; you must send null.

The inability to send an empty array is slightly confusing and inconsistent with array-type meta registered with 'single' => true, which will correctly save the empty value.

Change History (6)

#1 @TimothyBlynJacobs
4 years ago

  • Keywords good-first-bug added
  • Milestone changed from Awaiting Review to Future Release
  • Version set to 4.7

@chrisvanpatten Do you want to work on a patch for this? We have a bit more time for inclusion in 5.6.

I think the fix would be updating the is_null() clause in WP_REST_Meta_Fields::update_value() to a accept an empty array if the meta type is not single.

This ticket was mentioned in Slack in #core-restapi by chrisvanpatten. View the logs.


4 years ago

This ticket was mentioned in PR #869 on WordPress/wordpress-develop by chrisvanpatten.


4 years ago
#3

  • Keywords has-patch has-unit-tests added

Allow passing an empty array to the REST API for registered non-single meta to remove the DB values, as an alternative to sending null.

Trac ticket: https://core.trac.wordpress.org/ticket/50790

#4 @TimothyBlynJacobs
4 years ago

  • Owner set to TimothyBlynJacobs
  • Resolution set to fixed
  • Status changed from new to closed

In 49966:

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

Previously, only null was supported.

Fixes #50790.
Props chrisvanpatten.

#5 @TimothyBlynJacobs
4 years ago

  • Milestone changed from Future Release to 5.7
Note: See TracTickets for help on using tickets.