From 181d77f04e816ae276296972d64ad3666171d2d9 Mon Sep 17 00:00:00 2001 From: "K. Adam White" Date: Wed, 28 Aug 2019 03:08:55 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@45903 git-svn-id: http://core.svn.wordpress.org/trunk@45714 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../rest-api/fields/class-wp-rest-meta-fields.php | 10 +++++++++- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php b/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php index 5b7240ddc6..490cf346b8 100644 --- a/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php +++ b/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php @@ -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; } } diff --git a/wp-includes/version.php b/wp-includes/version.php index 8c1a3da80d..9ce2bad563 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-alpha-45902'; +$wp_version = '5.3-alpha-45903'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.