WordPress.org

Make WordPress Core

Opened 6 months ago

Closed 4 days ago

Last modified 4 days ago

#50790 closed defect (bug) (fixed)

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

Reported by: chrisvanpatten Owned by: 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
3 months 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.


8 days ago

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


7 days ago

  • 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 days 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 days ago

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