PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.9
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.9
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 4.1.7.3.2 All 140 releases
← All changes | inc/class-lp-settings.php +312 -117 4.1.7.3.2 → 4.4.9 View file →
@@ -3,11 +3,13 @@
3 3 * Class LP_Settings
4 4 *
5 5 * @author ThimPress
6 6 * @package LearnPress/Classes
7 - * @version 1.0.1
7 + * @version 1.0.2
8 8 */
9 9
10 +use LearnPress\Databases\DataBase;
11 +
10 12 if ( ! defined( 'ABSPATH' ) ) {
11 13 exit;
12 14 }
13 15
@@ -24,13 +26,8 @@
24 26
25 27 /**
26 28 * @var bool
27 29 */
28 - protected $_load_data = false;
29 -
30 - /**
31 - * @var bool
32 - */
33 30 protected static $_instance = null;
34 31
35 32 /**
36 33 * Constructor.
@@ -35,20 +32,22 @@
35 32 /**
36 33 * Constructor.
37 34 *
38 35 * @param array|mixed $data
39 - * @param string $prefix
36 + * @param string $prefix
40 37 */
41 38 protected function __construct( $data = false, $prefix = 'learn_press_' ) {
39 + try {
40 + $this->_prefix = $prefix;
42 41
43 - $this->_prefix = $prefix;
44 -
45 - if ( false === $data ) {
46 - $this->_load_data = true;
47 - $this->_load_options();
48 - } else {
49 - settype( $data, 'array' );
50 - $this->_options = $data;
42 + if ( false === $data ) {
43 + $this->_load_options();
44 + } else {
45 + settype( $data, 'array' );
46 + $this->_options = $data;
47 + }
48 + } catch ( Throwable $e ) {
49 + error_log( __METHOD__ . ': ' . $e->getMessage() );
51 50 }
52 51 }
53 52
54 53 /**
@@ -63,17 +62,27 @@
63 62 return new LP_Settings( $options, $prefix );
64 63 }
65 64
66 65 /**
67 - * Load options from database.
66 + * Load all options.
68 67 *
69 - * @param bool $force
68 + * @throws Exception
69 + * @version 1.0.2
70 + * @since 3.0.0
70 71 */
71 - protected function _load_options( $force = false ) {
72 + protected function _load_options() {
73 + // Check cache exists
74 + $lp_settings_cache = new LP_Settings_Cache( true );
75 + $lp_options = $lp_settings_cache->get_lp_settings();
76 + if ( false !== $lp_options ) {
77 + $this->_options = $lp_options;
78 +
79 + return;
80 + }
81 +
72 82 global $wpdb;
73 83 $query = $wpdb->prepare(
74 - "
75 - SELECT option_name, option_value
84 + "SELECT option_name, option_value
76 85 FROM {$wpdb->options}
77 86 WHERE option_name LIKE %s",
78 87 $wpdb->esc_like( $this->_prefix ) . '%'
79 88 );
@@ -78,13 +87,15 @@
78 87 $wpdb->esc_like( $this->_prefix ) . '%'
79 88 );
80 89
81 90 $options = $wpdb->get_results( $query );
82 -
83 - if ( $options ) {
91 + if ( ! empty( $options ) ) {
84 92 foreach ( $options as $option ) {
85 93 $this->_options[ $option->option_name ] = LP_Helper::maybe_unserialize( $option->option_value );
86 94 }
95 +
96 + // Set cache
97 + $lp_settings_cache->set_lp_settings( json_encode( $this->_options ) );
87 98 }
88 99 }
89 100
90 101 /**
@@ -131,9 +142,9 @@
131 142 /**
132 143 * Get option recurse separated by DOT
133 144 *
134 145 * @param string $var
135 - * @param mixed $default
146 + * @param mixed $default
136 147 *
137 148 * @return mixed
138 149 */
139 150 public function get( string $var = '', $default = null ) {
@@ -196,25 +207,19 @@
196 207 update_option( $this->_prefix . $key, $value );
197 208 // $this->refresh();
198 209 }
199 210
200 - public function refresh() {
201 - if ( $this->_load_data ) {
202 - // $this->_load_options( true );
203 - }
204 -
205 - return $this;
206 - }
207 -
208 211 /**
209 212 * Update option with default prefix is learn_press_
210 213 *
211 214 * @param string $name
212 - * @param mixed $value
215 + * @param mixed $value
213 216 * @param string $prefix
214 217 */
215 218 public static function update_option( $name, $value, $prefix = 'learn_press_' ) {
216 219 update_option( "{$prefix}{$name}", $value );
220 + $lp_settings_cache = new LP_Settings_Cache( true );
221 + $lp_settings_cache->clean_lp_settings();
217 222 }
218 223
219 224 /**
220 225 * Get option with default prefix is learn_press_
@@ -219,9 +224,9 @@
219 224 /**
220 225 * Get option with default prefix is learn_press_
221 226 *
222 227 * @param string $name
223 - * @param mixed $default
228 + * @param mixed $default
224 229 *
225 230 * @return mixed
226 231 * @since 3.2.8
227 232 * @editor tungnx
@@ -226,11 +231,39 @@
226 231 * @since 3.2.8
227 232 * @editor tungnx
228 233 */
229 234 public static function get_option( string $name = '', $default = false ) {
230 - return get_option( "learn_press_{$name}", $default );
235 + $key = "learn_press_{$name}";
236 + $options = self::instance()->_options;
237 + if ( isset( $options[ $key ] ) ) {
238 + return $options[ $key ];
239 + }
240 +
241 + return get_option( $key, $default );
231 242 }
232 243
244 + /**
245 + * Get list of dismissed admin notices.
246 + *
247 + * @return array
248 + */
249 + public static function get_admin_notices_dismiss(): array {
250 + return get_option( 'lp_admin_notices_dismiss', [] );
251 + }
252 +
253 + /**
254 + * Check if an admin notice has been dismissed.
255 + *
256 + * @param string $key Notice key.
257 + *
258 + * @return bool
259 + */
260 + public static function is_admin_notice_dismissed( string $key ): bool {
261 + $dismissed = self::get_admin_notices_dismiss();
262 +
263 + return isset( $dismissed[ $key ] );
264 + }
265 +
233 266 public function get_int( $key ) {
234 267 $value = $this->get( $key );
235 268
236 269 return intval( $value );
@@ -247,91 +280,8 @@
247 280 return self::$_instance;
248 281 }
249 282
250 283 /**
251 - * Load all 'no' options from other plugins for caching purpose.
252 - *
253 - * @since 3.0.0
254 - * @deprecated 4.0.0
255 - * @editor tungnx
256 - * @reason not use
257 - */
258 - /*
259 - public static function load_site_options() {
260 - static $loaded = false;
261 -
262 - if ( $loaded ) {
263 - return;
264 - }
265 -
266 - $options = array(
267 - 'pmpro_updates',
268 - 'pmpro_stripe_billingaddress',
269 - 'pmpro_only_filter_pmpro_emails',
270 - 'pmpro_email_member_notification',
271 - 'pmpro_hideads',
272 - 'pmpro_hideadslevels',
273 - '_bbp_enable_group_forums',
274 - '_bbp_theme_package_id',
275 - '_bbp_root_slug',
276 - '_bbp_include_root',
277 - '_bbp_forum_slug',
278 - '_bbp_topic_slug',
279 - '_bbp_show_on_root',
280 - '_bbp_topic_archive_slug',
281 - '_bbp_reply_slug',
282 - '_bbp_topic_tag_slug',
283 - '_bbp_allow_topic_tags',
284 - '_bbp_use_autoembed',
285 - '_bbp_user_slug',
286 - '_bbp_view_slug',
287 - '_bbp_search_slug',
288 - '_bbp_reply_archive_slug',
289 - '_bbp_user_favs_slug',
290 - '_bbp_user_subs_slug',
291 - 'pmpro_nuclear_HTTPS',
292 - 'pmpro_gateway',
293 - 'pmpro_recaptcha',
294 - 'pmpro_use_ssl',
295 - '_bbp_enable_favorites',
296 - '_bbp_enable_subscriptions',
297 - '_bbp_allow_search',
298 - '_bbp_use_wp_editor',
299 - 'pmpro_hide_footer_link',
300 - 'learn-press-flush-rewrite-rules',
301 - '_lp_tabs_data',
302 - 'learn_press_permalinks',
303 - );
304 - global $wpdb;
305 -
306 - $format = array_fill( 0, sizeof( $options ), '%s' );
307 - $q = $wpdb->prepare( "
308 - SELECT option_name, option_value
309 - FROM $wpdb->options
310 - WHERE 1
311 - AND option_name IN(" . join( ',', $format ) . ")
312 - ", $options );
313 -
314 - $alloptions_db = $wpdb->get_results( $q, OBJECT_K );
315 - $notoptions = wp_cache_get( 'notoptions', 'options' );
316 -
317 - foreach ( $options as $o_name ) {
318 - if ( ! empty( $alloptions_db[ $o_name ] ) ) {
319 - $o_value = LP_Helper::maybe_unserialize( $alloptions_db[ $o_name ]->option_value );
320 - wp_cache_set( $o_name, $o_value, 'options' );
321 - } else {
322 - if ( ! is_array( $notoptions ) ) {
323 - $notoptions = array();
324 - }
325 - $notoptions[ $o_name ] = '';
326 - }
327 - }
328 -
329 - wp_cache_set( 'notoptions', $notoptions, 'options' );
330 - $loaded = true;
331 - }*/
332 -
333 - /**
334 284 * Get settings endpoints for checkout page.
335 285 *
336 286 * @return array
337 287 * @since 3.0.0
@@ -399,8 +349,57 @@
399 349 return apply_filters( 'learn-press/endpoints/profile', $endpoints );
400 350 }
401 351
402 352 /**
353 + * Get settings endpoints for course builder page.
354 + *
355 + * @return array
356 + * @since 4.3.0
357 + */
358 + public function get_course_builder_endpoints() {
359 + $endpoints = LP_Object_Cache::get( 'course-builder', 'learn-press-endpoints' );
360 +
361 + if ( false === $endpoints ) {
362 + $endpoints = array();
363 + $defaults = [
364 + 'courses' => 'courses',
365 + 'courses-edit' => 'edit',
366 + 'courses-curriculum' => 'curriculum',
367 + 'courses-settings' => 'settings',
368 + 'lessons' => 'lessons',
369 + 'lessons-edit' => 'edit',
370 + 'lessons-settings' => 'settings',
371 + 'quizzes' => 'quizzes',
372 + 'quizzes-edit' => 'edit',
373 + 'quizzes-questions' => 'questions',
374 + 'quizzes-settings' => 'settings',
375 + 'questions' => 'questions',
376 + 'questions-edit' => 'edit',
377 + 'questions-settings' => 'settings',
378 + ];
379 +
380 + $settings = array();
381 +
382 + if ( $settings ) {
383 + foreach ( $settings as $k => $v ) {
384 + $k = preg_replace( '!_!', '-', $k );
385 + $endpoints[ $k ] = $v;
386 + }
387 + }
388 +
389 + foreach ( $defaults as $k => $v ) {
390 + if ( empty( $endpoints[ $k ] ) ) {
391 + $endpoints[ $k ] = $v;
392 + }
393 + }
394 +
395 + LP_Object_Cache::set( 'course-builder', $endpoints, 'learn-press-endpoints' );
396 + }
397 +
398 + return apply_filters( 'learn-press/endpoints/course-builder', $endpoints );
399 + }
400 +
401 + /**
403 402 * Check setting enable option "Auto start"
404 403 *
405 404 * @return bool
406 405 */
@@ -405,8 +404,204 @@
405 404 * @return bool
406 405 */
407 406 public static function is_auto_start_course(): bool {
408 407 return 'yes' === self::get_option( 'auto_enroll', 'yes' );
408 + }
409 +
410 + /**
411 + * Check table learnpress_course is created
412 + *
413 + * @return bool
414 + * @throws Exception
415 + */
416 + public static function is_created_tb_courses(): bool {
417 + $lp_db = DataBase::getInstance();
418 + return $lp_db->check_table_exists( $lp_db->tb_lp_courses );
419 + }
420 +
421 + /**
422 + * Check table thim_cache is created
423 + *
424 + * @return bool
425 + */
426 + public static function is_created_tb_thim_cache(): bool {
427 + return get_option( 'thim_cache_tb_created' ) === 'yes';
428 + }
429 +
430 + /**
431 + * Check enable option "Store data in $_SESSION PHP" instead of $_COOKIE
432 + *
433 + * @return bool
434 + */
435 + public static function is_store_ip_customer(): bool {
436 + return self::get_option( 'store_ip_customer_session', 'no' ) === 'yes';
437 + }
438 +
439 + /**
440 + * Check table learnpress_files is created
441 + * @return boolean
442 + * @throws Exception
443 + */
444 + public static function is_created_tb_material_files(): bool {
445 + $lp_db = DataBase::getInstance();
446 + return $lp_db->check_table_exists( $lp_db->tb_lp_files );
447 + }
448 +
449 + /**
450 + * Check table learnpress_mcp_api_keys is created.
451 + *
452 + * @return bool
453 + * @throws Exception
454 + */
455 + public static function is_created_tb_mcp_api_keys(): bool {
456 + $lp_db = DataBase::getInstance();
457 + return $lp_db->check_table_exists( $lp_db->tb_lp_mcp_api_keys );
458 + }
459 +
460 + /**
461 + * Check table learnpress_webhooks is created.
462 + *
463 + * @return bool
464 + * @throws Exception
465 + */
466 + public static function is_created_tb_webhooks(): bool {
467 + $lp_db = DataBase::getInstance();
468 + return $lp_db->check_table_exists( $lp_db->tb_lp_webhooks );
469 + }
470 +
471 + public static function lp_material_file_types(): array {
472 + return array(
473 + 'txt' => 'text/plain',
474 + 'doc,docx' => 'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
475 + 'odt' => 'application/vnd.oasis.opendocument.text',
476 + 'rtf' => 'application/rtf',
477 + 'pdf' => 'application/pdf',
478 + 'jpg,jpeg' => 'image/jpeg',
479 + 'png' => 'image/png',
480 + 'gif' => 'image/gif',
481 + 'bmp' => 'image/bmp',
482 + // 'svg' => 'image/svg+xml',
483 + 'mp3' => 'audio/mpeg',
484 + 'wav' => 'audio/wav',
485 + 'flac' => 'audio/flac',
486 + 'aac' => 'audio/aac',
487 + 'wma' => 'audio/x-ms-wma',
488 + 'mp4' => 'video/mp4',
489 + 'avi' => 'video/avi',
490 + 'mkv' => 'video/x-matroska',
491 + 'mov' => 'video/quicktime',
492 + 'wmv' => 'video/x-ms-wmv',
493 + 'xls,xlsx' => 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
494 + 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
495 + 'csv' => 'text/csv',
496 + 'numbers' => 'application/vnd.apple.numbers',
497 + 'tsv' => 'text/tab-separated-values',
498 + 'zip' => 'application/zip,application/octet-stream,application/x-zip-compressed,multipart/x-zip',
499 + );
500 + }
501 +
502 + /**
503 + * Check theme support load courses ajax
504 + *
505 + * @return bool
506 + * @since 4.2.3.3
507 + * @version 1.0.0
508 + */
509 + public static function theme_no_support_load_courses_ajax(): bool {
510 + $theme_no_load_ajax = apply_filters(
511 + 'lp/page/courses/themes/no_load_ajax',
512 + [
513 + 'Coaching',
514 + 'Course Builder',
515 + 'eLearningWP',
516 + 'Ivy School',
517 + 'StarKid',
518 + 'Academy LMS',
519 + 'Coaching Child',
520 + 'Course Builder Child',
521 + 'eLearningWP Child',
522 + 'Ivy School Child',
523 + 'StarKid Child',
524 + 'Academy LMS Child',
525 + ]
526 + );
527 + $theme_current = wp_get_theme()->get( 'Name' );
528 +
529 + return in_array( $theme_current, $theme_no_load_ajax );
530 + }
531 +
532 + /**
533 + * Check theme support load courses ajax
534 + *
535 + * @return string
536 + * @version 1.0.0
537 + * @since 4.2.3.3
538 + */
539 + public static function get_permalink_single_course(): string {
540 + $course_slug_default = 'courses';
541 + try {
542 + $course_slug = self::get_option( 'course_base', 'courses' );
543 + if ( empty( $course_slug ) ) {
544 + $course_slug = $course_slug_default;
545 + }
546 + $course_slug = preg_replace( '!^/!', '', $course_slug );
547 + } catch ( Throwable $e ) {
548 + $course_slug = $course_slug_default;
549 + }
550 +
551 + return $course_slug;
552 + }
553 +
554 + /**
555 + * Check theme support load courses ajax
556 + *
557 + * @return array
558 + * @version 1.0.0
559 + * @since 4.2.3.3
560 + */
561 + public static function get_course_items_slug(): array {
562 + /**
563 + * Set rule item course.
564 + *
565 + * Use urldecode to convert an encoded string to normal.
566 + * This fixed the issue with custom slug of lesson/quiz in some languages
567 + * Eg: урока
568 + */
569 + $lesson_slug = urldecode( sanitize_title_with_dashes( self::get_option( 'lesson_slug', 'lessons' ) ) );
570 + $quiz_slug = urldecode( sanitize_title_with_dashes( self::get_option( 'quiz_slug', 'quizzes' ) ) );
571 +
572 + return apply_filters(
573 + 'learn-press/course-item-slugs/for-rewrite-rules',
574 + array(
575 + LP_LESSON_CPT => $lesson_slug,
576 + LP_QUIZ_CPT => $quiz_slug,
577 + )
578 + );
579 + }
580 +
581 + /**
582 + * Return url lp-ajax.php
583 + *
584 + * @return string
585 + * @since 4.2.7.6
586 + * @version 1.0.1
587 + */
588 + public static function url_handle_lp_ajax(): string {
589 + return home_url( 'lp-ajax-handle' );
590 + }
591 +
592 + /**
593 + * Check if instructor access to WordPress admin screens is restricted
594 + *
595 + * When enabled, instructors are redirected away from most wp-admin pages
596 + * and continue their work in Course Builder instead. Administrators keep full access.
597 + *
598 + * @return bool True if instructor access is restricted, false otherwise
599 + * @since 4.3.6
600 + * @version 1.0.0
601 + */
602 + public static function is_hide_instructor_access_admin_screen(): bool {
603 + return self::get_option( 'hide_instructor_access_admin_screen', 'no' ) === 'yes';
409 604 }
410 605 }
411 606
412 607 LP_Settings::instance();