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 +90 -29 4.4.1 → 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() ) {
@@ -63,8 +59,13 @@
63 59 if ( ! LP_Settings::is_created_tb_mcp_api_keys() ) {
64 60 $this->create_table_mcp_api_keys();
65 61 }
66 62
63 + // Runtime migration for Webhooks table.
64 + if ( ! LP_Settings::is_created_tb_webhooks() ) {
65 + $this->create_table_webhooks();
66 + }
67 +
67 68 // Set roles and capabilities.
68 69 learn_press_add_user_roles();
69 70
70 71 ini_set( 'max_execution_time', LearnPress::$time_limit_default_of_sever );
@@ -83,16 +84,24 @@
83 84 return self::$instance;
84 85 }
85 86
86 87 /**
87 - * Do something after LP is activated.
88 + * Run installation tasks when LearnPress is activated.
88 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 + *
89 98 * @since 4.0.0
90 99 */
91 100 public function on_activate() {
92 101 $this->create_tables();
93 102
94 - if ( ! self::tables_install_done() ) {
103 + if ( ! $this->tables_install_done() ) {
95 104 return;
96 105 }
97 106
98 107 // Check if LP install before has db version
@@ -100,8 +109,16 @@
100 109 // Save database version of LP
101 110 update_option( LP_KEY_DB_VERSION, LearnPress::instance()->db_version );
102 111 }
103 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 +
104 121 // Create pages default.
105 122 self::create_pages();
106 123
107 124 // Set permalink is "Post name".
@@ -109,8 +126,14 @@
109 126 update_option( 'permalink_structure', '/%postname%/' );
110 127 // flush_rewrite_rules();
111 128 }
112 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 +
113 136 // Force option users_can_register to ON.
114 137 /*if ( ! get_option( 'users_can_register' ) ) {
115 138 update_option( 'users_can_register', 1 );
116 139 }*/
@@ -117,34 +140,40 @@
117 140 }
118 141
119 142 /**
120 143 * Create tables required for LP
144 + * @throws Exception
121 145 */
122 146 private function create_tables() {
123 - try {
124 - $tables = Config::instance()->get( 'tables-v4', 'table' );
125 - foreach ( $tables as $table ) {
126 - LP_Database::getInstance()->wpdb->query( $table );
127 - }
147 + $db = LP_Database::getInstance();
148 + $tables = Config::instance()->get( 'tables-v4', 'table' );
149 + foreach ( $tables as $table ) {
150 + $db->wpdb->query( $table );
128 151
129 - if ( ! LP_Settings::is_created_tb_thim_cache() ) {
130 - $this->create_table_thim_cache();
131 - }
152 + $db->check_execute_has_error();
153 + }
132 154
133 - if ( ! LP_Settings::is_created_tb_material_files() ) {
134 - $this->create_table_learnpress_files();
135 - }
155 + if ( ! LP_Settings::is_created_tb_thim_cache() ) {
156 + $this->create_table_thim_cache();
157 + }
136 158
137 - // Ensure MCP API keys table exists for activation/upgrade flows.
138 - // Keep this explicit guard in addition to tables-v4 config loading.
139 - if ( ! LP_Settings::is_created_tb_mcp_api_keys() ) {
140 - $this->create_table_mcp_api_keys();
141 - }
159 + if ( ! LP_Settings::is_created_tb_material_files() ) {
160 + $this->create_table_learnpress_files();
161 + }
142 162
143 - update_option( 'learn_press_check_tables', 'yes' );
144 - } catch ( Throwable $e ) {
145 - error_log( $e->getMessage() );
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();
146 167 }
168 +
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();
173 + }
174 +
175 + update_option( 'learn_press_check_tables', 'yes' );
147 176 }
148 177
149 178 /**
150 179 * Create table thim_cache
@@ -287,8 +316,41 @@
287 316 }
288 317 }
289 318
290 319 /**
320 + * Create table learnpress_webhooks.
321 + *
322 + * @since 4.3.3
323 + * @return void
324 + */
325 + public function create_table_webhooks() {
326 + global $wpdb;
327 +
328 + try {
329 + $collation = $wpdb->has_cap( 'collation' ) ? $wpdb->get_charset_collate() : 'ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci';
330 +
331 + $sql = "CREATE TABLE IF NOT EXISTS {$this->lp_db->tb_lp_webhooks} (
332 + webhook_id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
333 + user_id bigint(20) unsigned NOT NULL DEFAULT 0,
334 + status varchar(20) NOT NULL DEFAULT 'active',
335 + name varchar(200) NOT NULL DEFAULT '',
336 + delivery_url longtext NOT NULL,
337 + secret text NOT NULL,
338 + events longtext NOT NULL,
339 + created_at datetime NOT NULL,
340 + updated_at datetime NULL DEFAULT NULL,
341 + PRIMARY KEY (webhook_id),
342 + KEY user_id (user_id),
343 + KEY status (status)
344 + ) $collation";
345 +
346 + $wpdb->query( $sql );
347 + } catch ( Throwable $e ) {
348 + error_log( $e->getMessage() );
349 + }
350 + }
351 +
352 + /**
291 353 * Create default pages for LP
292 354 */
293 355 public static function create_pages() {
294 356 $pages = self::$_pages;
@@ -327,10 +389,8 @@
327 389 'post_name' => $page_slug,
328 390 );
329 391 LP_Helper::create_page( $data_create_page, "learn_press_{$page}_page_id" );
330 392 }
331 -
332 - flush_rewrite_rules();
333 393 } catch ( Exception $ex ) {
334 394 error_log( $ex->getMessage() );
335 395 }
336 396 }
@@ -340,11 +400,12 @@
340 400 *
341 401 * @return bool
342 402 */
343 403 public function tables_install_done(): bool {
344 - $install_done = get_option( 'learn_press_check_tables', 'no' );
345 - if ( is_multisite() && 'yes' !== $install_done ) {
404 + $install_done = 'yes' === get_option( 'learn_press_check_tables', 'no' );
405 + if ( ! $install_done ) {
346 406 $this->create_tables();
407 + $install_done = 'yes' === get_option( 'learn_press_check_tables', 'no' );
347 408 }
348 409
349 410 return $install_done;
350 411 }