mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-05-23 12:44:30 +00:00
REST API: Only cast scalar types to string when comparing new & old meta values.
Newly-supported array and object meta types should not be cast to strings. Props TimothyBlynJacobs, caercam. Fixes #47928. git-svn-id: https://develop.svn.wordpress.org/trunk@45903 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -350,9 +350,17 @@ abstract class WP_REST_Meta_Fields {
|
||||
// Do the exact same check for a duplicate value as in update_metadata() to avoid update_metadata() returning false.
|
||||
$old_value = get_metadata( $meta_type, $object_id, $meta_key );
|
||||
$subtype = get_object_subtype( $meta_type, $object_id );
|
||||
$args = $this->get_registered_fields()[ $meta_key ];
|
||||
|
||||
if ( 1 === count( $old_value ) ) {
|
||||
if ( (string) sanitize_meta( $meta_key, $value, $meta_type, $subtype ) === $old_value[0] ) {
|
||||
$sanitized = sanitize_meta( $meta_key, $value, $meta_type, $subtype );
|
||||
|
||||
if ( in_array( $args['type'], array( 'string', 'number', 'integer', 'boolean' ), true ) ) {
|
||||
// The return value of get_metadata will always be a string for scalar types.
|
||||
$sanitized = (string) $sanitized;
|
||||
}
|
||||
|
||||
if ( $sanitized === $old_value[0] ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user