<?php
/**
 * Plugin Name: HVAC No-Cache for Login
 * Description: Prevents caching on login and dashboard pages
 * Version: 1.0
 */

function hvac_disable_cache() {
    // Check if we are on a login-related page
    $uri = isset($_SERVER["REQUEST_URI"]) ? $_SERVER["REQUEST_URI"] : "";
    $disable_cache = false;
    
    // Pages that should never be cached
    $no_cache_pages = array(
        "community-login",
        "wp-login.php",
        "hvac-dashboard",
        "certificate-reports",
        "generate-certificates",
        "event-summary"
    );
    
    foreach ($no_cache_pages as $page) {
        if (strpos($uri, $page) !== false) {
            $disable_cache = true;
            break;
        }
    }
    
    // Also disable cache for logged-in users or authentication attempts
    if (is_user_logged_in() || isset($_POST["log"]) || isset($_GET["login"])) {
        $disable_cache = true;
    }
    
    if ($disable_cache) {
        // Define WordPress constant
        if (!defined("DONOTCACHEPAGE")) {
            define("DONOTCACHEPAGE", true);
        }
        
        // Set no-cache headers
        header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
        header("Pragma: no-cache");
    }
}
add_action("init", "hvac_disable_cache", 0);

// Disable Breeze caching for logged-in users
function hvac_disable_breeze_cache() {
    if (is_user_logged_in()) {
        add_filter("breeze_skip_cache", "__return_true");
    }
}
add_action("init", "hvac_disable_breeze_cache");