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 +607 -569 4.3.8 → 4.4.9 View file →
@@ -1,569 +1,607 @@
1 -<?php
2 -/**
3 - * Class LP_Settings
4 - *
5 - * @author ThimPress
6 - * @package LearnPress/Classes
7 - * @version 1.0.1
8 - */
9 -
10 -if ( ! defined( 'ABSPATH' ) ) {
11 - exit;
12 -}
13 -
14 -class LP_Settings {
15 - /**
16 - * @var array
17 - */
18 - protected $_options = array();
19 -
20 - /**
21 - * @var string
22 - */
23 - protected $_prefix = '';
24 -
25 - /**
26 - * @var bool
27 - */
28 - protected static $_instance = null;
29 -
30 - /**
31 - * Constructor.
32 - *
33 - * @param array|mixed $data
34 - * @param string $prefix
35 - */
36 - protected function __construct( $data = false, $prefix = 'learn_press_' ) {
37 - try {
38 - $this->_prefix = $prefix;
39 -
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() );
48 - }
49 - }
50 -
51 - /**
52 - * @param string $group
53 - * @param string $prefix
54 - *
55 - * @return LP_Settings
56 - */
57 - public function get_group( $group, $prefix = '' ) {
58 - $options = ! empty( $this->_options[ $this->_prefix . $group ] ) ? $this->get( $this->_prefix . $group ) : array();
59 -
60 - return new LP_Settings( $options, $prefix );
61 - }
62 -
63 - /**
64 - * Load all options.
65 - *
66 - * @throws Exception
67 - * @version 1.0.2
68 - * @since 3.0.0
69 - */
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 -
80 - global $wpdb;
81 - $query = $wpdb->prepare(
82 - "SELECT option_name, option_value
83 - FROM {$wpdb->options}
84 - WHERE option_name LIKE %s",
85 - $wpdb->esc_like( $this->_prefix ) . '%'
86 - );
87 -
88 - $options = $wpdb->get_results( $query );
89 - if ( ! empty( $options ) ) {
90 - foreach ( $options as $option ) {
91 - $this->_options[ $option->option_name ] = LP_Helper::maybe_unserialize( $option->option_value );
92 - }
93 -
94 - // Set cache
95 - $lp_settings_cache->set_lp_settings( json_encode( $this->_options ) );
96 - }
97 - }
98 -
99 - /**
100 - * Set new value for a key
101 - *
102 - * @param $name
103 - * @param $value
104 - */
105 - public function set( $name, $value ) {
106 - if ( $this->_prefix && strpos( $name, $this->_prefix ) === false ) {
107 - $name = $this->_prefix . $name;
108 - }
109 - $this->_set_option( $this->_options, $name, $value );
110 - }
111 -
112 - private function _set_option( &$obj, $var, $value ) {
113 - $var = (array) explode( '.', $var );
114 - $current_var = array_shift( $var );
115 - if ( is_object( $obj ) ) {
116 - if ( isset( $obj->{$current_var} ) ) {
117 - $obj->{$current_var} = LP_Helper::maybe_unserialize( $obj->{$current_var} );
118 - if ( count( $var ) ) {
119 - $this->_set_option( $obj->{$current_var}, join( '.', $var ), $value );
120 - } else {
121 - $obj->{$current_var} = $value;
122 - }
123 - } else {
124 - $obj->{$current_var} = $value;
125 - }
126 - } else {
127 - if ( isset( $obj[ $current_var ] ) ) {
128 - $obj[ $current_var ] = LP_Helper::maybe_unserialize( $obj[ $current_var ] );
129 - if ( count( $var ) ) {
130 - $this->_set_option( $obj[ $current_var ], join( '.', $var ), $value );
131 - } else {
132 - $obj[ $current_var ] = $value;
133 - }
134 - } else {
135 - $obj[ $current_var ] = $value;
136 - }
137 - }
138 - }
139 -
140 - /**
141 - * Get option recurse separated by DOT
142 - *
143 - * @param string $var
144 - * @param mixed $default
145 - *
146 - * @return mixed
147 - */
148 - public function get( string $var = '', $default = null ) {
149 - if ( empty( $var ) ) {
150 - return $this->_options;
151 - }
152 -
153 - if ( $this->_prefix && strpos( $var, $this->_prefix ) === false ) {
154 - $var = $this->_prefix . $var;
155 - }
156 -
157 - $return = $this->_get_option( $this->_options, $var, $default );
158 -
159 - if ( $return == '' || is_null( $return ) ) {
160 - $return = $default;
161 - }
162 -
163 - return $return;
164 - }
165 -
166 - /**
167 - * @param $obj
168 - * @param $var
169 - * @param null $default
170 - *
171 - * @return null
172 - */
173 - public function _get_option( $obj, $var, $default = null ) {
174 - $var = (array) explode( '.', $var );
175 - $current_var = array_shift( $var );
176 - if ( is_object( $obj ) ) {
177 - if ( isset( $obj->{$current_var} ) ) {
178 - $obj->{$current_var} = LP_Helper::maybe_unserialize( $obj->{$current_var} );
179 - if ( count( $var ) ) {
180 - return $this->_get_option( $obj->{$current_var}, join( '.', $var ), $default );
181 - } else {
182 - return $obj->{$current_var};
183 - }
184 - } else {
185 - return $default;
186 - }
187 - } else {
188 - if ( isset( $obj[ $current_var ] ) ) {
189 - $obj[ $current_var ] = LP_Helper::maybe_unserialize( $obj[ $current_var ] );
190 - if ( count( $var ) ) {
191 - return $this->_get_option( $obj[ $current_var ], join( '.', $var ), $default );
192 - } else {
193 - return $obj[ $current_var ];
194 - }
195 - } else {
196 - return $default;
197 - }
198 - }
199 - }
200 -
201 - public function update( $key, $value = '' ) {
202 - if ( func_num_args() == 1 ) {
203 - $value = $this->get( $key );
204 - }
205 - update_option( $this->_prefix . $key, $value );
206 - // $this->refresh();
207 - }
208 -
209 - /**
210 - * Update option with default prefix is learn_press_
211 - *
212 - * @param string $name
213 - * @param mixed $value
214 - * @param string $prefix
215 - */
216 - public static function update_option( $name, $value, $prefix = 'learn_press_' ) {
217 - update_option( "{$prefix}{$name}", $value );
218 - $lp_settings_cache = new LP_Settings_Cache( true );
219 - $lp_settings_cache->clean_lp_settings();
220 - }
221 -
222 - /**
223 - * Get option with default prefix is learn_press_
224 - *
225 - * @param string $name
226 - * @param mixed $default
227 - *
228 - * @return mixed
229 - * @since 3.2.8
230 - * @editor tungnx
231 - */
232 - public static function get_option( string $name = '', $default = false ) {
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 );
240 - }
241 -
242 - public function get_int( $key ) {
243 - $value = $this->get( $key );
244 -
245 - return intval( $value );
246 - }
247 -
248 - /**
249 - * @return bool|LP_Settings
250 - */
251 - public static function instance() {
252 - if ( is_null( self::$_instance ) ) {
253 - self::$_instance = new self();
254 - }
255 -
256 - return self::$_instance;
257 - }
258 -
259 - /**
260 - * Get settings endpoints for checkout page.
261 - *
262 - * @return array
263 - * @since 3.0.0
264 - */
265 - public function get_checkout_endpoints() {
266 - $endpoints = LP_Object_Cache::get( 'checkout', 'learn-press-endpoints' );
267 -
268 - if ( false === $endpoints ) {
269 - $defaults = array(
270 - 'lp-order-received' => 'lp-order-received',
271 - );
272 -
273 - $endpoints = array();
274 - $settings = LP_Settings::instance()->get( 'checkout_endpoints' );
275 -
276 - if ( $settings ) {
277 - foreach ( $settings as $k => $v ) {
278 - $k = preg_replace( '!_!', '-', $k );
279 - $endpoints[ $k ] = $v;
280 - }
281 - }
282 -
283 - foreach ( $defaults as $k => $v ) {
284 - if ( empty( $endpoints[ $k ] ) ) {
285 - $endpoints[ $k ] = $v;
286 - }
287 - }
288 -
289 - LP_Object_Cache::set( 'checkout', $endpoints, 'learn-press-endpoints' );
290 - }
291 -
292 - return apply_filters( 'learn-press/endpoints/checkout', $endpoints );
293 - }
294 -
295 - /**
296 - * Get settings endpoints for profile page.
297 - *
298 - * @return array
299 - * @since 3.0.0
300 - */
301 - public function get_profile_endpoints() {
302 - $endpoints = LP_Object_Cache::get( 'profile', 'learn-press-endpoints' );
303 -
304 - if ( false === $endpoints ) {
305 - $defaults = array();
306 - $endpoints = array();
307 -
308 - $settings = LP_Settings::instance()->get( 'profile_endpoints' );
309 - if ( $settings ) {
310 - foreach ( $settings as $k => $v ) {
311 - $k = preg_replace( '!_!', '-', $k );
312 - $endpoints[ $k ] = $v;
313 - }
314 - }
315 -
316 - foreach ( $defaults as $k => $v ) {
317 - if ( empty( $endpoints[ $k ] ) ) {
318 - $endpoints[ $k ] = $v;
319 - }
320 - }
321 -
322 - LP_Object_Cache::set( 'profile', $endpoints, 'learn-press-endpoints' );
323 - }
324 -
325 - return apply_filters( 'learn-press/endpoints/profile', $endpoints );
326 - }
327 -
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 - /**
378 - * Check setting enable option "Auto start"
379 - *
380 - * @return bool
381 - */
382 - public static function is_auto_start_course(): bool {
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 - public static function lp_material_file_types(): array {
434 - return array(
435 - 'txt' => 'text/plain',
436 - 'doc,docx' => 'application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document',
437 - 'odt' => 'application/vnd.oasis.opendocument.text',
438 - 'rtf' => 'application/rtf',
439 - 'pdf' => 'application/pdf',
440 - 'jpg,jpeg' => 'image/jpeg',
441 - 'png' => 'image/png',
442 - 'gif' => 'image/gif',
443 - 'bmp' => 'image/bmp',
444 - // 'svg' => 'image/svg+xml',
445 - 'mp3' => 'audio/mpeg',
446 - 'wav' => 'audio/wav',
447 - 'flac' => 'audio/flac',
448 - 'aac' => 'audio/aac',
449 - 'wma' => 'audio/x-ms-wma',
450 - 'mp4' => 'video/mp4',
451 - 'avi' => 'video/avi',
452 - 'mkv' => 'video/x-matroska',
453 - 'mov' => 'video/quicktime',
454 - 'wmv' => 'video/x-ms-wmv',
455 - 'xls,xlsx' => 'application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
456 - 'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
457 - 'csv' => 'text/csv',
458 - 'numbers' => 'application/vnd.apple.numbers',
459 - 'tsv' => 'text/tab-separated-values',
460 - 'zip' => 'application/zip,application/octet-stream,application/x-zip-compressed,multipart/x-zip',
461 - );
462 - }
463 -
464 - /**
465 - * Check theme support load courses ajax
466 - *
467 - * @return bool
468 - * @since 4.2.3.3
469 - * @version 1.0.0
470 - */
471 - public static function theme_no_support_load_courses_ajax(): bool {
472 - $theme_no_load_ajax = apply_filters(
473 - 'lp/page/courses/themes/no_load_ajax',
474 - [
475 - 'Coaching',
476 - 'Course Builder',
477 - 'eLearningWP',
478 - 'Ivy School',
479 - 'StarKid',
480 - 'Academy LMS',
481 - 'Coaching Child',
482 - 'Course Builder Child',
483 - 'eLearningWP Child',
484 - 'Ivy School Child',
485 - 'StarKid Child',
486 - 'Academy LMS Child',
487 - ]
488 - );
489 - $theme_current = wp_get_theme()->get( 'Name' );
490 -
491 - return in_array( $theme_current, $theme_no_load_ajax );
492 - }
493 -
494 - /**
495 - * Check theme support load courses ajax
496 - *
497 - * @return string
498 - * @version 1.0.0
499 - * @since 4.2.3.3
500 - */
501 - public static function get_permalink_single_course(): string {
502 - $course_slug_default = 'courses';
503 - try {
504 - $course_slug = self::get_option( 'course_base', 'courses' );
505 - if ( empty( $course_slug ) ) {
506 - $course_slug = $course_slug_default;
507 - }
508 - $course_slug = preg_replace( '!^/!', '', $course_slug );
509 - } catch ( Throwable $e ) {
510 - $course_slug = $course_slug_default;
511 - }
512 -
513 - return $course_slug;
514 - }
515 -
516 - /**
517 - * Check theme support load courses ajax
518 - *
519 - * @return array
520 - * @version 1.0.0
521 - * @since 4.2.3.3
522 - */
523 - public static function get_course_items_slug(): array {
524 - /**
525 - * Set rule item course.
526 - *
527 - * Use urldecode to convert an encoded string to normal.
528 - * This fixed the issue with custom slug of lesson/quiz in some languages
529 - * Eg: урока
530 - */
531 - $lesson_slug = urldecode( sanitize_title_with_dashes( self::get_option( 'lesson_slug', 'lessons' ) ) );
532 - $quiz_slug = urldecode( sanitize_title_with_dashes( self::get_option( 'quiz_slug', 'quizzes' ) ) );
533 -
534 - return apply_filters(
535 - 'learn-press/course-item-slugs/for-rewrite-rules',
536 - array(
537 - LP_LESSON_CPT => $lesson_slug,
538 - LP_QUIZ_CPT => $quiz_slug,
539 - )
540 - );
541 - }
542 -
543 - /**
544 - * Return url lp-ajax.php
545 - *
546 - * @return string
547 - * @since 4.2.7.6
548 - * @version 1.0.1
549 - */
550 - public static function url_handle_lp_ajax(): string {
551 - return home_url( 'lp-ajax-handle' );
552 - }
553 -
554 - /**
555 - * Check if instructor access to WordPress admin screens is restricted
556 - *
557 - * When enabled, instructors are redirected away from most wp-admin pages
558 - * and continue their work in Course Builder instead. Administrators keep full access.
559 - *
560 - * @return bool True if instructor access is restricted, false otherwise
561 - * @since 4.3.6
562 - * @version 1.0.0
563 - */
564 - public static function is_hide_instructor_access_admin_screen(): bool {
565 - return self::get_option( 'hide_instructor_access_admin_screen', 'no' ) === 'yes';
566 - }
567 -}
568 -
569 -LP_Settings::instance();
1 +<?php
2 +/**
3 + * Class LP_Settings
4 + *
5 + * @author ThimPress
6 + * @package LearnPress/Classes
7 + * @version 1.0.2
8 + */
9 +
10 +use LearnPress\Databases\DataBase;
11 +
12 +if ( ! defined( 'ABSPATH' ) ) {
13 + exit;
14 +}
15 +
16 +class LP_Settings {
17 + /**
18 + * @var array
19 + */
20 + protected $_options = array();
21 +
22 + /**
23 + * @var string
24 + */
25 + protected $_prefix = '';
26 +
27 + /**
28 + * @var bool
29 + */
30 + protected static $_instance = null;
31 +
32 + /**
33 + * Constructor.
34 + *
35 + * @param array|mixed $data
36 + * @param string $prefix
37 + */
38 + protected function __construct( $data = false, $prefix = 'learn_press_' ) {
39 + try {
40 + $this->_prefix = $prefix;
41 +
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() );
50 + }
51 + }
52 +
53 + /**
54 + * @param string $group
55 + * @param string $prefix
56 + *
57 + * @return LP_Settings
58 + */
59 + public function get_group( $group, $prefix = '' ) {
60 + $options = ! empty( $this->_options[ $this->_prefix . $group ] ) ? $this->get( $this->_prefix . $group ) : array();
61 +
62 + return new LP_Settings( $options, $prefix );
63 + }
64 +
65 + /**
66 + * Load all options.
67 + *
68 + * @throws Exception
69 + * @version 1.0.2
70 + * @since 3.0.0
71 + */
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 +
82 + global $wpdb;
83 + $query = $wpdb->prepare(
84 + "SELECT option_name, option_value
85 + FROM {$wpdb->options}
86 + WHERE option_name LIKE %s",
87 + $wpdb->esc_like( $this->_prefix ) . '%'
88 + );
89 +
90 + $options = $wpdb->get_results( $query );
91 + if ( ! empty( $options ) ) {
92 + foreach ( $options as $option ) {
93 + $this->_options[ $option->option_name ] = LP_Helper::maybe_unserialize( $option->option_value );
94 + }
95 +
96 + // Set cache
97 + $lp_settings_cache->set_lp_settings( json_encode( $this->_options ) );
98 + }
99 + }
100 +
101 + /**
102 + * Set new value for a key
103 + *
104 + * @param $name
105 + * @param $value
106 + */
107 + public function set( $name, $value ) {
108 + if ( $this->_prefix && strpos( $name, $this->_prefix ) === false ) {
109 + $name = $this->_prefix . $name;
110 + }
111 + $this->_set_option( $this->_options, $name, $value );
112 + }
113 +
114 + private function _set_option( &$obj, $var, $value ) {
115 + $var = (array) explode( '.', $var );
116 + $current_var = array_shift( $var );
117 + if ( is_object( $obj ) ) {
118 + if ( isset( $obj->{$current_var} ) ) {
119 + $obj->{$current_var} = LP_Helper::maybe_unserialize( $obj->{$current_var} );
120 + if ( count( $var ) ) {
121 + $this->_set_option( $obj->{$current_var}, join( '.', $var ), $value );
122 + } else {
123 + $obj->{$current_var} = $value;
124 + }
125 + } else {
126 + $obj->{$current_var} = $value;
127 + }
128 + } else {
129 + if ( isset( $obj[ $current_var ] ) ) {
130 + $obj[ $current_var ] = LP_Helper::maybe_unserialize( $obj[ $current_var ] );
131 + if ( count( $var ) ) {
132 + $this->_set_option( $obj[ $current_var ], join( '.', $var ), $value );
133 + } else {
134 + $obj[ $current_var ] = $value;
135 + }
136 + } else {
137 + $obj[ $current_var ] = $value;
138 + }
139 + }
140 + }
141 +
142 + /**
143 + * Get option recurse separated by DOT
144 + *
145 + * @param string $var
146 + * @param mixed $default
147 + *
148 + * @return mixed
149 + */
150 + public function get( string $var = '', $default = null ) {
151 + if ( empty( $var ) ) {
152 + return $this->_options;
153 + }
154 +
155 + if ( $this->_prefix && strpos( $var, $this->_prefix ) === false ) {
156 + $var = $this->_prefix . $var;
157 + }
158 +
159 + $return = $this->_get_option( $this->_options, $var, $default );
160 +
161 + if ( $return == '' || is_null( $return ) ) {
162 + $return = $default;
163 + }
164 +
165 + return $return;
166 + }
167 +
168 + /**
169 + * @param $obj
170 + * @param $var
171 + * @param null $default
172 + *
173 + * @return null
174 + */
175 + public function _get_option( $obj, $var, $default = null ) {
176 + $var = (array) explode( '.', $var );
177 + $current_var = array_shift( $var );
178 + if ( is_object( $obj ) ) {
179 + if ( isset( $obj->{$current_var} ) ) {
180 + $obj->{$current_var} = LP_Helper::maybe_unserialize( $obj->{$current_var} );
181 + if ( count( $var ) ) {
182 + return $this->_get_option( $obj->{$current_var}, join( '.', $var ), $default );
183 + } else {
184 + return $obj->{$current_var};
185 + }
186 + } else {
187 + return $default;
188 + }
189 + } else {
190 + if ( isset( $obj[ $current_var ] ) ) {
191 + $obj[ $current_var ] = LP_Helper::maybe_unserialize( $obj[ $current_var ] );
192 + if ( count( $var ) ) {
193 + return $this->_get_option( $obj[ $current_var ], join( '.', $var ), $default );
194 + } else {
195 + return $obj[ $current_var ];
196 + }
197 + } else {
198 + return $default;
199 + }
200 + }
201 + }
202 +
203 + public function update( $key, $value = '' ) {
204 + if ( func_num_args() == 1 ) {
205 + $value = $this->get( $key );
206 + }
207 + update_option( $this->_prefix . $key, $value );
208 + // $this->refresh();
209 + }
210 +
211 + /**
212 + * Update option with default prefix is learn_press_
213 + *
214 + * @param string $name
215 + * @param mixed $value
216 + * @param string $prefix
217 + */
218 + public static function update_option( $name, $value, $prefix = 'learn_press_' ) {
219 + update_option( "{$prefix}{$name}", $value );
220 + $lp_settings_cache = new LP_Settings_Cache( true );
221 + $lp_settings_cache->clean_lp_settings();
222 + }
223 +
224 + /**
225 + * Get option with default prefix is learn_press_
226 + *
227 + * @param string $name
228 + * @param mixed $default
229 + *
230 + * @return mixed
231 + * @since 3.2.8
232 + * @editor tungnx
233 + */
234 + public static function get_option( string $name = '', $default = false ) {
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 );
242 + }
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 +
266 + public function get_int( $key ) {
267 + $value = $this->get( $key );
268 +
269 + return intval( $value );
270 + }
271 +
272 + /**
273 + * @return bool|LP_Settings
274 + */
275 + public static function instance() {
276 + if ( is_null( self::$_instance ) ) {
277 + self::$_instance = new self();
278 + }
279 +
280 + return self::$_instance;
281 + }
282 +
283 + /**
284 + * Get settings endpoints for checkout page.
285 + *
286 + * @return array
287 + * @since 3.0.0
288 + */
289 + public function get_checkout_endpoints() {
290 + $endpoints = LP_Object_Cache::get( 'checkout', 'learn-press-endpoints' );
291 +
292 + if ( false === $endpoints ) {
293 + $defaults = array(
294 + 'lp-order-received' => 'lp-order-received',
295 + );
296 +
297 + $endpoints = array();
298 + $settings = LP_Settings::instance()->get( 'checkout_endpoints' );
299 +
300 + if ( $settings ) {
301 + foreach ( $settings as $k => $v ) {
302 + $k = preg_replace( '!_!', '-', $k );
303 + $endpoints[ $k ] = $v;
304 + }
305 + }
306 +
307 + foreach ( $defaults as $k => $v ) {
308 + if ( empty( $endpoints[ $k ] ) ) {
309 + $endpoints[ $k ] = $v;
310 + }
311 + }
312 +
313 + LP_Object_Cache::set( 'checkout', $endpoints, 'learn-press-endpoints' );
314 + }
315 +
316 + return apply_filters( 'learn-press/endpoints/checkout', $endpoints );
317 + }
318 +
319 + /**
320 + * Get settings endpoints for profile page.
321 + *
322 + * @return array
323 + * @since 3.0.0
324 + */
325 + public function get_profile_endpoints() {
326 + $endpoints = LP_Object_Cache::get( 'profile', 'learn-press-endpoints' );
327 +
328 + if ( false === $endpoints ) {
329 + $defaults = array();
330 + $endpoints = array();
331 +
332 + $settings = LP_Settings::instance()->get( 'profile_endpoints' );
333 + if ( $settings ) {
334 + foreach ( $settings as $k => $v ) {
335 + $k = preg_replace( '!_!', '-', $k );
336 + $endpoints[ $k ] = $v;
337 + }
338 + }
339 +
340 + foreach ( $defaults as $k => $v ) {
341 + if ( empty( $endpoints[ $k ] ) ) {
342 + $endpoints[ $k ] = $v;
343 + }
344 + }
345 +
346 + LP_Object_Cache::set( 'profile', $endpoints, 'learn-press-endpoints' );
347 + }
348 +
349 + return apply_filters( 'learn-press/endpoints/profile', $endpoints );
350 + }
351 +
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 + /**
402 + * Check setting enable option "Auto start"
403 + *
404 + * @return bool
405 + */
406 + public static function is_auto_start_course(): bool {
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';
604 + }
605 +}
606 +
607 +LP_Settings::instance();