<?php

/**
 * Plugin Name:       Acadlix
 * Description:       Acadlix is a feature-rich LMS plugin for WordPress, designed to transform your website into a complete e-learning platform. With Acadlix, you can effortlessly create and sell online courses, test series, quizzes, and assignments.
 * Version:           1.1.3
 * Requires at least: 6.8
 * Tested up to:      7.0.1
 * Requires PHP:      8.2
 * Author:            Team Acadlix
 * Author URI:        https://acadlix.com/
 * Text Domain:       acadlix
 * Domain Path:        /languages/Common/
 * License:           GPL v2 or later
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.html
 */


defined('ABSPATH') || exit();


if (!defined('ACADLIX_PLUGIN_FILE')) {
  define('ACADLIX_PLUGIN_FILE', __FILE__);
  include_once 'includes/acadlix-constant.php';
}
/**
 * Environment checks
 */
if (!function_exists('acadlix_environment_check')) {
  /**
   * Check if the environment meets the plugin requirements.
   *
   * @return bool True if the environment is suitable, false otherwise.
   */
  function acadlix_environment_check()
  {
    global $wp_version;

    // PHP check
    if (version_compare(PHP_VERSION, '8.2', '<')) {
      add_action('admin_notices', function () {
        ?>
        <div class="notice notice-error">
          <p><?php echo esc_html(sprintf(
            /* translators: 1: required PHP version 2: current PHP version */
            __('Acadlix requires PHP %1$s or higher. You are running PHP %2$s.', 'acadlix'),
            '8.2',
            PHP_VERSION
          )); ?></p>
        </div>
        <?php
      });

      // deactivate and prevent reactivation
      require_once ABSPATH . 'wp-admin/includes/plugin.php';
      deactivate_plugins(ACADLIX_PLUGIN_BASENAME);
      return false;
    }

    // WordPress check
    if (version_compare($wp_version, '6.8', '<')) {
      add_action('admin_notices', function () use ($wp_version) {
        ?>
        <div class="notice notice-error">
          <p><?php echo esc_html(sprintf(
            /* translators: 1: required WP version 2: current WP version */
            __('Acadlix requires WordPress %1$s or higher. You are running WordPress %2$s.', 'acadlix'),
            '6.8',
            $wp_version
          )); ?></p>
        </div>
        <?php
      });

      require_once ABSPATH . 'wp-admin/includes/plugin.php';
      deactivate_plugins(ACADLIX_PLUGIN_BASENAME);
      return false;
    }

    return true;
  }
}

// Run environment check early
if (!acadlix_environment_check()) {
  return; // stop loading the plugin completely
}

require_once ACADLIX_PLUGIN_DIR . '/bootstrap-activator.php';
Acadlix_Bootstrap_Activator::init_hooks();

if (function_exists('acadlix')) {
  return;
}

require_once ACADLIX_INCLUDES_PATH . '/AcadlixAbstract.php';
require_once ACADLIX_INCLUDES_PATH . '/Acadlix.php';
// acadlix();
add_action('plugins_loaded', function () {
  acadlix();
});
