Application
Source
File: classes/Application.php
final class Application { public $version = '1.0.0'; protected static $_instance = null; public $path; public $url; public $basename; //Module public $core; public $admin; private $post_type; private $resources; private $ajax; private $localize_script; private $metabox; private $course_builder; private $course_curriculum; private $template; private $permalinks; private $lecture; private $discussion; private $dashboard; public $shortcode; private $user; private $withdrawal; private $course_gate; private $wishlist; private $quiz; //Factory /** * Course Factory Instance * * @var Course */ public $course_factory = null; //Integration /** * WooCommerce integration class instance * * @var WooCommerce */ public $wc; /** * Easy Digital Download Integration class instance. * * @var EDD */ public $edd; public static function instance() { if ( is_null( self::$_instance ) ) { self::$_instance = new self(); } return self::$_instance; } public function __construct() { $this->define_tables(); $this->includes(); $this->init_hooks(); add_action( 'admin_init', [ $this, 'flush_rewrite_rules' ] ); } /** * Register custom tables within $wpdb object. */ private function define_tables() { global $wpdb; // List of tables without prefixes. $tables = [ 'dozent_completes' => 'dozent_completes', 'dozent_instructor_courses' => 'dozent_instructor_courses', 'dozent_reviews' => 'dozent_reviews', 'dozent_enrols' => 'dozent_enrols', 'dozent_withdrawal' => 'dozent_withdrawal', 'dozent_earnings' => 'dozent_earnings', 'dozent_quiz_questions' => 'dozent_quiz_questions', 'dozent_quiz_question_options' => 'dozent_quiz_question_options', 'dozent_quiz_attempts' => 'dozent_quiz_attempts', 'dozent_quiz_answers' => 'dozent_quiz_answers', ]; foreach ( $tables as $name => $table ) { $wpdb->$name = $wpdb->prefix . $table; $wpdb->tables[] = $table; } } public function includes() { include_once dirname( DOZENT_FILE ) . '/includes/define_constants.php'; include_once DOZENT_ABSPATH . 'includes/core-functions.php'; include_once DOZENT_ABSPATH . 'includes/form-functions.php'; include_once DOZENT_ABSPATH . 'includes/conditional-functions.php'; include_once DOZENT_ABSPATH . 'includes/template-functions.php'; include_once DOZENT_ABSPATH . 'includes/user-functions.php'; include_once DOZENT_ABSPATH . 'includes/course-functions.php'; include_once DOZENT_ABSPATH . 'includes/quiz-functions.php'; include_once DOZENT_ABSPATH . 'includes/earning-functions.php'; include_once DOZENT_ABSPATH . 'includes/integration-functions.php'; include_once DOZENT_ABSPATH . 'includes/template-hooks.php'; } public function init_hooks() { add_action( 'init', [ $this, 'init' ], 0 ); add_action( 'init', [ $this, 'register_hooks' ], 99 ); register_activation_hook( DOZENT_FILE, [ $this, 'install' ] ); } public function init() { $this->path = DOZENT_ABSPATH; $this->url = DOZENT_URL; $this->basename = DOZENT_BASENAME; do_action( 'dozent_init_before' ); $this->load_plugin_textdomain(); $this->flash_message_support(); $this->core = new Core(); $this->admin = new Admin(); $this->post_type = new PostType(); $this->resources = new Resources(); $this->ajax = new Ajax(); $this->localize_script = new LocalizeScript(); $this->metabox = new MetaBox(); $this->course_builder = new CourseBuilder(); $this->course_curriculum = CourseCurriculum::instance(); $this->template = new Template(); $this->permalinks = new Permalinks(); $this->lecture = new Lecture(); $this->discussion = new Discussion(); $this->dashboard = new Dashboard(); $this->shortcode = new ShortCode(); $this->user = new User(); $this->withdrawal = new Withdrawal(); $this->course_gate = new CourseGate(); $this->wishlist = new Wishlist(); $this->quiz = new Quiz(); //Factory $this->course_factory = new Course(); //Integration $this->wc = new WooCommerce(); $this->edd = new EDD(); do_action( 'dozent_init_after' ); } /** * Register hooks for DozentLMS * * @since DozentLMS 1.0.0 */ public function register_hooks() { $dozent_action = dozent_input_text( 'dozent_action' ); if ( $dozent_action ) { do_action( $dozent_action ); } } public function load_plugin_textdomain() { load_plugin_textdomain( 'dozent', false, basename( dirname( DOZENT_FILE ) ) . '/languages' ); } public function flash_message_support() { $cookie = $_COOKIE; $flash_message = dozent_array_get( 'dozent_flash.message', $cookie ); if ( ! empty( $flash_message ) ) { if ( is_admin() ) { add_action( 'admin_notices', [ $this, 'admin_show_flash_message' ] ); } setcookie( 'dozent_flash[message]' ); setcookie( 'dozent_flash[type]' ); setcookie( 'dozent_flash[view_count]' ); } } public function admin_show_flash_message() { dozent_flash_message(); } public function install() { $version = get_option( 'dozent_version' ); do_action( 'dozent_plugin_before_activate', $version ); //Save Option if ( ! $version ) { //Install necessary things for the Dozent Install::instance(); //Rewrite Flush update_option( 'required_rewrite_flush', dozent_time() ); } do_action( 'dozent_plugin_after_activate', $version ); //Updated the current Dozent Plugin version. update_option( 'dozent_version', DOZENT_VERSION ); } /** * Rewrite flush to server with new URL base * Usage case: change courses, lectures, quiz, assignments and others permalink base * * @since DozentLMS 1.0.0 */ public function flush_rewrite_rules() { $is_required_flush = get_option( 'required_rewrite_flush' ); if ( $is_required_flush ) { delete_option( 'required_rewrite_flush' ); flush_rewrite_rules(); } } }
Methods
- __construct
- admin_show_flash_message
- define_tables — Register custom tables within $wpdb object.
- flash_message_support
- flush_rewrite_rules — Rewrite flush to server with new URL base Usage case: change courses, lectures, quiz, assignments and others permalink base
- includes
- init
- init_hooks
- install
- instance
- load_plugin_textdomain
- register_hooks — Register hooks for DozentLMS