PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 2.1.2
Tutor LMS – eLearning and online course solution v2.1.2
3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / includes / tutor-general-functions.php
tutor / includes Last commit date
theme-compatibility 4 years ago tinymce_translate.php 4 years ago tutor-general-functions.php 3 years ago tutor-template-functions.php 3 years ago tutor-template-hook.php 4 years ago
tutor-general-functions.php
1028 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 /**
7 * Tutor input sanitization
8 */
9
10 if ( ! function_exists( 'tutor_sanitize_data' ) ) {
11 /**
12 * Escaping for Sanitize data.
13 *
14 * @since 1.9.13
15 *
16 * @param string $input.
17 * @param string $type.
18 * @return string|array|object
19 */
20 function tutor_sanitize_data( $input = null, $type = null ) {
21 $array = array();
22 $object = new stdClass();
23
24 if ( is_string( $input ) ) {
25
26 if ( 'textarea' == $type ) {
27 $input = sanitize_textarea_field( $input );
28 } elseif ( 'kses' == $type ) {
29 $input = wp_kses_post( $input );
30 } else {
31 $input = sanitize_text_field( $input );
32 }
33
34 return $input;
35
36 } elseif ( is_object( $input ) && count( get_object_vars( $input ) ) ) {
37
38 foreach ( $input as $key => $value ) {
39 if ( is_object( $value ) ) {
40 $object->$key = tutor_sanitize_data( $value );
41 } else {
42 $key = sanitize_text_field( $key );
43 $value = sanitize_text_field( $value );
44 $object->$key = $value;
45 }
46 }
47 return $object;
48 } elseif ( is_array( $input ) && count( $input ) ) {
49 foreach ( $input as $key => $value ) {
50 if ( is_array( $value ) ) {
51 $array[ $key ] = tutor_sanitize_data( $value );
52 } else {
53 $key = sanitize_text_field( $key );
54 $value = sanitize_text_field( $value );
55 $array[ $key ] = $value;
56 }
57 }
58
59 return $array;
60 }
61 }
62 }
63
64 if ( ! function_exists( 'tutor_placeholder_img_src' ) ) {
65 function tutor_placeholder_img_src() {
66 $src = tutor()->url . 'assets/images/placeholder.svg';
67 return apply_filters( 'tutor_placeholder_img_src', $src );
68 }
69 }
70
71 /**
72 * @return string
73 *
74 * Get course categories selecting UI
75 *
76 * @since v.1.3.4
77 */
78
79 if ( ! function_exists( 'tutor_course_categories_dropdown' ) ) {
80 function tutor_course_categories_dropdown( $post_ID = 0, $args = array() ) {
81
82 $default = array(
83 'classes' => '',
84 'name' => 'tax_input[course-category]',
85 'multiple' => true,
86 );
87
88 $args = apply_filters( 'tutor_course_categories_dropdown_args', array_merge( $default, $args ) );
89
90 $multiple_select = '';
91
92 if ( tutor_utils()->array_get( 'multiple', $args ) ) {
93 if ( isset( $args['name'] ) ) {
94 $args['name'] = $args['name'] . '[]';
95 }
96 $multiple_select = "multiple='multiple'";
97 }
98
99 extract( $args );
100
101 $classes = (array) $classes;
102 $classes = implode( ' ', $classes );
103
104 $categories = tutor_utils()->get_course_categories();
105
106 $output = '';
107 $output .= '<select name="' . $name . '" ' . $multiple_select . ' class="' . $classes . '" data-placeholder="' . __( 'Search Course Category. ex. Design, Development, Business', 'tutor' ) . '">';
108 $output .= '<option value="">' . __( 'Select a category', 'tutor' ) . '</option>';
109 $output .= _generate_categories_dropdown_option( $post_ID, $categories, $args );
110 $output .= '</select>';
111
112 return $output;
113 }
114 }
115
116 /**
117 * @return string
118 *
119 * Get course tags selecting UI
120 *
121 * @since v.1.3.4
122 */
123
124 if ( ! function_exists( 'tutor_course_tags_dropdown' ) ) {
125 function tutor_course_tags_dropdown( $post_ID = 0, $args = array() ) {
126
127 $default = array(
128 'classes' => '',
129 'name' => 'tax_input[course-tag]',
130 'multiple' => true,
131 );
132
133 $args = apply_filters( 'tutor_course_tags_dropdown_args', array_merge( $default, $args ) );
134
135 $multiple_select = '';
136
137 if ( tutor_utils()->array_get( 'multiple', $args ) ) {
138 if ( isset( $args['name'] ) ) {
139 $args['name'] = $args['name'] . '[]';
140 }
141 $multiple_select = "multiple='multiple'";
142 }
143
144 extract( $args );
145
146 $classes = (array) $classes;
147 $classes = implode( ' ', $classes );
148
149 $tags = tutor_utils()->get_course_tags();
150
151 $output = '';
152 $output .= '<select name=' . $name . ' ' . $multiple_select . ' class="' . $classes . '" data-placeholder="' . __( 'Search Course Tags. ex. Design, Development, Business', 'tutor' ) . '">';
153 $output .= '<option value="">' . __( 'Select a tag', 'tutor' ) . '</option>';
154 $output .= _generate_tags_dropdown_option( $post_ID, $tags, $args );
155 $output .= '</select>';
156
157 return $output;
158 }
159 }
160
161 /**
162 * @param $categories
163 * @param string $parent_name
164 *
165 * @return string
166 *
167 * Get selecting options, recursive supports
168 *
169 * @since v.1.3.4
170 */
171
172 if ( ! function_exists( '_generate_categories_dropdown_option' ) ) {
173 function _generate_categories_dropdown_option( $post_ID = 0, $categories = array(), $args = array(), $depth = 0 ) {
174 $output = '';
175
176 if ( ! tutor_utils()->count( $categories ) ) {
177 return $output;
178 }
179
180 if ( ! is_numeric( $post_ID ) || $post_ID < 1 ) {
181 return $output;
182 }
183
184 foreach ( $categories as $category_id => $category ) {
185 if ( ! $category->parent ) {
186 $depth = 0;
187 }
188
189 $childrens = tutor_utils()->array_get( 'children', $category );
190 $has_in_term = has_term( $category->term_id, 'course-category', $post_ID );
191
192 $depth_seperator = '';
193 if ( $depth ) {
194 for ( $depth_i = 0; $depth_i < $depth; $depth_i++ ) {
195 $depth_seperator .= '-';
196 }
197 }
198
199 $output .= '<option value="' . $category->term_id . '" ' . selected( $has_in_term, true, false ) . '> ' . $depth_seperator . ' ' . $category->name . '</option>';
200
201 if ( tutor_utils()->count( $childrens ) ) {
202 $depth++;
203 $output .= _generate_categories_dropdown_option( $post_ID, $childrens, $args, $depth );
204 }
205 }
206
207 return $output;
208 }
209 }
210 /**
211 * @param $tags
212 * @param string $parent_name
213 *
214 * @return string
215 *
216 * Get selecting options, recursive supports
217 *
218 * @since v.1.3.4
219 */
220
221 if ( ! function_exists( '_generate_tags_dropdown_option' ) ) {
222 function _generate_tags_dropdown_option( $post_ID = 0, $tags = array(), $args = array(), $depth = 0 ) {
223 $output = '';
224
225 if ( ! tutor_utils()->count( $tags ) ) {
226 return $output;
227 }
228
229 if ( ! is_numeric( $post_ID ) || $post_ID < 1 ) {
230 return $output;
231 }
232
233 foreach ( $tags as $tag ) {
234
235 $has_in_term = has_term( $tag->term_id, 'course-tag', $post_ID );
236
237 $output .= '<option value="' . $tag->name . '" ' . selected( $has_in_term, true, false ) . '>' . $tag->name . '</option>';
238
239 }
240
241 return $output;
242 }
243 }
244
245 /**
246 * @param array $args
247 *
248 * @return string
249 *
250 * Generate course categories checkbox
251 * @since v.1.3.4
252 */
253
254 if ( ! function_exists( 'tutor_course_categories_checkbox' ) ) {
255 function tutor_course_categories_checkbox( $post_ID = 0, $args = array() ) {
256 $default = array(
257 'name' => 'tax_input[course-category]',
258 );
259
260 $args = apply_filters( 'tutor_course_categories_checkbox_args', array_merge( $default, $args ) );
261
262 if ( isset( $args['name'] ) ) {
263 $args['name'] = $args['name'] . '[]';
264 }
265
266 extract( $args );
267
268 $categories = tutor_utils()->get_course_categories();
269 $output = '';
270 $output .= __tutor_generate_categories_checkbox( $post_ID, $categories, $args );
271
272 return $output;
273 }
274 }
275
276 /**
277 * @param array $args
278 *
279 * @return string
280 *
281 * Generate course tags checkbox
282 * @since v.1.3.4
283 */
284
285 if ( ! function_exists( 'tutor_course_tags_checkbox' ) ) {
286 function tutor_course_tags_checkbox( $post_ID = 0, $args = array() ) {
287 $default = array(
288 'name' => 'tax_input[course-tag]',
289 );
290
291 $args = apply_filters( 'tutor_course_tags_checkbox_args', array_merge( $default, $args ) );
292
293 if ( isset( $args['name'] ) ) {
294 $args['name'] = $args['name'] . '[]';
295 }
296
297 extract( $args );
298
299 $tags = tutor_utils()->get_course_tags();
300 $output = '';
301 $output .= __tutor_generate_tags_checkbox( $post_ID, $tags, $args );
302
303 return $output;
304 }
305 }
306
307 /**
308 * @param $categories
309 * @param string $parent_name
310 * @param array $args
311 *
312 * @return string
313 *
314 * Internal function to generate course categories checkbox
315 *
316 * @since v.1.3.4
317 */
318 if ( ! function_exists( '__tutor_generate_categories_checkbox' ) ) {
319 function __tutor_generate_categories_checkbox( $post_ID = 0, $categories = array(), $args = array() ) {
320
321 $output = '';
322 $input_name = tutor_utils()->array_get( 'name', $args );
323
324 if ( tutor_utils()->count( $categories ) ) {
325 $output .= '<ul class="tax-input-course-category">';
326 foreach ( $categories as $category_id => $category ) {
327 $childrens = tutor_utils()->array_get( 'children', $category );
328 $has_in_term = has_term( $category->term_id, 'course-category', $post_ID );
329
330 $output .= '<li class="tax-input-course-category-item tax-input-course-category-item-' . $category->term_id . '"><label class="course-category-checkbox"> <input type="checkbox" name="' . $input_name . '" value="' . $category->term_id . '" ' . checked( $has_in_term, true, false ) . '/> <span>' . $category->name . '</span> </label>';
331
332 if ( tutor_utils()->count( $childrens ) ) {
333 $output .= __tutor_generate_categories_checkbox( $post_ID, $childrens, $args );
334 }
335 $output .= ' </li>';
336 }
337 $output .= '</ul>';
338 }
339
340 return $output;
341
342 }
343 }
344 /**
345 * @param $tags
346 * @param string $parent_name
347 * @param array $args
348 *
349 * @return string
350 *
351 * Internal function to generate course tags checkbox
352 *
353 * @since v.1.3.4
354 */
355 if ( ! function_exists( '__tutor_generate_tags_checkbox' ) ) {
356 function __tutor_generate_tags_checkbox( $post_ID = 0, $tags = array(), $args = array() ) {
357
358 $output = '';
359 $input_name = tutor_utils()->array_get( 'name', $args );
360
361 if ( tutor_utils()->count( $tags ) ) {
362 $output .= '<ul class="tax-input-course-tag">';
363 foreach ( $tags as $tag ) {
364 $has_in_term = has_term( $tag->term_id, 'course-tag', $post_ID );
365
366 $output .= '<li class="tax-input-course-tag-item tax-input-course-tag-item-' . $tag->term_id . '"><label class="course-tag-checkbox"> <input type="checkbox" name="' . $input_name . '" value="' . $tag->term_id . '" ' . checked( $has_in_term, true, false ) . ' /> <span>' . $tag->name . '</span> </label>';
367
368 $output .= ' </li>';
369 }
370 $output .= '</ul>';
371 }
372
373 return $output;
374 }
375 }
376
377 /**
378 * @param string $content
379 * @param string $title
380 *
381 * @return string
382 *
383 * Wrap course builder sections within div for frontend
384 *
385 * @since v.1.3.4
386 */
387
388 if ( ! function_exists( 'course_builder_section_wrap' ) ) {
389 function course_builder_section_wrap( $content = '', $title = '', $echo = true ) {
390 ob_start();
391 ?>
392 <div class="tutor-course-builder-section">
393 <div class="tutor-course-builder-section-title">
394 <span class="tutor-fs-5 tutor-fw-bold tutor-color-secondary">
395 <i class="tutor-icon-angle-up" area-hidden="true"></i>
396 <span><?php echo $title; ?></span>
397 </span>
398 </div>
399 <div class="tutor-course-builder-section-content">
400 <?php echo $content; ?>
401 </div>
402 </div>
403 <?php
404 $html = ob_get_clean();
405
406 if ( $echo ) {
407 echo tutor_kses_html( $html );
408 } else {
409 return $html;
410 }
411 }
412 }
413
414
415 if ( ! function_exists( 'get_tutor_header' ) ) {
416 function get_tutor_header( $fullScreen = false ) {
417 $enable_spotlight_mode = tutor_utils()->get_option( 'enable_spotlight_mode' );
418
419 if ( $enable_spotlight_mode || $fullScreen ) {
420 ?>
421 <!doctype html>
422 <html <?php language_attributes(); ?>>
423
424 <head>
425 <meta charset="<?php bloginfo( 'charset' ); ?>" />
426 <meta name="viewport" content="width=device-width, initial-scale=1" />
427 <link rel="profile" href="https://gmpg.org/xfn/11" />
428 <?php wp_head(); ?>
429 </head>
430
431 <body <?php body_class(); ?>>
432 <div id="tutor-page-wrap" class="tutor-site-wrap site">
433 <?php
434 } else {
435 tutor_utils()->tutor_custom_header();
436 }
437 }
438 }
439
440 if ( ! function_exists( 'get_tutor_footer' ) ) {
441 function get_tutor_footer( $fullScreen = false ) {
442 $enable_spotlight_mode = tutor_utils()->get_option( 'enable_spotlight_mode' );
443 if ( $enable_spotlight_mode || $fullScreen ) {
444 ?>
445 </div>
446 <?php wp_footer(); ?>
447
448 </body>
449
450 </html>
451 <?php
452 } else {
453 tutor_utils()->tutor_custom_footer();
454 }
455 }
456 }
457
458 /**
459 * @param null $key
460 * @param bool $default
461 *
462 * @return array|bool|mixed
463 *
464 * Get tutor option by this helper function
465 *
466 * @since v.1.3.6
467 */
468 if ( ! function_exists( 'get_tutor_option' ) ) {
469 function get_tutor_option( $key = null, $default = false ) {
470 return tutor_utils()->get_option( $key, $default );
471 }
472 }
473
474 /**
475 * @param null $key
476 * @param bool $value
477 *
478 * Update tutor option by this helper function
479 *
480 * @since v.1.3.6
481 */
482 if ( ! function_exists( 'update_tutor_option' ) ) {
483 function update_tutor_option( $key = null, $value = false ) {
484 tutor_utils()->update_option( $key, $value );
485 }
486 }
487 /**
488 * @param int $course_id
489 * @param null $key
490 * @param bool $default
491 *
492 * @return array|bool|mixed
493 *
494 * Get tutor course settings by course ID
495 *
496 * @since v.1.4.1
497 */
498 if ( ! function_exists( 'get_tutor_course_settings' ) ) {
499 function get_tutor_course_settings( $course_id = 0, $key = null, $default = false ) {
500 return tutor_utils()->get_course_settings( $course_id, $key, $default );
501 }
502 }
503
504 /**
505 * @param int $lesson_id
506 * @param null $key
507 * @param bool $default
508 *
509 * @return array|bool|mixed
510 *
511 * Get lesson content drip settings
512 */
513
514 if ( ! function_exists( 'get_item_content_drip_settings' ) ) {
515 function get_item_content_drip_settings( $lesson_id = 0, $key = null, $default = false ) {
516 return tutor_utils()->get_item_content_drip_settings( $lesson_id, $key, $default );
517 }
518 }
519
520 /**
521 * @param null $msg
522 * @param string $type
523 * @param bool $echo
524 *
525 * @return string
526 *
527 * Print Alert by tutor_alert()
528 *
529 * @since v.1.4.1
530 */
531 if ( ! function_exists( 'tutor_alert' ) ) {
532 function tutor_alert( $msg = null, $type = 'warning', $echo = true ) {
533 if ( ! $msg ) {
534
535 if ( $type === 'any' ) {
536 if ( ! $msg ) {
537 $type = 'warning';
538 $msg = tutor_flash_get( $type );
539 }
540 if ( ! $msg ) {
541 $type = 'danger';
542 $msg = tutor_flash_get( $type );
543 }
544 if ( ! $msg ) {
545 $type = 'success';
546 $msg = tutor_flash_get( $type );
547 }
548 } else {
549 $msg = tutor_flash_get( $type );
550 }
551 }
552 if ( ! $msg ) {
553 return $msg;
554 }
555
556 $html = '<div class="asas tutor-alert tutor-' . esc_attr( $type ) . '">
557 <div class="tutor-alert-text">
558 <span class="tutor-alert-icon tutor-fs-4 tutor-icon-circle-info tutor-mr-12"></span>
559 <span>' . wp_kses( $msg, array( 'div', 'span' ) ) . '</span>
560 </div>
561 </div>';
562 if ( $echo ) {
563 echo tutor_kses_html( $html );
564 }
565 return $html;
566 }
567 }
568
569
570 /**
571 * @param bool $echo
572 *
573 * Simply call tutor_nonce_field() to generate nonce field
574 *
575 * @since v.1.4.2
576 */
577
578 if ( ! function_exists( 'tutor_nonce_field' ) ) {
579 function tutor_nonce_field( $echo = true ) {
580 wp_nonce_field( tutor()->nonce_action, tutor()->nonce, $echo );
581 }
582 }
583
584 /**
585 * @param null $key
586 * @param string $message
587 *
588 * Set Flash Message
589 */
590
591 if ( ! function_exists( 'tutor_flash_set' ) ) {
592 function tutor_flash_set( $key = null, $message = '' ) {
593 if ( ! $key ) {
594 return;
595 }
596 // ensure session is started
597 if ( session_status() !== PHP_SESSION_ACTIVE ) {
598 session_start();
599 }
600 $_SESSION[ $key ] = $message;
601 }
602 }
603
604 /**
605 * @param null $key
606 *
607 * @return array|bool|mixed|null
608 *
609 * @since v.1.4.2
610 *
611 * Get flash message
612 */
613
614 if ( ! function_exists( 'tutor_flash_get' ) ) {
615 function tutor_flash_get( $key = null ) {
616 if ( $key ) {
617 // ensure session is started
618 if ( session_status() !== PHP_SESSION_ACTIVE ) {
619 @session_start();
620 }
621 if ( empty( $_SESSION ) ) {
622 return null;
623 }
624 $message = tutor_utils()->array_get( $key, $_SESSION );
625 if ( $message ) {
626 unset( $_SESSION[ $key ] );
627 }
628 return $message;
629 }
630 return $key;
631 }
632 }
633
634 if ( ! function_exists( 'tutor_redirect_back' ) ) {
635 /**
636 * @param null $url
637 *
638 * Redirect to back or a specific URL and terminate
639 *
640 * @since v.1.4.3
641 */
642 function tutor_redirect_back( $url = null ) {
643 if ( ! $url ) {
644 $url = tutor_utils()->referer();
645 }
646 wp_safe_redirect( $url );
647 exit();
648 }
649 }
650
651 /**
652 * @param string $action
653 * @param bool $echo
654 *
655 * @return string
656 *
657 * @since v.1.4.3
658 */
659
660 if ( ! function_exists( 'tutor_action_field' ) ) {
661 function tutor_action_field( $action = '', $echo = true ) {
662 $output = '';
663 if ( $action ) {
664 $output = '<input type="hidden" name="tutor_action" value="' . $action . '">';
665 }
666
667 if ( $echo ) {
668 echo tutor_kses_html( $output );
669 } else {
670 return $output;
671 }
672 }
673 }
674
675
676 if ( ! function_exists( 'tutor_time' ) ) {
677 /**
678 * Return current Time from WordPress time
679 * @return int|string
680 * @since v.1.4.3
681 */
682 function tutor_time() {
683 $gmt_offset = get_option( 'gmt_offset' );
684 return time() + ( $gmt_offset * HOUR_IN_SECONDS );
685 }
686 }
687
688 /**
689 * Toggle maintenance mode for the site.
690 *
691 * Creates/deletes the maintenance file to enable/disable maintenance mode.
692 *
693 * @since v.1.4.6
694 *
695 * @global WP_Filesystem_Base $wp_filesystem Subclass
696 *
697 * @param bool $enable True to enable maintenance mode, false to disable.
698 */
699 if ( ! function_exists( 'tutor_maintenance_mode' ) ) {
700 function tutor_maintenance_mode( $enable = false ) {
701 $file = ABSPATH . '.tutor_maintenance';
702 if ( $enable ) {
703 // Create maintenance file to signal that we are upgrading
704 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
705
706 if ( ! file_exists( $file ) ) {
707 file_put_contents( $file, $maintenance_string );
708 }
709 } else {
710 if ( file_exists( $file ) ) {
711 unlink( $file );
712 }
713 }
714 }
715 }
716
717 /**
718 * @return bool
719 *
720 * Check if the current page is course single page
721 *
722 * @since v.1.6.0
723 */
724
725 if ( ! function_exists( 'is_single_course' ) ) {
726 function is_single_course( $check_spotlight = false ) {
727 global $wp_query;
728 $course_post_type = tutor()->course_post_type;
729
730 $post_types = array( $course_post_type );
731 if ( $check_spotlight ) {
732 $post_types = array_merge(
733 $post_types,
734 array(
735 'lesson',
736 'tutor_quiz',
737 'tutor_assignments',
738 'tutor_zoom_meeting',
739 )
740 );
741 }
742
743 if ( is_single() && ! empty( $wp_query->query['post_type'] ) && in_array( $wp_query->query['post_type'], $post_types ) ) {
744 return true;
745 }
746 return false;
747 }
748 }
749
750 /**
751 * Require wp_date form return js date format.
752 * this is helpful for date picker
753 *
754 * @return string
755 *
756 * @since 1.9.7
757 */
758 if ( ! function_exists( 'tutor_js_date_format_against_wp' ) ) {
759 function tutor_js_date_format_against_wp() {
760 $wp_date_format = get_option( 'date_format' );
761 $default_format = 'Y-M-d';
762
763 $formats = array(
764 'Y-m-d' => 'Y-M-d',
765 'm/d/Y' => 'M-d-Y',
766 'd/m/Y' => 'd-M-Y',
767 'F j, Y' => 'MMMM d, yyyy',
768 'j F Y' => 'MMMM d, yyyy',
769 );
770 return isset( $formats[ $wp_date_format ] ) ? $formats[ $wp_date_format ] : $default_format;
771 }
772 }
773
774 /**
775 * Convert date to desire format
776 *
777 * NOTE: mysql query use formated date from here
778 * that's why date_i18n need to be ignore
779 *
780 * @param $format string
781 *
782 * @param $date string
783 *
784 * @return string ( date )
785 */
786 if ( ! function_exists( 'tutor_get_formated_date' ) ) {
787 function tutor_get_formated_date( string $require_format, string $user_date ) {
788 $date = date_create( str_replace( '/', '-', $user_date ) );
789 if ( is_a( $date, 'DateTime' ) ) {
790 $formatted_date = date_format( $date, $require_format );
791 } else {
792 $formatted_date = date( $require_format, strtotime( $user_date ) );
793 }
794 return $formatted_date;
795 }
796 }
797
798 /**
799 * Get translated date
800 *
801 * @since v2.0.2
802 *
803 * @param string $date date in string from to translate & format.
804 * @param string $format optional date format, default is wp date time format.
805 *
806 * @return string translated date
807 */
808 if ( ! function_exists( 'tutor_i18n_get_formated_date' ) ) {
809 function tutor_i18n_get_formated_date( string $date, string $format = '' ) {
810 if ( '' === $format ) {
811 $format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
812 }
813 return date_i18n( $format, strtotime( $date ) );
814 }
815 }
816
817 if ( ! function_exists( '_tutor_search_by_title_only' ) ) {
818 /**
819 * Search SQL filter for matching against post title only.
820 *
821 * @link http://wordpress.stackexchange.com/a/11826/1685
822 *
823 * @param string $search
824 * @param WP_Query $wp_query
825 */
826 function _tutor_search_by_title_only( $search, $wp_query ) {
827 if ( ! empty( $search ) && ! empty( $wp_query->query_vars['search_terms'] ) ) {
828 global $wpdb;
829
830 $q = $wp_query->query_vars;
831 $n = ! empty( $q['exact'] ) ? '' : '%';
832
833 $search = array();
834
835 foreach ( (array) $q['search_terms'] as $term ) {
836 $search[] = $wpdb->prepare( "$wpdb->posts.post_title LIKE %s", $n . $wpdb->esc_like( $term ) . $n );
837 }
838
839 if ( ! is_user_logged_in() ) {
840 $search[] = "$wpdb->posts.post_password = ''";
841 }
842
843 $search = ' AND ' . implode( ' AND ', $search );
844 }
845
846 return $search;
847 }
848 }
849
850 if ( ! function_exists( 'pr' ) ) {
851 /**
852 * Function to print_r
853 *
854 * @param array $var .
855 * @return array
856 */
857 function pr( $var ) {
858 $template = PHP_SAPI !== 'cli' && PHP_SAPI !== 'phpdbg' ? '<pre class="pr">%s</pre>' : "\n%s\n\n";
859 printf( $template, trim( print_r( $var, true ) ) );
860
861 return $var;
862 }
863 }
864
865 if ( ! function_exists( 'get_request' ) ) {
866 /**
867 * Function to get_request
868 *
869 * @param array $var .
870 * @return array
871 */
872 function get_request( $var ) {
873 return isset( $_REQUEST[ $var ] ) ? sanitize_text_field( $_REQUEST[ $var ] ) : false;
874
875 }
876 }
877
878 if ( ! function_exists( 'tutor_kses_allowed_html' ) ) {
879 function tutor_kses_allowed_html( $allowed_tags, $context ) {
880 $tags = array( 'input', 'style', 'script', 'select', 'form', 'option', 'optgroup', 'iframe', 'bdi', 'source' );
881 $atts = array( 'min', 'max', 'maxlength', 'type', 'method', 'enctype', 'action', 'selected', 'class', 'id', 'disabled', 'checked', 'readonly', 'name', 'aria-*', 'style', 'role', 'placeholder', 'value', 'data-*', 'src', 'width', 'height', 'frameborder', 'allow', 'fullscreen', 'title', 'multiple' );
882
883 foreach ( $tags as $tag ) {
884 $tag_attrs = array();
885
886 foreach ( $atts as $att ) {
887 $tag_attrs[ $att ] = true;
888 }
889
890 $allowed_tags[ $tag ] = $tag_attrs;
891 }
892
893 return $allowed_tags;
894 }
895 }
896
897 if ( ! function_exists( 'tutor_kses_allowed_css' ) ) {
898 function tutor_kses_allowed_css( $styles ) {
899 $styles[] = 'display';
900 $styles[] = '--progress-value';
901 return $styles;
902 }
903 }
904
905 if ( ! function_exists( 'tutor_kses_html' ) ) {
906 function tutor_kses_html( $content ) {
907
908 return $content;
909 add_filter( 'wp_kses_allowed_html', 'tutor_kses_allowed_html', 10, 2 );
910 add_filter( 'safe_style_css', 'tutor_kses_allowed_css' );
911
912 $content = preg_replace( '/<!--(.|\s)*?-->/', '', $content );
913 $content = wp_kses_post( $content );
914 $content = str_replace( '&amp;', '&', $content );
915
916 remove_filter( 'safe_style_css', 'tutor_kses_allowed_css' );
917 remove_filter( 'wp_kses_allowed_html', 'tutor_kses_allowed_html' );
918
919 return $content;
920 }
921 }
922
923 /**
924 * @return array
925 *
926 * Get all Withdraw Methods available on this system
927 *
928 * @since v.1.5.7
929 */
930 if ( ! function_exists( 'get_tutor_all_withdrawal_methods' ) ) {
931 function get_tutor_all_withdrawal_methods() {
932 return apply_filters( 'tutor_withdrawal_methods_all', array() );
933 }
934 }
935
936
937 if ( ! function_exists( 'tutor_log' ) ) {
938 function tutor_log() {
939 $arg_list = func_get_args();
940
941 foreach ($arg_list as $data) {
942 ob_start();
943 var_dump( $data );
944 error_log( ob_get_clean() );
945 }
946 }
947 }
948
949 if ( ! function_exists( 'tutor_wc_price_currency_format' ) ) {
950 function tutor_wc_price_currency_format( $amount ) {
951
952 $symbol = get_woocommerce_currency_symbol();
953 $position = get_option( 'woocommerce_currency_pos', 'left' );
954
955 switch ( $position ) {
956 case 'left':
957 $amount = $symbol . $amount;
958 break;
959 case 'left_space':
960 $amount = $symbol . ' ' . $amount;
961 break;
962
963 case 'right':
964 $amount = $amount . $symbol;
965 break;
966 case 'right_space':
967 $amount = $amount . ' ' . $symbol;
968 break;
969
970 default:
971 $amount = $symbol . $amount;
972 break;
973 }
974
975 return $amount;
976 }
977 }
978
979 if ( ! function_exists( 'tutor_meta_box_wrapper' ) ) {
980 /**
981 * Tutor meta box wrapper
982 *
983 * @since v2.0.2
984 *
985 * @param string $id id of meta box.
986 * @param string $title meta box title.
987 * @param mixed $callback callback function that meta box will call.
988 * @param string $screen which screen meta box should appear.
989 * @param string $context optional param. Where meta box should appear.
990 * @param string $priority optional.
991 * @param string $custom_class optional. If provide it will add this class along
992 * with div id.
993 *
994 * @return void if class provided then filter hook will return class.
995 */
996 function tutor_meta_box_wrapper(
997 $id,
998 $title,
999 $callback,
1000 $screen,
1001 $context = 'advanced',
1002 $priority = 'default',
1003 $custom_class = ''
1004 ) {
1005 add_meta_box(
1006 $id,
1007 $title,
1008 $callback,
1009 $screen,
1010 $context,
1011 $priority
1012 );
1013 if ( '' !== $custom_class ) {
1014 $post_type = tutor()->course_post_type;
1015 add_filter(
1016 "postbox_classes_{$post_type}_{$id}",
1017 function( $classes ) use ( $custom_class ) {
1018 if ( ! in_array( $custom_class, $classes ) ) {
1019 $classes[] = $custom_class;
1020 }
1021 return $classes;
1022 }
1023 );
1024 }
1025 }
1026 }
1027
1028