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

/**
 * REEID — Global SEO Plugin Neutralizer
 *
 * When enabled:
 * - REEID fully controls canonical + hreflang
 * - All SEO plugins are silenced
 * - Works for Pages, Posts, Woo (including inline)
 */

add_action('wp', function () {

    if (is_admin()) {
        return;
    }

    if ( ! (bool) get_option('reeid_seo_override_hreflang', false) ) {
        return;
    }

    /* ---------------------------------
     * Remove WordPress core canonical
     * --------------------------------- */
    remove_action('wp_head', 'rel_canonical');

    /* ---------------------------------
     * Yoast
     * --------------------------------- */
    remove_action('wpseo_head', 'wpseo_head', 1);
    add_filter('wpseo_canonical', '__return_false', 99);
    add_filter('wpseo_hreflang_links', '__return_empty_array', 99);

    /* ---------------------------------
     * Rank Math
     * --------------------------------- */
    add_filter('rank_math/frontend/canonical', '__return_false', 99);
    add_filter('rank_math/frontend/hreflang', '__return_false', 99);
    add_filter('rank_math/frontend/hreflang/links', '__return_empty_array', 99);

    /* ---------------------------------
     * AIOSEO
     * --------------------------------- */
    add_filter('aioseo_canonical_url', '__return_false', 99);
    add_filter('aioseo_hreflang_tags', '__return_empty_array', 99);
    remove_all_actions('aioseo_head');

    /* ---------------------------------
     * SEOPress
     * --------------------------------- */
    add_filter('seopress_canonical', '__return_false', 99);
    add_filter('seopress_hreflang_links', '__return_empty_array', 99);

    /* ---------------------------------
     * SureRank
     * --------------------------------- */
    remove_all_actions('surerank_print_meta');

}, 0);