WC_Cache_Helper::additional_nocache_headers()public staticWC 3.6.0

Set additional nocache headers.

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

Хуки из метода

Возвращает

null. Ничего (null).

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

$result = WC_Cache_Helper::additional_nocache_headers( $headers );
$headers(массив) (обязательный)
Header names and field values.

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

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

Код WC_Cache_Helper::additional_nocache_headers() WC 8.7.0

public static function additional_nocache_headers( $headers ) {
	global $wp_query;

	$agent = isset( $_SERVER['HTTP_USER_AGENT'] ) ? wp_unslash( $_SERVER['HTTP_USER_AGENT'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized

	$set_cache = false;

	/**
	 * Allow plugins to enable nocache headers. Enabled for Google weblight.
	 *
	 * @param bool $enable_nocache_headers Flag indicating whether to add nocache headers. Default: false.
	 */
	if ( apply_filters( 'woocommerce_enable_nocache_headers', false ) ) {
		$set_cache = true;
	}

	/**
	 * Enabled for Google weblight.
	 *
	 * @see https://support.google.com/webmasters/answer/1061943?hl=en
	 */
	if ( false !== strpos( $agent, 'googleweblight' ) ) {
		// no-transform: Opt-out of Google weblight. https://support.google.com/webmasters/answer/6211428?hl=en.
		$set_cache = true;
	}

	if ( false !== strpos( $agent, 'Chrome' ) && isset( $wp_query ) && is_cart() ) {
		$set_cache = true;
	}

	if ( $set_cache ) {
		$headers['Cache-Control'] = 'no-transform, no-cache, no-store, must-revalidate';
	}
	return $headers;
}