<?php
/**
 * DESATIVAR PLUGINS CONFLITANTES
 * 
 * Este arquivo deve ser colocado em: wp-content/mu-plugins/
 * Ele automaticamente desativa plugins que conflitam com o tema
 * 
 * INSTRUÇÕES:
 * 1. Crie a pasta: wp-content/mu-plugins/ (se não existir)
 * 2. Cole este arquivo lá
 * 3. Acesse o site - plugins conflitantes serão desativados
 */

if (!defined('ABSPATH')) exit;

add_action('admin_init', function() {
    // Lista de plugins conflitantes
    $conflicting_plugins = array(
        'hot-custom-logic/hot-custom-logic.php',
        'hot-custom-logic.php',
        'hot-performance-mu.php',
        'hot-core-functions.php'
    );
    
    $active_plugins = get_option('active_plugins', array());
    $deactivated = array();
    
    foreach ($conflicting_plugins as $plugin) {
        $key = array_search($plugin, $active_plugins);
        if ($key !== false) {
            unset($active_plugins[$key]);
            $deactivated[] = $plugin;
        }
    }
    
    if (!empty($deactivated)) {
        update_option('active_plugins', $active_plugins);
        
        // Mensaje para admin
        add_action('admin_notices', function() use ($deactivated) {
            ?>
            <div class="notice notice-warning is-dismissible">
                <p><strong>⚠️ Conflicting Plugins Deactivated:</strong></p>
                <ul>
                    <?php foreach ($deactivated as $plugin) : ?>
                        <li><?php echo esc_html($plugin); ?></li>
                    <?php endforeach; ?>
                </ul>
                <p>These plugins conflicted with the <strong>Grupos Telegram Hot</strong> theme and were automatically deactivated.</p>
                <p>The theme already includes all the functionalities de these plugins.</p>
            </div>
            <?php
        });
    }
});

// Remove plugins antigos da pasta plugins se existirem
add_action('admin_init', function() {
    $plugin_files_to_remove = array(
        WP_PLUGIN_DIR . '/hot-custom-logic.php',
        WP_PLUGIN_DIR . '/hot-performance-mu.php'
    );
    
    foreach ($plugin_files_to_remove as $file) {
        if (file_exists($file)) {
            @unlink($file);
        }
    }
});
