WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/28/2019 03:07:03 AM (8 weeks ago)
Author:
kadamwhite
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php

    r45807 r45903  
    351351        $old_value = get_metadata( $meta_type, $object_id, $meta_key );
    352352        $subtype   = get_object_subtype( $meta_type, $object_id );
     353        $args      = $this->get_registered_fields()[ $meta_key ];
    353354
    354355        if ( 1 === count( $old_value ) ) {
    355             if ( (string) sanitize_meta( $meta_key, $value, $meta_type, $subtype ) === $old_value[0] ) {
     356            $sanitized = sanitize_meta( $meta_key, $value, $meta_type, $subtype );
     357
     358            if ( in_array( $args['type'], array( 'string', 'number', 'integer', 'boolean' ), true ) ) {
     359                // The return value of get_metadata will always be a string for scalar types.
     360                $sanitized = (string) $sanitized;
     361            }
     362
     363            if ( $sanitized === $old_value[0] ) {
    356364                return true;
    357365            }
Note: See TracChangeset for help on using the changeset viewer.