<?php/** * Plugin Name: Pasta Fresca OpenAI Ads & Crawlers * Description: Enables explicit OpenAI crawler policy and consent-aware ChatGPT Ads Measurement Pixel events. * Version: 1.0.2 * Requires at least: 6.5 * Requires PHP: 8.1 * Author: Pasta Fresca Web Team * * @package PastaFrescaOpenAIAds */defined('ABSPATH') || exit;const PASTA_FRESCA_OPENAI_ADS_OPTION = 'pasta_fresca_openai_ads_options';function pasta_fresca_openai_ads_robots_text(): string{    $sitemap = home_url('/wp-sitemap.xml');    return "User-agent: OAI-AdsBot\n"        . "Allow: /\n\n"        . "User-agent: OAI-SearchBot\n"        . "Allow: /\n\n"        . "User-agent: GPTBot\n"        . "Allow: /\n\n"        . "User-agent: *\n"        . "Allow: /\n\n"        . "Sitemap: " . esc_url_raw($sitemap) . "\n";}/**
 * Keep the public crawler policy explicit and independent from training access. * GPTBot is allowed; Search and Ads crawlers are allowed. */function pasta_fresca_openai_ads_robots(string $output, bool $public): string{    if (!$public) {        return $output;    }

    return pasta_fresca_openai_ads_robots_text();}add_filter('robots_txt', 'pasta_fresca_openai_ads_robots', 99, 2);/** * Hostinger can serve a static robots.txt before WordPress runs. Keep that * file aligned with the same policy when the document root is writable. */function pasta_fresca_openai_ads_ensure_static_robots(): void{    if (!current_user_can('manage_options')) {        return;    }    $content = pasta_fresca_openai_ads_robots_text();    $content_path = trailingslashit(WP_CONTENT_DIR) . 'pasta-fresca-openai-robots.txt';    if ((!is_file($content_path) || hash_file('sha256', $content_path) !== hash('sha256', $content)) && is_writable(WP_CONTENT_DIR)) {        $content_temp = $content_path . '.tmp-' . wp_generate_password(8, false, false);        if (file_put_contents($content_temp, $content, LOCK_EX) !== false) {            @rename($content_temp, $content_path);        }    }

    // Override a host-level/static robots.txt when .htaccess is writable.    require_once ABSPATH . 'wp-admin/includes/file.php';    require_once ABSPATH . 'wp-admin/includes/misc.php';    $home_path = get_home_path();    $htaccess = trailingslashit($home_path) . '.htaccess';    if (is_file($content_path) && is_writable($htaccess)) {        $uploads = wp_upload_dir();        $backup_dir = trailingslashit($uploads['basedir']) . 'pasta-fresca-robots-backups';        if (empty($uploads['error']) && is_file($htaccess) && wp_mkdir_p($backup_dir)) {            $backup = trailingslashit($backup_dir) . 'htaccess-' . gmdate('Ymd-His') . '.txt';            if (!is_file($backup)) @copy($htaccess, $backup);        }        insert_with_markers($htaccess, 'Pasta Fresca OpenAI Robots', array(            'RewriteRule ^robots\\.txt$ wp-content/pasta-fresca-openai-robots.'))}}<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="https://pastafrescavietnam.com/wp-sitemap-index.xsl" ?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><sitemap><loc>https://pastafrescavietnam.com/wp-sitemap-posts-post-1.xml</loc></sitemap><sitemap><loc>https://pastafrescavietnam.com/wp-sitemap-posts-page-1.xml</loc></sitemap><sitemap><loc>https://pastafrescavietnam.com/wp-sitemap-posts-pf_dish-1.xml</loc></sitemap><sitemap><loc>https://pastafrescavietnam.com/wp-sitemap-posts-pf_location-1.xml</loc></sitemap><sitemap><loc>https://pastafrescavietnam.com/wp-sitemap-posts-pf_job-1.xml</loc></sitemap><sitemap><loc>https://pastafrescavietnam.com/wp-sitemap-taxonomies-category-1.xml</loc></sitemap><sitemap><loc>https://pastafrescavietnam.com/wp-sitemap-users-1.xml</loc></sitemap></sitemapindex>
