/* add_action('wp_footer', function () {
    echo '<div id="lp-geoapify-config" hidden data-endpoint="'
        . esc_url(admin_url('admin-ajax.php', 'relative'))
        . '"></div>';
}, 1);

add_action(
    'wp_ajax_lp_geoapify_address',
    'lp_geoapify_address_proxy'
);

add_action(
    'wp_ajax_nopriv_lp_geoapify_address',
    'lp_geoapify_address_proxy'
);

function lp_geoapify_address_proxy() {
    $key = '07c9f21f17d84efc81d91975afed4242';

    $raw = isset($_GET['text'])
        ? wp_unslash($_GET['text'])
        : '';

    if (!is_string($raw)) {
        wp_send_json(
            array('message' => 'Recherche invalide.'),
            400
        );
    }

    $text = trim(sanitize_text_field($raw));

    $length = function_exists('mb_strlen')
        ? mb_strlen($text)
        : strlen($text);

    if ($length < 3 || $length > 200) {
        wp_send_json(
            array(
                'message' => 'Saisissez entre 3 et 200 caractères.'
            ),
            400
        );
    }

    // Limite indicative : 60 appels par minute et par IP.
    // L’IP peut être partagée derrière un proxy.
    $ip = isset($_SERVER['REMOTE_ADDR'])
        ? (string) $_SERVER['REMOTE_ADDR']
        : 'unknown';

    $bucket = 'lp_geo_' . hash_hmac(
        'sha256',
        $ip . '|' . floor(time() / 60),
        wp_salt('auth')
    );

    $count = (int) get_transient($bucket);

    if ($count >= 60) {
        wp_send_json(
            array(
                'message' => 'Trop de recherches. Réessayez dans une minute.'
            ),
            429
        );
    }

    set_transient($bucket, $count + 1, 70);

    $url = add_query_arg(
        array(
            'text'   => $text,
            'filter' => 'countrycode:be',
            'lang'   => 'fr',
            'limit'  => 5,
            'format' => 'json',
            'apiKey' => $key,
        ),
        'https://api.geoapify.com/v1/geocode/autocomplete'
    );

    $response = wp_remote_get(
        $url,
        array(
            'timeout'     => 10,
            'redirection' => 0,
        )
    );

    if (
        is_wp_error($response)
        || wp_remote_retrieve_response_code($response) !== 200
    ) {
        wp_send_json(
            array(
                'message' => 'Service temporairement indisponible.'
            ),
            502
        );
    }

    $data = json_decode(
        wp_remote_retrieve_body($response),
        true
    );

    if (
        !is_array($data)
        || !isset($data['results'])
        || !is_array($data['results'])
    ) {
        wp_send_json(
            array('message' => 'Réponse invalide du service.'),
            502
        );
    }

    // Vérification supplémentaire : résultats belges uniquement.
    $results = array_values(
        array_filter(
            $data['results'],
            function ($address) {
                return is_array($address)
                    && isset($address['country_code'])
                    && strtolower($address['country_code']) === 'be';
            }
        )
    );

    wp_send_json(
        array('results' => $results)
    );
} */
<?xml version="1.0" encoding="UTF-8"?>  <sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
                          <sitemap>
                                        <loc>https://la-plateforme.be/fr/sitemap_post.xml</loc>
                        <lastmod>2026-10-20</lastmod>
          </sitemap>
              
                          <sitemap>
                                        <loc>https://la-plateforme.be/fr/sitemap_page.xml</loc>
                        <lastmod>2026-10-20</lastmod>
          </sitemap>
              
                          <sitemap>
                                        <loc>https://la-plateforme.be/fr/sitemap_agenda.xml</loc>
                        <lastmod>2026-10-20</lastmod>
          </sitemap>
              
                          <sitemap>
                                        <loc>https://la-plateforme.be/fr/sitemap_quizz.xml</loc>
                        <lastmod>2025-10-03</lastmod>
          </sitemap>
              
                          <sitemap>
                                        <loc>https://la-plateforme.be/fr/sitemap_ressources.xml</loc>
                        <lastmod>2026-10-20</lastmod>
          </sitemap>
              
    </sitemapindex>
