<?php
/**
 * Plugin Name:       GDPR Consent Plugin Controller
 * Plugin URI:        https://www.wpupgrader.com/gdpr-consent-wordpress-plugin/
 * Description:       Controls activating and deactivating plugins before WordPress is loaded based on the visitors consents.
 * Version:           %plugin_version%
 * Tested up to:      5.5
 * Requires at least: 4.5.1
 * Requires PHP:      5.6.2
 * Author:            WP Upgrader
 * Author URI:        https://www.wpupgrader.com/
 * Text Domain:       gdprc_consent_mu
 */

if (!\wp_installing() && !\wp_is_recovery_mode()) {
    $hasLiteInstalled = \file_exists(\trailingslashit(WP_PLUGIN_DIR).'gdpr-consent-lite/mu/plugin-controller.php');
    $hasProInstalled = \file_exists(\trailingslashit(WP_PLUGIN_DIR).'gdpr-consent/mu/plugin-controller.php');

    if ($hasLiteInstalled && !$hasProInstalled) {
        // Lite Only
        require_once \trailingslashit(WP_PLUGIN_DIR).'gdpr-consent-lite/mu/plugin-controller.php';
    }
    else if (!$hasLiteInstalled && $hasProInstalled) {
        // Pro Only
        require_once \trailingslashit(WP_PLUGIN_DIR).'gdpr-consent/mu/plugin-controller.php';
    }
    else if ($hasLiteInstalled && $hasProInstalled) {
        // Has both
        $activePluginController = \trailingslashit(WP_PLUGIN_DIR).'gdpr-consent-lite/mu/plugin-controller.php';
        $activePlugins = (array)\get_option('active_plugins', []);
        if (!empty($activePlugins)) {
            foreach ($activePlugins as $plugin) {
                // Check if PRO is active?
                if (\stripos($plugin, 'gdpr-consent/') > -1) {
                    $activePluginController = \trailingslashit(WP_PLUGIN_DIR).'gdpr-consent/mu/plugin-controller.php';
                    break;
                }
            }
        }
        require_once $activePluginController;
    }
    else if (!$hasLiteInstalled && !$hasProInstalled) {
        // Has nothing
        @\unlink(__FILE__); // clean up self
    }
}
