WP_REST_Meta_Fields::is_meta_value_same_as_stored_value()protectedWP 5.5.0

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

Method of the class: WP_REST_Meta_Fields{}

No Hooks.




// protected - for code of main (parent) or child class
$result = $this->is_meta_value_same_as_stored_value( $meta_key, $subtype, $stored_value, $user_value );
$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.


Since 5.5.0 Introduced.

WP_REST_Meta_Fields::is_meta_value_same_as_stored_value() code WP 6.5.2

protected function is_meta_value_same_as_stored_value( $meta_key, $subtype, $stored_value, $user_value ) {
	$args      = $this->get_registered_fields()[ $meta_key ];
	$sanitized = sanitize_meta( $meta_key, $user_value, $this->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;