mirror of
https://github.com/WordPress/WordPress.git
synced 2025-01-14 04:01:54 +01:00
REST API: Slash existing meta values when comparing with incoming meta upates.
When comparing the old and new values for a meta key being set, ensure both values are sanitized using the same logic so that equal values match. props boonebgorges, dcavins, MattGeri, pilou69, TimothyBlynJacobs. Fixes #42069. Built from https://develop.svn.wordpress.org/branches/5.0@43740 git-svn-id: http://core.svn.wordpress.org/branches/5.0@43569 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
a2d601024f
commit
a943d902c1
@ -295,19 +295,17 @@ abstract class WP_REST_Meta_Fields {
|
||||
);
|
||||
}
|
||||
|
||||
$meta_key = wp_slash( $meta_key );
|
||||
$meta_value = wp_slash( $value );
|
||||
|
||||
// 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 );
|
||||
|
||||
if ( 1 === count( $old_value ) ) {
|
||||
if ( $old_value[0] === $meta_value ) {
|
||||
if ( (string) sanitize_meta( $meta_key, $value, $meta_type, $subtype ) === $old_value[0] ) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if ( ! update_metadata( $meta_type, $object_id, $meta_key, $meta_value ) ) {
|
||||
if ( ! update_metadata( $meta_type, $object_id, wp_slash( $meta_key ), wp_slash( $value ) ) ) {
|
||||
return new WP_Error(
|
||||
'rest_meta_database_error',
|
||||
__( 'Could not update meta value in database.' ),
|
||||
|
@ -4,7 +4,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '5.0-alpha-43739';
|
||||
$wp_version = '5.0-alpha-43740';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user