WC_Helper_Updater::should_use_cached_update_dataprivate staticWC 10.3.6

Validates cached update data and checks if it matches the expected hash.

Ensures the cached data is properly structured and corresponds to the current payload to prevent fatal errors and avoid stale cache returns.

Method of the class: WC_Helper_Updater{}

No Hooks.

Returns

true|false. True if the data is valid and hash matches, false otherwise.

Usage

$result = WC_Helper_Updater::should_use_cached_update_data( $data, $hash );
$data(mixed) (required)
The data retrieved from the transient.
$hash(string) (required)
The expected hash to compare against.

Changelog

Since 10.3.6 Introduced.

WC_Helper_Updater::should_use_cached_update_data() code WC 10.4.3

private static function should_use_cached_update_data( $data, $hash ) {
	if ( ! is_array( $data ) ) {
		return false;
	}

	if ( ! isset( $data['hash'], $data['products'] ) ) {
		return false;
	}

	if ( ! is_string( $data['hash'] ) || ! is_array( $data['products'] ) ) {
		return false;
	}

	return hash_equals( $hash, $data['hash'] );
}