<?php
/*
 * Plugin Name:       Flexy Consent
 * Plugin URI:        https://flexyconsent.com
 * Description:       Enhance compliance with a robust, lightweight CMP solution FlexyConsent-easy GDPR consent management for WordPress sites.
 * Version:           1.1.2.3
 * Requires at least: 4.0
 * Requires PHP:      5.6
 * Author:            flexyconsent
 * Author URI:        https://flexyconsent.com
 * License:           GPL v2 or later
 * License URL:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       flexyconsent
 */

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

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

global $flexyconsent_plugin_dir_url;
$flexyconsent_plugin_dir_url = plugin_dir_url(__FILE__);
global $flexyconsent_plugin_dir_path;
$flexyconsent_plugin_dir_path = plugin_dir_path(__FILE__);

load_plugin_textdomain('flexyconsent', false, dirname(plugin_basename(__FILE__)) . '/languages/');

include($flexyconsent_plugin_dir_path . 'inc.php');

/**
 * Activate the plugin.
 */
function flexyconsent_activate()
{
    $mu_plugin_dir = WP_CONTENT_DIR . '/mu-plugins';
    if (!is_dir($mu_plugin_dir)) {
        require_once ABSPATH . 'wp-admin/includes/file.php';
        wp_mkdir_p($mu_plugin_dir);
    }

    $mu_plugin_file = $mu_plugin_dir . '/flexyconsent-loader.php';
    if (!file_exists($mu_plugin_file)) {
        $loader_code = "<?php
        require_once WP_PLUGIN_DIR . '/flexyconsent/flexyconsent.php';
        ?>";
        file_put_contents($mu_plugin_file, $loader_code);
    }
}

register_activation_hook(__FILE__, 'flexyconsent_activate');

function flexyconsent_deactivated()
{
    $mu_plugin_dir = WP_CONTENT_DIR . '/mu-plugins';
    $mu_plugin_file = $mu_plugin_dir . '/flexyconsent-loader.php';

    if (file_exists($mu_plugin_file)) {
        unlink($mu_plugin_file);
    }
}
register_deactivation_hook(__FILE__, 'flexyconsent_deactivated');

include($flexyconsent_plugin_dir_path . 'inc/initPages.php');
// include ($flexyconsent_plugin_dir_path.'inc/helpers.php');
include($flexyconsent_plugin_dir_path . 'pages/startPage.php');

global $flexyconsent_pages;
foreach ($flexyconsent_pages as $flexyconsent_page) {
    include($flexyconsent_plugin_dir_path . 'pages/' . $flexyconsent_page['id'] . '.php');
}
