Make WordPress Core

Opened 4 years ago

Last modified 4 years ago

#51730 new enhancement

update_metadata function: differentiate failure from no update

Reported by: msea55's profile msea55 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords:
Focuses: administration Cc:

Description (last modified by sabernhardt)

The WordPress function update_metadata, (as well as update_post_meta, and update_term_meta which call it) returns false on failure or if the value passed to the function is the same as the one that is already in the database. This behavior is documented by WordPress: https://developer.wordpress.org/reference/functions/update_metadata/.

However, I would like to be able to differentiate the failure case from the no update case. In my custom plugin I allow users to update post meta; I want to show them a failure message if their update failed and nothing if there was no update.

There is precedent for such a differentiation in wpdb::update which returns 0 if no rows are updated and false on failure. I can use this instead, but I would like the full functionality of update_metadata.

Is there a reason this differentiation is not made here? (either by default or with a passed in parameter). If not, this is a feature request to make that differentiation and return false on failure and 0 on no update.

Change History (1)

#1 @sabernhardt
4 years ago

  • Component changed from General to Options, Meta APIs
  • Description modified (diff)
  • Summary changed from Feature request: For update_metadata to differentiate failure from no update to update_metadata function: differentiate failure from no update
  • Type changed from feature request to enhancement
Note: See TracTickets for help on using tickets.