true ) ); } AIMSLMS_Auto_Pages::create_pages(); AIMSLMS_Auto_Pages::restore_pages(); AIMSLMS_Auto_Pages::add_pages_to_menu(); // NOTE: this used to be wired via register_activation_hook( __FILE__, ... ) // inside class-aimslms-admin-certificate.php itself, which never actually // fires - WordPress only calls activation hooks registered against the // plugin's main bootstrap file. Calling it here is what actually runs it. if ( false === get_option( 'aimslms_cert_design' ) ) { AIMSLMS_Admin_Certificate::set_certificate_defaults(); } flush_rewrite_rules(); } /** * Create custom database tables. * * @return bool True if every required table exists after dbDelta() runs, false otherwise. */ private static function create_tables() { global $wpdb; $charset_collate = $wpdb->get_charset_collate(); // Section table. $table_sections = $wpdb->prefix . 'aimslms_course_sections'; $sql_sections = "CREATE TABLE $table_sections ( id bigint(20) NOT NULL AUTO_INCREMENT, course_id bigint(20) NOT NULL, title VARCHAR(255) NOT NULL, description LONGTEXT NULL, sort_order INT NOT NULL DEFAULT 0, created_at DATETIME DEFAULT NULL, PRIMARY KEY (id), KEY course_id (course_id) ) $charset_collate;"; // Lession table. $table_lessons = $wpdb->prefix . 'aimslms_course_lessons'; $sql_lessons = "CREATE TABLE $table_lessons ( id bigint UNSIGNED NOT NULL AUTO_INCREMENT, course_id bigint(20) NOT NULL, section_id bigint UNSIGNED NOT NULL, title VARCHAR(255) NOT NULL, slug VARCHAR(255) NOT NULL, content LONGTEXT NULL, upload_file TEXT NULL, duration VARCHAR(50) NULL, sort_order INT NOT NULL DEFAULT 0, created_at DATETIME DEFAULT NULL, PRIMARY KEY (id), KEY section_id (section_id) ) $charset_collate;"; // Enrollments table. $table_enrollments = $wpdb->prefix . 'aimslms_course_enrollments'; $sql_enrollments = "CREATE TABLE $table_enrollments ( id bigint(20) NOT NULL AUTO_INCREMENT, user_id bigint(20) NOT NULL, course_id bigint(20) NOT NULL, order_id bigint(20) NOT NULL, enrollment_date datetime NOT NULL, status varchar(20) DEFAULT 'active' NOT NULL, payment_type varchar(20) DEFAULT 'one_time' NOT NULL, transaction_id VARCHAR(255) NULL, expiry_date datetime NULL, PRIMARY KEY (id), KEY user_id (user_id), KEY course_id (course_id) ) $charset_collate;"; // Progress table. $table_progress = $wpdb->prefix . 'aimslms_course_progress'; $sql_progress = "CREATE TABLE $table_progress ( id bigint(20) NOT NULL AUTO_INCREMENT, user_id bigint(20) NOT NULL, lesson_id bigint(20) NOT NULL, course_id bigint(20) NOT NULL, video_timestamp int(11) DEFAULT 0 NOT NULL, completion_percentage int(3) DEFAULT 0 NOT NULL, completed tinyint(1) DEFAULT 0 NOT NULL, last_accessed datetime NOT NULL, PRIMARY KEY (id), KEY user_id (user_id), KEY lesson_id (lesson_id), KEY course_id (course_id), UNIQUE KEY user_lesson (user_id, lesson_id) ) $charset_collate;"; // Transactions table. $table_transactions = $wpdb->prefix . 'aimslms_course_payment'; $sql_transactions = "CREATE TABLE $table_transactions ( id bigint(20) NOT NULL AUTO_INCREMENT, user_id bigint(20) NOT NULL, course_id bigint(20) NOT NULL, order_id bigint(20) NOT NULL, amount decimal(10,2) NOT NULL, defult_course_price decimal(10,2) NOT NULL, currency varchar(3) DEFAULT 'USD' NOT NULL, payment_method varchar(50) NOT NULL, payment_gateway VARCHAR(50) NOT NULL, payment_brand VARCHAR(50) NULL, raw_response LONGTEXT NULL, transaction_id varchar(255) NOT NULL, paypal_order_id varchar(255) NULL, stripe_payment_intent_id varchar(255) NULL, razorpay_order_id varchar(255) NULL, status varchar(20) DEFAULT 'pending' NOT NULL, previous_status varchar(20) NULL, transaction_date datetime NOT NULL, PRIMARY KEY (id), KEY user_id (user_id), KEY course_id (course_id), KEY transaction_id (transaction_id) ) $charset_collate;"; // Certificates table. $table_certificates = $wpdb->prefix . 'aimslms_course_certificates'; $sql_certificates = "CREATE TABLE $table_certificates ( id bigint(20) NOT NULL AUTO_INCREMENT, user_id bigint(20) NOT NULL, course_id bigint(20) NOT NULL, certificate_id varchar(255) NOT NULL, issue_date datetime NOT NULL, file_path varchar(255) NOT NULL, PRIMARY KEY (id), KEY user_id (user_id), KEY course_id (course_id), KEY certificate_id (certificate_id) ) $charset_collate;"; // Order table. $table_orders = $wpdb->prefix . 'aimslms_course_orders'; $sql_orders = "CREATE TABLE $table_orders ( id bigint(20) NOT NULL AUTO_INCREMENT, user_id bigint(20) NOT NULL, course_id bigint(20) NOT NULL, order_total decimal(10,2) NOT NULL, defult_course_price decimal(10,2) NOT NULL, currency varchar(10) NOT NULL DEFAULT 'USD', payment_method varchar(50) NOT NULL, payment_method_title varchar(100) NULL, created_via varchar(50) DEFAULT 'plugin' NOT NULL, order_key varchar(100) NOT NULL, cart_hash varchar(100) NULL, prices_include_tax tinyint(1) DEFAULT 0 NOT NULL, billing_first_name varchar(100) NULL, billing_last_name varchar(100) NULL, billing_email varchar(100) NULL, order_status varchar(20) DEFAULT 'pending' NOT NULL, previous_status varchar(20) NULL, transaction_id varchar(255) NULL, customer_note LONGTEXT NOT NULL, created_at datetime NOT NULL, updated_at datetime NOT NULL, PRIMARY KEY (id), KEY user_id (user_id), KEY course_id (course_id), KEY order_key (order_key) ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql_sections ); dbDelta( $sql_lessons ); dbDelta( $sql_enrollments ); dbDelta( $sql_progress ); dbDelta( $sql_transactions ); dbDelta( $sql_certificates ); dbDelta( $sql_orders ); $required_tables = array( $table_sections, $table_lessons, $table_enrollments, $table_progress, $table_transactions, $table_certificates, $table_orders, ); foreach ( $required_tables as $table ) { // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching -- Verifying dbDelta() actually created the table; no WP API alternative. if ( $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table ) ) !== $table ) { return false; } } // Save database version. update_option( 'aimslms_db_version', AIMSLMS_VERSION ); return true; } }