WC_Helper_Updater::should_use_cached_update_data │ private static │ WC 10.3.6

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

Ensures the cached data is properly structured, corresponds to the current payload, and was not expired by a refresh, to avoid fatal errors and stale cache returns.

Метод класса: WC_Helper_Updater{}

Хуков нет.

Возвращает

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

Использование

$result = WC_Helper_Updater::should_use_cached_update_data( $data, $hash );
$data(разное) (обязательный)
The data retrieved from the transient.
$hash(строка) (обязательный)
The expected hash to compare against.

Список изменений

С версии 10.3.6 Введена.

Код WC_Helper_Updater::should_use_cached_update_data() WC 11.3.0

private static function should_use_cached_update_data( $data, $hash ) {
	if ( ! is_array( $data ) || ! empty( $data['expired'] ) || ! self::is_fresh_update_data( $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'] );
}