<?php

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}
/**
 * REEID — SEO Sitemaps Compatibility (small, isolated)
 *
 * Purpose:
 * - Append REEID WC sitemap into RankMath sitemap_index.xml when RankMath is active.
 *
 * NOTE:
 * - We intentionally do NOT touch parse_request/query_vars anymore.
 * - Native resolver now skips sitemap endpoints, so RankMath routing stays intact.
 */



/**
 * RankMath: Append our REEID WC sitemap to RankMath index.
 * Filter: rank_math/sitemap/index
 */
add_filter( 'rank_math/sitemap/index', function ( $append ) {

    $loc = home_url( '/reeid-wc-product-sitemap.xml' );

    // Prevent duplicates.
    if ( is_string( $append ) && strpos( $append, 'reeid-wc-product-sitemap.xml' ) !== false ) {
        return $append;
    }

    $lastmod = gmdate( 'c' );

    $xml  = "\n\t<sitemap>\n";
    $xml .= "\t\t<loc>" . esc_url( $loc ) . "</loc>\n";
    $xml .= "\t\t<lastmod>" . esc_html( $lastmod ) . "</lastmod>\n";
    $xml .= "\t</sitemap>\n";

    return (string) $append . $xml;
}, 10, 1 );
