WP_REST_Meta_Fields::is_meta_value_same_as_stored_value() – Checks if the user provided value is equivalent to a stored value for the given meta key.

You appear to be a bot. Output may be restricted

Description

Checks if the user provided value is equivalent to a stored value for the given meta key.

Usage

$bool = WP_REST_Meta_Fields::is_meta_value_same_as_stored_value( $meta_key, $subtype, $stored_value, $user_value );

Parameters

$meta_key
( string ) required – The meta key being checked.
$subtype
( string ) required – The object subtype.
$stored_value
( mixed ) required – The currently stored value retrieved from get_metadata().
$user_value
( mixed ) required – The value provided by the user.

Returns

bool

Source

File name: wordpress/wp-includes/rest-api/fields/class-wp-rest-meta-fields.php
Lines:

1 to 11 of 11
  protected function is_meta_value_same_as_stored_value( $meta_key, $subtype, $stored_value, $user_value ) {
    $args      = $this->WP_REST_Meta_Fields::get_registered_fields()[ $meta_key ];
    $sanitized = sanitize_meta( $meta_key, $user_value, $this->WP_REST_Meta_Fields::get_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;
    }

    return $sanitized === $stored_value;
  }
 

 View on GitHub View on Trac