PluginProbe
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses / 4.4.8
LearnPress – WordPress LMS Plugin for Create and Sell Online Courses v4.4.8
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 4.2.0 All 139 releases
← All changes | inc/class-lp-settings.php +283 -116 4.1.7.14.4.8 View file →
@@ -24,13 +24,8 @@
24 24
25 25 /**
26 26 * @var bool
27 27 */
28 - protected $_load_data = false;
29 -
30 - /**
31 - * @var bool
32 - */
33 28 protected static $_instance = null;
34 29
35 30 /**
36 31 * Constructor.
@@ -35,20 +30,22 @@
35 30 /**
36 31 * Constructor.
37 32 *
38 33 * @param array|mixed $data
39 - * @param string $prefix
34 + * @param string $prefix
40 35 */
41 36 protected function __construct( $data = false, $prefix = 'learn_press_' ) {
37 + try {
38 + $this->_prefix = $prefix;
42 39
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;
40 + if ( false === $data ) {
41 + $this->_load_options();
42 + } else {
43 + settype( $data, 'array' );
44 + $this->_options = $data;
45 + }
46 + } catch ( Throwable $e ) {
47 + error_log( __METHOD__ . ': ' . $e->getMessage() );
51 48 }
52 49 }
53 50
54 51 /**
@@ -63,17 +60,27 @@
63 60 return new LP_Settings( $options, $prefix );
64 61 }
65 62
66 63 /**
67 - * Load options from database.
64 + * Load all options.
68 65 *
69 - * @param bool $force
66 + * @throws Exception
67 + * @version 1.0.2
68 + * @since 3.0.0
70 69 */
71 - protected function _load_options( $force = false ) {
70 + protected function _load_options() {
71 + // Check cache exists
72 + $lp_settings_cache = new LP_Settings_Cache( true );
73 + $lp_options = $lp_settings_cache->get_lp_settings();
74 + if ( false !== $lp_options ) {
75 + $this->_options = LP_Helper::json_decode( $lp_options, true );
76 +
77 + return;
78 + }
79 +
72 80 global $wpdb;
73 81 $query = $wpdb->prepare(
74 - "
75 - SELECT option_name, option_value
82 + "SELECT option_name, option_value
76 83 FROM {$wpdb->options}
77 84 WHERE option_name LIKE %s",
78 85 $wpdb->esc_like( $this->_prefix ) . '%'
79 86 );
@@ -78,13 +85,15 @@
78 85 $wpdb->esc_like( $this->_prefix ) . '%'
79 86 );
80 87
81 88 $options = $wpdb->get_results( $query );
82 -
83 - if ( $options ) {
89 + if ( ! empty( $options ) ) {
84 90 foreach ( $options as $option ) {
85 91 $this->_options[ $option->option_name ] = LP_Helper::maybe_unserialize( $option->option_value );
86 92 }
93 +
94 + // Set cache
95 + $lp_settings_cache->set_lp_settings( json_encode( $this->_options ) );
87 96 }
88 97 }
89 98
90 99 /**
@@ -131,9 +140,9 @@
131 140 /**
132 141 * Get option recurse separated by DOT
133 142 *
134 143 * @param string $var
135 - * @param mixed $default
144 + * @param mixed $default
136 145 *
137 146 * @return mixed
138 147 */
139 148 public function get( string $var = '', $default = null ) {
@@ -196,25 +205,19 @@
196 205 update_option( $this->_prefix . $key, $value );
197 206 // $this->refresh();
198 207 }
199 208
200 - public function refresh() {
201 - if ( $this->_load_data ) {
202 - // $this->_load_options( true );
203 - }
204 -
205 - return $this;
206 - }
207 -
208 209 /**
209 210 * Update option with default prefix is learn_press_
210 211 *
211 212 * @param string $name
212 - * @param mixed $value
213 + * @param mixed $value
213 214 * @param string $prefix
214 215 */
215 216 public static function update_option( $name, $value, $prefix = 'learn_press_' ) {
216 217 update_option( "{$prefix}{$name}", $value );
218 + $lp_settings_cache = new LP_Settings_Cache( true );
219 + $lp_settings_cache->clean_lp_settings();
217 220 }
218 221
219 222 /**
220 223 * Get option with default prefix is learn_press_
@@ -219,9 +222,9 @@
219 222 /**
220 223 * Get option with default prefix is learn_press_
221 224 *
222 225 * @param string $name
223 - * @param mixed $default
226 + * @param mixed $default
224 227 *
225 228 * @return mixed
226 229 * @since 3.2.8
227 230 * @editor tungnx
@@ -226,9 +229,15 @@
226 229 * @since 3.2.8
227 230 * @editor tungnx
228 231 */
229 232 public static function get_option( string $name = '', $default = false ) {
230 - return get_option( "learn_press_{$name}", $default );
233 + $key = "learn_press_{$name}";
234 + $options = self::instance()->_options;
235 + if ( isset( $options[ $key ] ) ) {
236 + return $options[ $key ];
237 + }
238 +
239 + return get_option( $key, $default );
231 240 }
232 241
233 242 public function get_int( $key ) {
234 243 $value = $this->get( $key );
@@ -247,91 +256,8 @@
247 256 return self::$_instance;
248 257 }
249 258
250 259 /**
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 260 * Get settings endpoints for checkout page.
335 261 *
336 262 * @return array
337 263 * @since 3.0.0
@@ -399,8 +325,57 @@
399 325 return apply_filters( 'learn-press/endpoints/profile', $endpoints );
400 326 }
401 327
402 328 /**
329 + * Get settings endpoints for course builder page.
330 + *
331 + * @return array
332 + * @since 4.3.0
333 + */
334 + public function get_course_builder_endpoints() {
335 + $endpoints = LP_Object_Cache::get( 'course-builder', 'learn-press-endpoints' );
336 +
337 + if ( false === $endpoints ) {
338 + $endpoints = array();
339 + $defaults = [
340 + 'courses' => 'courses',
341 + 'courses-edit' => 'edit',
342 + 'courses-curriculum' => 'curriculum',
343 + 'courses-settings' => 'settings',
344 + 'lessons' => 'lessons',
345 + 'lessons-edit' => 'edit',
346 + 'lessons-settings' => 'settings',
347 + 'quizzes' => 'quizzes',
348 + 'quizzes-edit' => 'edit',
349 + 'quizzes-questions' => 'questions',
350 + 'quizzes-settings' => 'settings',
351 + 'questions' => 'questions',
352 + 'questions-edit' => 'edit',
353 + 'questions-settings' => 'settings',
354 + ];
355 +
356 + $settings = array();
357 +
358 + if ( $settings ) {
359 + foreach ( $settings as $k => $v ) {
360 + $k = preg_replace( '!_!', '-', $k );
361 + $endpoints[ $k ] = $v;
362 + }
363 + }
364 +
365 + foreach ( $defaults as $k => $v ) {
366 + if ( empty( $endpoints[ $k ] ) ) {
367 + $endpoints[ $k ] = $v;
368 + }
369 + }
370 +
371 + LP_Object_Cache::set( 'course-builder', $endpoints, 'learn-press-endpoints' );
372 + }
373 +
374 + return apply_filters( 'learn-press/endpoints/course-builder', $endpoints );
375 + }
376 +
377 + /**
403 378 * Check setting enable option "Auto start"
404 379 *
405 380 * @return bool
406 381 */
@@ -405,8 +380,200 @@
405 380 * @return bool
406 381 */
407 382 public static function is_auto_start_course(): bool {
408 383 return 'yes' === self::get_option( 'auto_enroll', 'yes' );
384 + }
385 +
386 + /**
387 + * Check table learnpress_course is created
388 + *
389 + * @return bool
390 + */
391 + public static function is_created_tb_courses(): bool {
392 + $lp_db = LP_Database::getInstance();
393 + return $lp_db->check_table_exists( $lp_db->tb_lp_courses );
394 + }
395 +
396 + /**
397 + * Check table thim_cache is created
398 + *
399 + * @return bool
400 + */
401 + public static function is_created_tb_thim_cache(): bool {
402 + return get_option( 'thim_cache_tb_created' ) === 'yes';
403 + }
404 +
405 + /**
406 + * Check enable option "Store data in $_SESSION PHP" instead of $_COOKIE
407 + *
408 + * @return bool
409 + */
410 + public static function is_store_ip_customer(): bool {
411 + return self::get_option( 'store_ip_customer_session', 'no' ) === 'yes';
412 + }
413 +
414 + /**
415 + * Check table learnpress_files is created
416 + * @return boolean
417 + */
418 + public static function is_created_tb_material_files(): bool {
419 + $lp_db = LP_Database::getInstance();
420 + return $lp_db->check_table_exists( $lp_db->tb_lp_files );
421 + }
422 +
423 + /**
424 + * Check table learnpress_mcp_api_keys is created.
425 + *
426 + * @return bool
427 + */
428 + public static function is_created_tb_mcp_api_keys(): bool {
429 + $lp_db = LP_Database::getInstance();
430 + return $lp_db->check_table_exists( $lp_db->tb_lp_mcp_api_keys );
431 + }
432 +
433 + /**
434 + * Check table learnpress_webhooks is created.
435 + *
436 + * @return bool
437 + */
438 + public static function is_created_tb_webhooks(): bool {
439 + $lp_db = LP_Database::getInstance();
440 + return $lp_db->check_table_exists( $lp_db->tb_lp_webhooks );
441 + }
442 +
443 + public static function lp_material_file_types(): array {
444 + return array(
445 + 'txt' => 'text/plain',
446 + 'doc,docx' => 'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
447 + 'odt' => 'application/vnd.oasis.opendocument.text',
448 + 'rtf' => 'application/rtf',
449 + 'pdf' => 'application/pdf',
450 + 'jpg,jpeg' => 'image/jpeg',
451 + 'png' => 'image/png',
452 + 'gif' => 'image/gif',
453 + 'bmp' => 'image/bmp',
454 + // 'svg' => 'image/svg+xml',
455 + 'mp3' => 'audio/mpeg',
456 + 'wav' => 'audio/wav',
457 + 'flac' => 'audio/flac',
458 + 'aac' => 'audio/aac',
459 + 'wma' => 'audio/x-ms-wma',
460 + 'mp4' => 'video/mp4',
461 + 'avi' => 'video/avi',
462 + 'mkv' => 'video/x-matroska',
463 + 'mov' => 'video/quicktime',
464 + 'wmv' => 'video/x-ms-wmv',
465 + 'xls,xlsx' => 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
466 + 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
467 + 'csv' => 'text/csv',
468 + 'numbers' => 'application/vnd.apple.numbers',
469 + 'tsv' => 'text/tab-separated-values',
470 + 'zip' => 'application/zip,application/octet-stream,application/x-zip-compressed,multipart/x-zip',
471 + );
472 + }
473 +
474 + /**
475 + * Check theme support load courses ajax
476 + *
477 + * @return bool
478 + * @since 4.2.3.3
479 + * @version 1.0.0
480 + */
481 + public static function theme_no_support_load_courses_ajax(): bool {
482 + $theme_no_load_ajax = apply_filters(
483 + 'lp/page/courses/themes/no_load_ajax',
484 + [
485 + 'Coaching',
486 + 'Course Builder',
487 + 'eLearningWP',
488 + 'Ivy School',
489 + 'StarKid',
490 + 'Academy LMS',
491 + 'Coaching Child',
492 + 'Course Builder Child',
493 + 'eLearningWP Child',
494 + 'Ivy School Child',
495 + 'StarKid Child',
496 + 'Academy LMS Child',
497 + ]
498 + );
499 + $theme_current = wp_get_theme()->get( 'Name' );
500 +
501 + return in_array( $theme_current, $theme_no_load_ajax );
502 + }
503 +
504 + /**
505 + * Check theme support load courses ajax
506 + *
507 + * @return string
508 + * @version 1.0.0
509 + * @since 4.2.3.3
510 + */
511 + public static function get_permalink_single_course(): string {
512 + $course_slug_default = 'courses';
513 + try {
514 + $course_slug = self::get_option( 'course_base', 'courses' );
515 + if ( empty( $course_slug ) ) {
516 + $course_slug = $course_slug_default;
517 + }
518 + $course_slug = preg_replace( '!^/!', '', $course_slug );
519 + } catch ( Throwable $e ) {
520 + $course_slug = $course_slug_default;
521 + }
522 +
523 + return $course_slug;
524 + }
525 +
526 + /**
527 + * Check theme support load courses ajax
528 + *
529 + * @return array
530 + * @version 1.0.0
531 + * @since 4.2.3.3
532 + */
533 + public static function get_course_items_slug(): array {
534 + /**
535 + * Set rule item course.
536 + *
537 + * Use urldecode to convert an encoded string to normal.
538 + * This fixed the issue with custom slug of lesson/quiz in some languages
539 + * Eg: урока
540 + */
541 + $lesson_slug = urldecode( sanitize_title_with_dashes( self::get_option( 'lesson_slug', 'lessons' ) ) );
542 + $quiz_slug = urldecode( sanitize_title_with_dashes( self::get_option( 'quiz_slug', 'quizzes' ) ) );
543 +
544 + return apply_filters(
545 + 'learn-press/course-item-slugs/for-rewrite-rules',
546 + array(
547 + LP_LESSON_CPT => $lesson_slug,
548 + LP_QUIZ_CPT => $quiz_slug,
549 + )
550 + );
551 + }
552 +
553 + /**
554 + * Return url lp-ajax.php
555 + *
556 + * @return string
557 + * @since 4.2.7.6
558 + * @version 1.0.1
559 + */
560 + public static function url_handle_lp_ajax(): string {
561 + return home_url( 'lp-ajax-handle' );
562 + }
563 +
564 + /**
565 + * Check if instructor access to WordPress admin screens is restricted
566 + *
567 + * When enabled, instructors are redirected away from most wp-admin pages
568 + * and continue their work in Course Builder instead. Administrators keep full access.
569 + *
570 + * @return bool True if instructor access is restricted, false otherwise
571 + * @since 4.3.6
572 + * @version 1.0.0
573 + */
574 + public static function is_hide_instructor_access_admin_screen(): bool {
575 + return self::get_option( 'hide_instructor_access_admin_screen', 'no' ) === 'yes';
409 576 }
410 577 }
411 578
412 579 LP_Settings::instance();