<?php
namespace QuizPress\Classes;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use QuizPress\Helper;

abstract class CachePluginAbstract {
	protected $plugin = '';

	public static function init() {
		$self = new static();
		add_action( 'wp', array( $self, 'do_not_cache_page' ) );
	}

	public function do_not_cache_page() {
		if ( ! $this->is_plugin_active() ) {
			return;
		}

		// Admin pages, and frontend pages rendering the quiz, must always be
		// fresh — the quiz bootstraps from settings/addon data baked into the
		// page's inline script, which would otherwise go stale once cached.
		if ( Helper::is_quizpress_admin_page() || Helper::is_quizpress_quiz_page() ) {
			$this->do_not_cache();
		}
	}

	protected function is_plugin_active() {
		return Helper::is_plugin_active( $this->plugin );
	}

	abstract public function do_not_cache();

}
