REST API: Prevent database error when deleting meta data.

Add a check to `WP_REST_Meta_Fields::delete_meta_value()` ensuring meta data is set before attempting to delete it from the database. If the data does not exist, the delete is considered successful as the data matches the desired state.

Props BrechtVds, goaroundagain, TimothyBlynJacobs.
Fixes #52787.


git-svn-id: https://develop.svn.wordpress.org/trunk@50567 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Peter Wilson
2021-03-23 23:34:59 +00:00
parent 6388364fec
commit e2fff3fddc
2 changed files with 40 additions and 0 deletions
@@ -232,6 +232,10 @@ abstract class WP_REST_Meta_Fields {
);
}
if ( null === get_metadata_raw( $meta_type, $object_id, wp_slash( $meta_key ) ) ) {
return true;
}
if ( ! delete_metadata( $meta_type, $object_id, wp_slash( $meta_key ) ) ) {
return new WP_Error(
'rest_meta_database_error',