LLMS_Cache_Helper::maybe_no_cache()

Define nocache constants and set nocache headers on specified pages


Description Description

This prevents caching for the Checkout & Student Dashboard pages.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class.llms.cache.helper.php

	public function maybe_no_cache() {

		if ( ! is_blog_installed() ) {
			return;
		}

		/**
		 * Filter the list of pages that LifterLMS will send nocache headers for.
		 *
		 * @since 3.15.0
		 *
		 * @param int[] $ids List of WP_Post IDs.
		 */
		$ids = apply_filters(
			'llms_no_cache_page_ids',
			array(
				llms_get_page_id( 'checkout' ),
				llms_get_page_id( 'myaccount' ),
			)
		);

		/**
		 * Filter whether or not LifterLMS will send nocache headers.
		 *
		 * @since 6.4.0
		 *
		 * @param bool $no_cache Whether or not LifterLMS will send nocache headers.
		 */
		$do_not_cache = apply_filters( 'llms_no_cache', is_page( $ids ) || is_quiz() );

		if ( $do_not_cache ) {

			add_filter( 'nocache_headers', array( __CLASS__, 'additional_nocache_headers' ), 99 );

			llms_maybe_define_constant( 'DONOTCACHEPAGE', true );
			llms_maybe_define_constant( 'DONOTCACHEOBJECT', true );
			llms_maybe_define_constant( 'DONOTCACHEDB', true );
			nocache_headers();
			$this->exclude_page_from_wpe_server_cache();

			remove_filter( 'nocache_headers', array( __CLASS__, 'additional_nocache_headers' ), 99 );

		}

	}


Top ↑

Changelog Changelog

Changelog
Version Description
6.6.0 Added WP Engine server-side cache exclusions.
6.4.0 Force no caching on quiz pages. Added 'no-store' to the default WordPress nocache headers.
3.15.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.