<?php
defined('ABSPATH') || exit;

/**
 * REEID SEO Guard — PAGES ONLY
 * Purpose:
 * - Allow REEID hreflang on pages
 * - HARD exclude WooCommerce
 * - Neutralize 3rd-party SEO ONLY for pages
 */

add_action('wp', function () {
    if (is_admin()) {
        return;
    }

    // Must be explicitly enabled
    if ( ! (bool) get_option('reeid_seo_override_hreflang', false) ) {
        return;
    }

    // HARD STOP: WooCommerce must never be touched
    if ( function_exists('is_woocommerce') && is_woocommerce() ) {
        return;
    }
    if ( function_exists('is_product') && is_product() ) {
        return;
    }
    if ( function_exists('is_shop') && is_shop() ) {
        return;
    }

    // Pages only
    if ( ! is_page() ) {
        return;
    }

    // Yoast
    remove_action('wpseo_head', 'wpseo_head', 1);

    // Rank Math
    add_filter('rank_math/frontend/canonical', '__return_false', 99);
    remove_all_actions('rank_math/head');

    // AIOSEO
    remove_all_actions('aioseo_head');

    // SureRank
    remove_all_actions('surerank_print_meta');

}, 0);