PluginProbe
Academy LMS / 3.8.5
Academy LMS v3.8.5
3.8.5 3.8.3 3.8.4 3.8.2 3.8.1 3.8.0 3.7.4 trunk 3.0.0 3.0.1 3.0.2 3.1.0 3.1.1 3.1.2 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.10 3.3.11 3.3.2 3.3.3 3.3.4 All 43 releases
academy / academy.php

academy.php in Academy LMS 3.8.5, at academy.php

169 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: Academy LMS
4 * Plugin URI: http://academylms.net
5 * Description: Share your knowledge by launching an online course.
6 * Version: 3.8.5
7 * Author: Academy LMS
8 * Author URI: http://academylms.net
9 * License: GPL-3.0+
10 * License URI: http://www.gnu.org/licenses/gpl-3.0.txt
11 * Text Domain: academy
12 * Domain Path: /languages/
13 */
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit;
17 }
18
19 final class Academy {
20
21 private function __construct() {
22 $this->define_constants();
23 $this->set_global_settings();
24 $this->load_dependency();
25 register_activation_hook( __FILE__, [ $this, 'activate' ] );
26 register_deactivation_hook( __FILE__, [ $this, 'deactivate' ] );
27 add_action( 'activated_plugin', array( $this, 'activated_redirect' ), 10, 2 );
28 add_action( 'plugins_loaded', [ $this, 'load_action_scheduler' ], -10 );
29 add_action( 'plugins_loaded', [ $this, 'on_plugins_loaded' ] );
30 add_action( 'academy_loaded', [ $this, 'init_plugin' ] );
31
32 }
33
34 public static function init() {
35 static $instance = false;
36
37 if ( ! $instance ) {
38 $instance = new self();
39 }
40
41 return $instance;
42 }
43 public function define_constants() {
44 /**
45 * Defines CONSTANTS for Whole plugins.
46 */
47 define( 'ACADEMY_VERSION', '3.8.5' );
48 define( 'ACADEMY_DB_VERSION', '1.1' );
49 define( 'ACADEMY_SETTINGS_NAME', 'academy_settings' );
50 define( 'ACADEMY_ADDONS_SETTINGS_NAME', 'academy_addons' );
51 define( 'ACADEMY_PLUGIN_FILE', __FILE__ );
52 define( 'ACADEMY_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
53 define( 'ACADEMY_PLUGIN_SLUG', 'academy' );
54 define( 'ACADEMY_PLUGIN_ROOT_URI', plugins_url( '/', __FILE__ ) );
55 define( 'ACADEMY_ROOT_DIR_PATH', plugin_dir_path( __FILE__ ) );
56 define( 'ACADEMY_INCLUDES_DIR_PATH', ACADEMY_ROOT_DIR_PATH . 'includes/' );
57 define( 'ACADEMY_ASSETS_DIR_PATH', ACADEMY_ROOT_DIR_PATH . 'assets/' );
58 define( 'ACADEMY_ADDONS_DIR_PATH', ACADEMY_ROOT_DIR_PATH . 'addons/' );
59 define( 'ACADEMY_BLOCK_TEMPLATES_DIR_PATH', ACADEMY_ROOT_DIR_PATH . 'templates/block-templates/' );
60 define( 'ACADEMY_ASSETS_URI', ACADEMY_PLUGIN_ROOT_URI . 'assets/' );
61 define( 'ACADEMY_TEMPLATE_DEBUG_MODE', false );
62 }
63
64 /**
65 * When WP has loaded all plugins, trigger the `academy_loaded` hook.
66 *
67 * This ensures `academy_loaded` is called only after all other plugins
68 * are loaded, to avoid issues caused by plugin directory naming changing
69 *
70 * @since 1.0.0
71 */
72 public function on_plugins_loaded() {
73 do_action( 'academy_loaded' );
74 }
75
76 /**
77 * Initialize the plugin
78 *
79 * @return void
80 */
81 public function init_plugin() {
82 // Init action.
83 do_action( 'academy_before_init' );
84 $this->load_global_css();
85 $this->dispatch_hooks();
86 $this->load_addons();
87 // Init action.
88 do_action( 'academy_init' );
89 }
90
91 public function dispatch_hooks() {
92 Academy\Database::init();
93 Academy\PermalinkRewrite::init();
94 Academy\API::init();
95 Academy\Ajax::init();
96 Academy\Post::init();
97 Academy\Assets::init();
98 Academy\Integration::init();
99 Academy\Migration::init();
100 Academy\Shortcode::init();
101 Academy\Customizer::init();
102 Academy\Miscellaneous::init();
103 if ( is_admin() ) {
104 Academy\Admin::init();
105 }
106 Academy\Frontend::init();
107 }
108
109 public function load_global_css() {
110 Academy\Classes\GlobalCss::init();
111 }
112
113 public function load_addons() {
114 Academy\Addons::init();
115 }
116
117 public function set_global_settings() {
118 $GLOBALS['academy_settings'] = json_decode( get_option( ACADEMY_SETTINGS_NAME, '{}' ) );
119 $GLOBALS['academy_addons'] = json_decode( get_option( ACADEMY_ADDONS_SETTINGS_NAME, '{}' ) );
120 }
121
122 public function load_action_scheduler() {
123 $action_scheduler = ACADEMY_ROOT_DIR_PATH . 'vendor/woocommerce/action-scheduler/action-scheduler.php';
124 if ( file_exists( $action_scheduler ) ) {
125 require_once $action_scheduler;
126 }
127 }
128
129 public function load_dependency() {
130 require_once ACADEMY_INCLUDES_DIR_PATH . 'autoload.php';
131 $prefixed_autoload = ACADEMY_ROOT_DIR_PATH . 'vendor/prefixed/autoload.php';
132 if ( file_exists( $prefixed_autoload ) ) {
133 require_once $prefixed_autoload;
134 }
135 require_once ACADEMY_INCLUDES_DIR_PATH . 'functions.php';
136 require_once ACADEMY_INCLUDES_DIR_PATH . 'hooks.php';
137 }
138
139 public function activate() {
140 Academy\Installer::init();
141 }
142
143 public function deactivate() {
144
145 }
146
147 public function activated_redirect( $plugin, $network_wide = null ) {
148 if ( ACADEMY_PLUGIN_BASENAME === $plugin ) {
149 if ( ! get_option( 'academy_has_redirect_to_setup_wizard' ) ) {
150 update_option( 'academy_has_redirect_to_setup_wizard', true, false );
151 wp_safe_redirect( admin_url( 'admin.php?page=academy-setup' ) );
152 exit;
153 }
154 }
155 }
156 }
157
158 /**
159 * Initializes the main plugin
160 *
161 * @return \Academy
162 */
163 function academy_start() {
164 return Academy::init();
165 }
166
167 // Plugin Start
168 academy_start();
169