PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9.1
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9.1
4.4.9.1 4.4.9 4.4.8 4.4.7 4.4.6 4.4.5 4.4.4 4.4.3 4.4.2 4.4.1 4.4.0 4.3.9.1 4.3.9 4.3.8 4.3.7 4.1.6.9 4.1.6.9.1 4.1.6.9.2 4.1.6.9.3 4.1.6.9.4 4.1.7 4.1.7.1 4.1.7.2 4.1.7.3 4.1.7.3.1 All 141 releases
← All changes | inc/class-lp-install.php +51 -34 4.4.5 → 4.4.9.1 View file →
@@ -35,12 +35,8 @@
35 35 );
36 36
37 37 protected function __construct() {
38 38 $this->lp_db = LP_Database::getInstance();
39 - // Only run on backend.
40 - if ( ! is_admin() ) {
41 - return;
42 - }
43 39 ini_set( 'max_execution_time', HOUR_IN_SECONDS );
44 40 // From LP v4.2.2 temporary run create table thim_cache.
45 41 // After a long time, will remove this code. Only run create table when activate plugin LP.
46 42 if ( ! LP_Settings::is_created_tb_thim_cache() ) {
@@ -88,16 +84,24 @@
88 84 return self::$instance;
89 85 }
90 86
91 87 /**
92 - * Do something after LP is activated.
88 + * Run installation tasks when LearnPress is activated.
93 89 *
90 + * 1. Create required database tables.
91 + * 2. Stop here if table creation failed.
92 + * 3. Save the current database version.
93 + * 4. Register LearnPress custom post types and taxonomies.
94 + * 5. Create default pages (courses, profile, checkout, become a teacher, etc.).
95 + * 6. Set permalink structure to post name if not configured.
96 + * 7. Soft flush rewrite rules so WordPress rebuilds them with LP CPTs and pages on the next request.
97 + *
94 98 * @since 4.0.0
95 99 */
96 100 public function on_activate() {
97 101 $this->create_tables();
98 102
99 - if ( ! self::tables_install_done() ) {
103 + if ( ! $this->tables_install_done() ) {
100 104 return;
101 105 }
102 106
103 107 // Check if LP install before has db version
@@ -105,8 +109,16 @@
105 109 // Save database version of LP
106 110 update_option( LP_KEY_DB_VERSION, LearnPress::instance()->db_version );
107 111 }
108 112
113 + // Register custom post type and taxonomies .
114 + include_once LP_PLUGIN_PATH . 'inc/custom-post-types/abstract.php';
115 + include_once LP_PLUGIN_PATH . 'inc/custom-post-types/course.php';
116 + include_once LP_PLUGIN_PATH . 'inc/custom-post-types/lesson.php';
117 + include_once LP_PLUGIN_PATH . 'inc/custom-post-types/quiz.php';
118 + include_once LP_PLUGIN_PATH . 'inc/custom-post-types/question.php';
119 + include_once LP_PLUGIN_PATH . 'inc/custom-post-types/order.php';
120 +
109 121 // Create pages default.
110 122 self::create_pages();
111 123
112 124 // Set permalink is "Post name".
@@ -114,8 +126,14 @@
114 126 update_option( 'permalink_structure', '/%postname%/' );
115 127 // flush_rewrite_rules();
116 128 }
117 129
130 + // Set roles and capabilities.
131 + learn_press_add_user_roles();
132 +
133 + // Rebuilds them with LP CPTs and pages on next request.
134 + flush_rewrite_rules();
135 +
118 136 // Force option users_can_register to ON.
119 137 /*if ( ! get_option( 'users_can_register' ) ) {
120 138 update_option( 'users_can_register', 1 );
121 139 }*/
@@ -122,40 +140,40 @@
122 140 }
123 141
124 142 /**
125 143 * Create tables required for LP
144 + * @throws Exception
126 145 */
127 146 private function create_tables() {
128 - try {
129 - $tables = Config::instance()->get( 'tables-v4', 'table' );
130 - foreach ( $tables as $table ) {
131 - LP_Database::getInstance()->wpdb->query( $table );
132 - }
147 + $db = LP_Database::getInstance();
148 + $tables = Config::instance()->get( 'tables-v4', 'table' );
149 + foreach ( $tables as $table ) {
150 + $db->wpdb->query( $table );
133 151
134 - if ( ! LP_Settings::is_created_tb_thim_cache() ) {
135 - $this->create_table_thim_cache();
136 - }
152 + $db->check_execute_has_error();
153 + }
137 154
138 - if ( ! LP_Settings::is_created_tb_material_files() ) {
139 - $this->create_table_learnpress_files();
140 - }
155 + if ( ! LP_Settings::is_created_tb_thim_cache() ) {
156 + $this->create_table_thim_cache();
157 + }
141 158
142 - // Ensure MCP API keys table exists for activation/upgrade flows.
143 - // Keep this explicit guard in addition to tables-v4 config loading.
144 - if ( ! LP_Settings::is_created_tb_mcp_api_keys() ) {
145 - $this->create_table_mcp_api_keys();
146 - }
159 + if ( ! LP_Settings::is_created_tb_material_files() ) {
160 + $this->create_table_learnpress_files();
161 + }
147 162
148 - // Ensure Webhooks table exists for activation/upgrade flows.
149 - // Keep this explicit guard in addition to tables-v4 config loading.
150 - if ( ! LP_Settings::is_created_tb_webhooks() ) {
151 - $this->create_table_webhooks();
152 - }
163 + // Ensure MCP API keys table exists for activation/upgrade flows.
164 + // Keep this explicit guard in addition to tables-v4 config loading.
165 + if ( ! LP_Settings::is_created_tb_mcp_api_keys() ) {
166 + $this->create_table_mcp_api_keys();
167 + }
153 168
154 - update_option( 'learn_press_check_tables', 'yes' );
155 - } catch ( Throwable $e ) {
156 - error_log( $e->getMessage() );
169 + // Ensure Webhooks table exists for activation/upgrade flows.
170 + // Keep this explicit guard in addition to tables-v4 config loading.
171 + if ( ! LP_Settings::is_created_tb_webhooks() ) {
172 + $this->create_table_webhooks();
157 173 }
174 +
175 + update_option( 'learn_press_check_tables', 'yes' );
158 176 }
159 177
160 178 /**
161 179 * Create table thim_cache
@@ -371,10 +389,8 @@
371 389 'post_name' => $page_slug,
372 390 );
373 391 LP_Helper::create_page( $data_create_page, "learn_press_{$page}_page_id" );
374 392 }
375 -
376 - flush_rewrite_rules();
377 393 } catch ( Exception $ex ) {
378 394 error_log( $ex->getMessage() );
379 395 }
380 396 }
@@ -384,11 +400,12 @@
384 400 *
385 401 * @return bool
386 402 */
387 403 public function tables_install_done(): bool {
388 - $install_done = get_option( 'learn_press_check_tables', 'no' );
389 - if ( is_multisite() && 'yes' !== $install_done ) {
404 + $install_done = 'yes' === get_option( 'learn_press_check_tables', 'no' );
405 + if ( ! $install_done ) {
390 406 $this->create_tables();
407 + $install_done = 'yes' === get_option( 'learn_press_check_tables', 'no' );
391 408 }
392 409
393 410 return $install_done;
394 411 }