<?php
/**
 * Plugin Name: ProQyz LMS
 * Plugin URI: https://proqyz.spacetree.org/
 * Description: A powerful plugin to create quizzes and courses, helping students prepare effectively for exams. Easily build, manage, and track quiz-based learning content to support student progress. Perfect for educators and institutions!
 * Version: 3.0.0.2
 * Author: Spacetree
 * Author URI: https://spacetree.org
 * Text Domain: spacetree
 * Domain Path: /i18n/languages/
 * Requires at least: 6.3
 * Requires PHP: 7.4
 * 
 *
 * @package Spacetree
 * @description [Plugin is only working with database version 3.0 spacetree]
 */

defined( 'ABSPATH' ) || exit;

if ( ! defined( 'ST_PLUGIN_FILE' ) ) {
	define( 'ST_PLUGIN_FILE', __FILE__ );
}

# config setups



// Include the main Spacetree class.
if ( ! class_exists( 'Spacetree', false ) ) {
	include_once dirname( ST_PLUGIN_FILE ) . '/includes/class-spacetree.php';
}

/**
 * Returns the main instance of ST.
 *
 * @since  1.0.1
 * @return Spacetree
 */
function ST() { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName.FunctionNameInvalid
	return Spacetree::instance();
}


# config setups
function spacetree_plugin_silence_warnings() {
    // Save current error reporting level
    $GLOBALS['spacetree_plugin_old_error_level'] = error_reporting();

    // Turn off warnings and notices (E_WARNING, E_NOTICE, E_DEPRECATED, etc.)
    error_reporting($GLOBALS['spacetree_plugin_old_error_level'] & ~E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_WARNING & ~E_USER_NOTICE);
}
add_action('plugins_loaded', 'spacetree_plugin_silence_warnings', 0);

// Restore original error reporting after plugin finishes loading
function spacetree_plugin_restore_warnings() {
    if (isset($GLOBALS['spacetree_plugin_old_error_level'])) {
        error_reporting($GLOBALS['spacetree_plugin_old_error_level']);
    }
}
register_shutdown_function('spacetree_plugin_restore_warnings');

// Global for backwards compatibility.
$GLOBALS['spacetree'] = ST();

/**
 * Activation hook - Flush rewrite rules
 */
function spacetree_activate() {
    // Ensure classes are loaded
    if (!class_exists('ST_Private')) {
        include_once dirname(ST_PLUGIN_FILE) . '/includes/class-st-private.php';
    }
    
    // Flush rewrite rules after activation
    ST_Private::flush_rewrite_rules();
}
register_activation_hook(__FILE__, 'spacetree_activate');

/**
 * Deactivation hook - Flush rewrite rules
 */
function spacetree_deactivate() {
    // Flush rewrite rules to remove custom rules
    flush_rewrite_rules();
}
register_deactivation_hook(__FILE__, 'spacetree_deactivate');