define_constants(); $this->load_dependencies(); $this->register_hooks(); } /** * Get the single instance of the class. * * @return GameEngine */ public static function instance() { if (is_null(self::$instance)) { self::$instance = new self(); } return self::$instance; } /** * Define all essential plugin constants. */ private function define_constants() { define('GAMEENGINE_VERSION', '1.4.2'); define('GAMEENGINE_PLUGIN_SLUG', 'gameengine'); define('GAMEENGINE_FILE', __FILE__); define('GAMEENGINE_BASENAME', plugin_basename(GAMEENGINE_FILE)); define('GAMEENGINE_PATH', wp_normalize_path(plugin_dir_path(GAMEENGINE_FILE))); define('GAMEENGINE_URL', plugin_dir_url(GAMEENGINE_FILE)); define('GAMEENGINE_INCLUDES', GAMEENGINE_PATH . 'includes/'); define('GAMEENGINE_ROOT_DIR_PATH', plugin_dir_path(GAMEENGINE_FILE)); } /** * Load the plugin's dependencies. */ private function load_dependencies() { if (file_exists(GAMEENGINE_PATH . 'vendor/autoload.php')) { require_once GAMEENGINE_PATH . 'vendor/autoload.php'; } if (file_exists(GAMEENGINE_PATH . 'vendor/prefixed/autoload.php')) { require_once GAMEENGINE_PATH . 'vendor/prefixed/autoload.php'; } if (file_exists(GAMEENGINE_INCLUDES . 'autoload.php')) { require_once GAMEENGINE_INCLUDES . 'autoload.php'; } if (file_exists(GAMEENGINE_INCLUDES . 'functions.php')) { require_once GAMEENGINE_INCLUDES . 'functions.php'; } } /** * Register the core WordPress hooks. */ private function register_hooks() { register_activation_hook(GAMEENGINE_FILE, array(__CLASS__, 'activate')); register_deactivation_hook(GAMEENGINE_FILE, array(__CLASS__, 'deactivate')); add_action('deactivated_plugin', array($this, 'handle_dependency_deactivation'), 10, 2); add_action('init', array('\GameEngine\Core\Installer', 'maybe_sync_schema'), 4); add_action('init', array('\GameEngine\Core\Installer', 'maybe_repair_blanked_point_types'), 5); add_action('init', array('\GameEngine\Core\Installer', 'maybe_drop_retired_tables'), 6); add_action('init', array('\GameEngine\Core\Installer', 'maybe_backfill_slugs'), 7); add_action('init', array($this, 'init_modules'), 10); } /** * Initialize Plugin Hooks and Classes. */ public function init_modules() { if (is_admin() && class_exists('\GameEngine\Admin\Setup')) { \GameEngine\Admin\Setup::init(); } if (class_exists('\GameEngine\Classes\TaxonomyManager')) { \GameEngine\Classes\TaxonomyManager::init(); } if (class_exists('\GameEngine\Assets')) { \GameEngine\Assets::init(); } if (class_exists('\GameEngine\API\Manager')) { \GameEngine\API\Manager::init(); } $services = array( '\GameEngine\Classes\Scheduler', '\GameEngine\Classes\Logger', '\GameEngine\Classes\AchievementsManager', '\GameEngine\Classes\LevelsManager', '\GameEngine\Classes\EmailManager', '\GameEngine\Shortcode', '\GameEngine\Classes\Triggers', '\GameEngine\Classes\BadgeManager', '\GameEngine\Classes\NotificationManager', '\GameEngine\Classes\BuyPointsManager', '\GameEngine\Classes\GiftClaimManager', '\GameEngine\Classes\GiftPointsProduct', '\GameEngine\Classes\SocialSharing', ); foreach ($services as $service) { if (class_exists($service)) { $service::init(); } } if (is_admin() && class_exists('\GameEngine\Admin')) { \GameEngine\Admin::init(); } $this->load_optional_modules(); do_action('gameengine_init'); } private function load_optional_modules() { $paths = array( 'addons/restrict-unlock/init.php', 'addons/progress-map/init.php', 'addons/restrict-content/init.php', // Only ever loaded here — the course-unlock gate registers nothing // otherwise. next-release lost this line; see the init.php docblock. 'addons/academy-lms/init.php', 'addons/rewards-store/init.php' ); foreach ($paths as $path) { $full_path = GAMEENGINE_INCLUDES . $path; if (file_exists($full_path)) { require_once $full_path; } } } public static function activate() { if (class_exists('\GameEngine\Core\Installer')) { (new \GameEngine\Core\Installer())->run(); } set_transient('gameengine_activation_redirect', true, 30); } public static function deactivate() { if (class_exists('\GameEngine\Core\Installer')) { (new \GameEngine\Core\Installer())->uninstall(); } } /** * Keep addon settings consistent when dependency plugins are deactivated. * * @param string $plugin Deactivated plugin basename. * @param bool $network_deactivating Whether the plugin is network deactivated. */ public function handle_dependency_deactivation($plugin, $network_deactivating) { $dependency_map = array( 'academy/academy.php' => 'academylms', 'tutor/tutor.php' => 'tutorlms', 'woocommerce/woocommerce.php' => 'woocommerce', 'storeengine/storeengine.php' => 'storeengine', ); if (! isset($dependency_map[$plugin])) { return; } $addon_slug = $dependency_map[$plugin]; $active_addons = get_option('gameengine_active_addons', array()); if (! in_array($addon_slug, $active_addons, true)) { return; } $active_addons = array_values(array_diff($active_addons, array($addon_slug))); update_option('gameengine_active_addons', $active_addons); if (class_exists('\GameEngine\Classes\TriggerRegistry')) { \GameEngine\Classes\TriggerRegistry::reset(); } } } if (! function_exists('gameengine')) { /** * Global accessor. */ function gameengine() { return GameEngine::instance(); } } GameEngine::instance();