PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.9.15
Tutor LMS – eLearning and online course solution v1.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 5 years ago tinymce_translate.php 4 years ago tutor-general-functions.php 4 years ago tutor-template-functions.php 4 years ago tutor-template-hook.php 5 years ago
tutor-general-functions.php
839 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
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 /**
65 * Tutor general Functions
66 */
67
68 if ( ! function_exists( 'tutor_withdrawal_methods' ) ) {
69 function tutor_withdrawal_methods() {
70 $withdraw = new \TUTOR\Withdraw();
71
72 return $withdraw->available_withdraw_methods;
73 }
74 }
75
76 /**
77 * @return array
78 *
79 * Get all Withdraw Methods available on this system
80 *
81 * @since v.1.5.7
82 */
83
84 if ( ! function_exists( 'get_tutor_all_withdrawal_methods' ) ) {
85 function get_tutor_all_withdrawal_methods() {
86 $withdraw = new \TUTOR\Withdraw();
87
88 return $withdraw->withdraw_methods;
89 }
90 }
91
92 if ( ! function_exists( 'tutor_placeholder_img_src' ) ) {
93 function tutor_placeholder_img_src() {
94 $src = tutor()->url . 'assets/images/placeholder.jpg';
95 return apply_filters( 'tutor_placeholder_img_src', $src );
96 }
97 }
98
99 /**
100 * @return string
101 *
102 * Get course categories selecting UI
103 *
104 * @since v.1.3.4
105 */
106
107 if ( ! function_exists( 'tutor_course_categories_dropdown' ) ) {
108 function tutor_course_categories_dropdown( $post_ID = 0, $args = array() ) {
109
110 $default = array(
111 'classes' => '',
112 'name' => 'tax_input[course-category]',
113 'multiple' => true,
114 );
115
116 $args = apply_filters( 'tutor_course_categories_dropdown_args', array_merge( $default, $args ) );
117
118 $multiple_select = '';
119
120 if ( tutor_utils()->array_get( 'multiple', $args ) ) {
121 if ( isset( $args['name'] ) ) {
122 $args['name'] = $args['name'] . '[]';
123 }
124 $multiple_select = "multiple='multiple'";
125 }
126
127 extract( $args );
128
129 $classes = (array) $classes;
130 $classes = implode( ' ', $classes );
131
132 $categories = tutor_utils()->get_course_categories();
133
134 $output = '';
135 $output .= '<select name="' . $name . '" ' . $multiple_select . ' class="' . $classes . '" data-placeholder="' . __( 'Search Course Category. ex. Design, Development, Business', 'tutor' ) . '">';
136 $output .= '<option value="">' . __( 'Select a category', 'tutor' ) . '</option>';
137 $output .= _generate_categories_dropdown_option( $post_ID, $categories, $args );
138 $output .= '</select>';
139
140 return $output;
141 }
142 }
143
144 /**
145 * @return string
146 *
147 * Get course tags selecting UI
148 *
149 * @since v.1.3.4
150 */
151
152 if ( ! function_exists( 'tutor_course_tags_dropdown' ) ) {
153 function tutor_course_tags_dropdown( $post_ID = 0, $args = array() ) {
154
155 $default = array(
156 'classes' => '',
157 'name' => 'tax_input[course-tag]',
158 'multiple' => true,
159 );
160
161 $args = apply_filters( 'tutor_course_tags_dropdown_args', array_merge( $default, $args ) );
162
163 $multiple_select = '';
164
165 if ( tutor_utils()->array_get( 'multiple', $args ) ) {
166 if ( isset( $args['name'] ) ) {
167 $args['name'] = $args['name'] . '[]';
168 }
169 $multiple_select = "multiple='multiple'";
170 }
171
172 extract( $args );
173
174 $classes = (array) $classes;
175 $classes = implode( ' ', $classes );
176
177 $tags = tutor_utils()->get_course_tags();
178
179 $output = '';
180 $output .= '<select name=' . $name . ' ' . $multiple_select . ' class="' . $classes . '" data-placeholder="' . __( 'Search Course Tags. ex. Design, Development, Business', 'tutor' ) . '">';
181 $output .= '<option value="">' . __( 'Select a tag', 'tutor' ) . '</option>';
182 $output .= _generate_tags_dropdown_option( $post_ID, $tags, $args );
183 $output .= '</select>';
184
185 return $output;
186 }
187 }
188
189 /**
190 * @param $categories
191 * @param string $parent_name
192 *
193 * @return string
194 *
195 * Get selecting options, recursive supports
196 *
197 * @since v.1.3.4
198 */
199
200 if ( ! function_exists( '_generate_categories_dropdown_option' ) ) {
201 function _generate_categories_dropdown_option( $post_ID = 0, $categories = array(), $args = array(), $depth = 0 ) {
202 $output = '';
203
204 if ( ! tutor_utils()->count( $categories ) ) {
205 return $output;
206 }
207
208 if ( ! is_numeric( $post_ID ) || $post_ID < 1 ) {
209 return $output;
210 }
211
212 foreach ( $categories as $category_id => $category ) {
213 if ( ! $category->parent ) {
214 $depth = 0;
215 }
216
217 $childrens = tutor_utils()->array_get( 'children', $category );
218 $has_in_term = has_term( $category->term_id, 'course-category', $post_ID );
219
220 $depth_seperator = '';
221 if ( $depth ) {
222 for ( $depth_i = 0; $depth_i < $depth; $depth_i++ ) {
223 $depth_seperator .= '-';
224 }
225 }
226
227 $output .= '<option value="' . $category->term_id . '" ' . selected( $has_in_term, true, false ) . '> ' . $depth_seperator . ' ' . $category->name . '</option>';
228
229 if ( tutor_utils()->count( $childrens ) ) {
230 $depth++;
231 $output .= _generate_categories_dropdown_option( $post_ID, $childrens, $args, $depth );
232 }
233 }
234
235 return $output;
236 }
237 }
238 /**
239 * @param $tags
240 * @param string $parent_name
241 *
242 * @return string
243 *
244 * Get selecting options, recursive supports
245 *
246 * @since v.1.3.4
247 */
248
249 if ( ! function_exists( '_generate_tags_dropdown_option' ) ) {
250 function _generate_tags_dropdown_option( $post_ID = 0, $tags = array(), $args = array(), $depth = 0 ) {
251 $output = '';
252
253 if ( ! tutor_utils()->count( $tags ) ) {
254 return $output;
255 }
256
257 if ( ! is_numeric( $post_ID ) || $post_ID < 1 ) {
258 return $output;
259 }
260
261 foreach ( $tags as $tag ) {
262
263 $has_in_term = has_term( $tag->term_id, 'course-tag', $post_ID );
264
265 $output .= '<option value="' . $tag->name . '" ' . selected( $has_in_term, true, false ) . '>' . $tag->name . '</option>';
266
267 }
268
269 return $output;
270 }
271 }
272
273 /**
274 * @param array $args
275 *
276 * @return string
277 *
278 * Generate course categories checkbox
279 * @since v.1.3.4
280 */
281
282 if ( ! function_exists( 'tutor_course_categories_checkbox' ) ) {
283 function tutor_course_categories_checkbox( $post_ID = 0, $args = array() ) {
284 $default = array(
285 'name' => 'tax_input[course-category]',
286 );
287
288 $args = apply_filters( 'tutor_course_categories_checkbox_args', array_merge( $default, $args ) );
289
290 if ( isset( $args['name'] ) ) {
291 $args['name'] = $args['name'] . '[]';
292 }
293
294 extract( $args );
295
296 $categories = tutor_utils()->get_course_categories();
297 $output = '';
298 $output .= __tutor_generate_categories_checkbox( $post_ID, $categories, $args );
299
300 return $output;
301 }
302 }
303
304 /**
305 * @param array $args
306 *
307 * @return string
308 *
309 * Generate course tags checkbox
310 * @since v.1.3.4
311 */
312
313 if ( ! function_exists( 'tutor_course_tags_checkbox' ) ) {
314 function tutor_course_tags_checkbox( $post_ID = 0, $args = array() ) {
315 $default = array(
316 'name' => 'tax_input[course-tag]',
317 );
318
319 $args = apply_filters( 'tutor_course_tags_checkbox_args', array_merge( $default, $args ) );
320
321 if ( isset( $args['name'] ) ) {
322 $args['name'] = $args['name'] . '[]';
323 }
324
325 extract( $args );
326
327 $tags = tutor_utils()->get_course_tags();
328 $output = '';
329 $output .= __tutor_generate_tags_checkbox( $post_ID, $tags, $args );
330
331 return $output;
332 }
333 }
334
335 /**
336 * @param $categories
337 * @param string $parent_name
338 * @param array $args
339 *
340 * @return string
341 *
342 * Internal function to generate course categories checkbox
343 *
344 * @since v.1.3.4
345 */
346 if ( ! function_exists( '__tutor_generate_categories_checkbox' ) ) {
347 function __tutor_generate_categories_checkbox( $post_ID = 0, $categories = array(), $args = array() ) {
348
349 $output = '';
350 $input_name = tutor_utils()->array_get( 'name', $args );
351
352 if ( tutor_utils()->count( $categories ) ) {
353 $output .= '<ul class="tax-input-course-category">';
354 foreach ( $categories as $category_id => $category ) {
355 $childrens = tutor_utils()->array_get( 'children', $category );
356 $has_in_term = has_term( $category->term_id, 'course-category', $post_ID );
357
358 $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>';
359
360 if ( tutor_utils()->count( $childrens ) ) {
361 $output .= __tutor_generate_categories_checkbox( $post_ID, $childrens, $args );
362 }
363 $output .= ' </li>';
364 }
365 $output .= '</ul>';
366 }
367
368 return $output;
369
370 }
371 }
372 /**
373 * @param $tags
374 * @param string $parent_name
375 * @param array $args
376 *
377 * @return string
378 *
379 * Internal function to generate course tags checkbox
380 *
381 * @since v.1.3.4
382 */
383 if ( ! function_exists( '__tutor_generate_tags_checkbox' ) ) {
384 function __tutor_generate_tags_checkbox( $post_ID = 0, $tags = array(), $args = array() ) {
385
386 $output = '';
387 $input_name = tutor_utils()->array_get( 'name', $args );
388
389 if ( tutor_utils()->count( $tags ) ) {
390 $output .= '<ul class="tax-input-course-tag">';
391 foreach ( $tags as $tag ) {
392 $has_in_term = has_term( $tag->term_id, 'course-tag', $post_ID );
393
394 $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>';
395
396 $output .= ' </li>';
397 }
398 $output .= '</ul>';
399 }
400
401 return $output;
402 }
403 }
404
405 /**
406 * @param string $content
407 * @param string $title
408 *
409 * @return string
410 *
411 * Wrap course builder sections within div for frontend
412 *
413 * @since v.1.3.4
414 */
415
416 if ( ! function_exists( 'course_builder_section_wrap' ) ) {
417 function course_builder_section_wrap( $content = '', $title = '', $echo = true ) {
418 ob_start();
419 ?>
420 <div class="tutor-course-builder-section">
421 <div class="tutor-course-builder-section-title">
422 <h3><i class="tutor-icon-down"></i> <span><?php echo $title; ?></span></h3>
423 </div>
424 <div class="tutor-course-builder-section-content">
425 <?php echo $content; ?>
426 </div>
427 </div>
428 <?php
429 $html = ob_get_clean();
430
431 if ( $echo ) {
432 echo tutor_kses_html( $html );
433 } else {
434 return $html;
435 }
436 }
437 }
438
439
440 if ( ! function_exists( 'get_tutor_header' ) ) {
441 function get_tutor_header( $fullScreen = false ) {
442 $enable_spotlight_mode = tutor_utils()->get_option( 'enable_spotlight_mode' );
443
444 if ( $enable_spotlight_mode || $fullScreen ) {
445 ?>
446 <!doctype html>
447 <html <?php language_attributes(); ?>>
448
449 <head>
450 <meta charset="<?php bloginfo( 'charset' ); ?>" />
451 <meta name="viewport" content="width=device-width, initial-scale=1" />
452 <link rel="profile" href="https://gmpg.org/xfn/11" />
453 <?php wp_head(); ?>
454 </head>
455
456 <body <?php body_class(); ?>>
457 <div id="tutor-page-wrap" class="tutor-site-wrap site">
458 <?php
459 } else {
460 tutor_utils()->tutor_custom_header();
461 }
462 }
463 }
464
465 if ( ! function_exists( 'get_tutor_footer' ) ) {
466 function get_tutor_footer( $fullScreen = false ) {
467 $enable_spotlight_mode = tutor_utils()->get_option( 'enable_spotlight_mode' );
468 if ( $enable_spotlight_mode || $fullScreen ) {
469 ?>
470 </div>
471 <?php wp_footer(); ?>
472
473 </body>
474
475 </html>
476 <?php
477 } else {
478 tutor_utils()->tutor_custom_footer();
479 }
480 }
481 }
482
483 /**
484 * @param null $key
485 * @param bool $default
486 *
487 * @return array|bool|mixed
488 *
489 * Get tutor option by this helper function
490 *
491 * @since v.1.3.6
492 */
493 if ( ! function_exists( 'get_tutor_option' ) ) {
494 function get_tutor_option( $key = null, $default = false ) {
495 return tutils()->get_option( $key, $default );
496 }
497 }
498
499 /**
500 * @param null $key
501 * @param bool $value
502 *
503 * Update tutor option by this helper function
504 *
505 * @since v.1.3.6
506 */
507 if ( ! function_exists( 'update_tutor_option' ) ) {
508 function update_tutor_option( $key = null, $value = false ) {
509 tutils()->update_option( $key, $value );
510 }
511 }
512 /**
513 * @param int $course_id
514 * @param null $key
515 * @param bool $default
516 *
517 * @return array|bool|mixed
518 *
519 * Get tutor course settings by course ID
520 *
521 * @since v.1.4.1
522 */
523 if ( ! function_exists( 'get_tutor_course_settings' ) ) {
524 function get_tutor_course_settings( $course_id = 0, $key = null, $default = false ) {
525 return tutils()->get_course_settings( $course_id, $key, $default );
526 }
527 }
528
529 /**
530 * @param int $lesson_id
531 * @param null $key
532 * @param bool $default
533 *
534 * @return array|bool|mixed
535 *
536 * Get lesson content drip settings
537 */
538
539 if ( ! function_exists( 'get_item_content_drip_settings' ) ) {
540 function get_item_content_drip_settings( $lesson_id = 0, $key = null, $default = false ) {
541 return tutils()->get_item_content_drip_settings( $lesson_id, $key, $default );
542 }
543 }
544
545 /**
546 * @param null $msg
547 * @param string $type
548 * @param bool $echo
549 *
550 * @return string
551 *
552 * Print Alert by tutor_alert()
553 *
554 * @since v.1.4.1
555 */
556 if ( ! function_exists( 'tutor_alert' ) ) {
557 function tutor_alert( $msg = null, $type = 'warning', $echo = true ) {
558 if ( ! $msg ) {
559
560 if ( $type === 'any' ) {
561 if ( ! $msg ) {
562 $type = 'warning';
563 $msg = tutor_flash_get( $type );
564 }
565 if ( ! $msg ) {
566 $type = 'danger';
567 $msg = tutor_flash_get( $type );
568 }
569 if ( ! $msg ) {
570 $type = 'success';
571 $msg = tutor_flash_get( $type );
572 }
573 } else {
574 $msg = tutor_flash_get( $type );
575 }
576 }
577 if ( ! $msg ) {
578 return $msg;
579 }
580
581 $html = '<div class="tutor-alert tutor-alert-' . $type . '">' . $msg . '</div>';
582
583 if ( $echo ) {
584 echo tutor_kses_html( $html );
585 }
586 return $html;
587 }
588 }
589
590
591 /**
592 * @param bool $echo
593 *
594 * Simply call tutor_nonce_field() to generate nonce field
595 *
596 * @since v.1.4.2
597 */
598
599 if ( ! function_exists( 'tutor_nonce_field' ) ) {
600 function tutor_nonce_field( $echo = true ) {
601 wp_nonce_field( tutor()->nonce_action, tutor()->nonce, $echo );
602 }
603 }
604
605 /**
606 * @param null $key
607 * @param string $message
608 *
609 * Set Flash Message
610 */
611
612 if ( ! function_exists( 'tutor_flash_set' ) ) {
613 function tutor_flash_set( $key = null, $message = '' ) {
614 if ( ! $key ) {
615 return;
616 }
617 // ensure session is started
618 if ( session_status() !== PHP_SESSION_ACTIVE ) {
619 session_start();
620 }
621 $_SESSION[ $key ] = $message;
622 }
623 }
624
625 /**
626 * @param null $key
627 *
628 * @return array|bool|mixed|null
629 *
630 * @since v.1.4.2
631 *
632 * Get flash message
633 */
634
635 if ( ! function_exists( 'tutor_flash_get' ) ) {
636 function tutor_flash_get( $key = null ) {
637 if ( $key ) {
638 // ensure session is started
639 if ( session_status() !== PHP_SESSION_ACTIVE ) {
640 @session_start();
641 }
642 if ( empty( $_SESSION ) ) {
643 return null;
644 }
645 $message = tutils()->array_get( $key, $_SESSION );
646 if ( $message ) {
647 unset( $_SESSION[ $key ] );
648 }
649 return $message;
650 }
651 return $key;
652 }
653 }
654
655 if ( ! function_exists( 'tutor_redirect_back' ) ) {
656 /**
657 * @param null $url
658 *
659 * Redirect to back or a specific URL and terminate
660 *
661 * @since v.1.4.3
662 */
663 function tutor_redirect_back( $url = null ) {
664 if ( ! $url ) {
665 $url = tutils()->referer();
666 }
667 wp_safe_redirect( $url );
668 exit();
669 }
670 }
671
672 /**
673 * @param string $action
674 * @param bool $echo
675 *
676 * @return string
677 *
678 * @since v.1.4.3
679 */
680
681 if ( ! function_exists( 'tutor_action_field' ) ) {
682 function tutor_action_field( $action = '', $echo = true ) {
683 $output = '';
684 if ( $action ) {
685 $output = '<input type="hidden" name="tutor_action" value="' . $action . '">';
686 }
687
688 if ( $echo ) {
689 echo tutor_kses_html( $output );
690 } else {
691 return $output;
692 }
693 }
694 }
695
696 /**
697 * @return int|string
698 *
699 * Return current Time from WordPress time
700 *
701 * @since v.1.4.3
702 */
703
704 if ( ! function_exists( 'tutor_time' ) ) {
705 function tutor_time() {
706 // return current_time( 'timestamp' );
707 return time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
708 }
709 }
710
711 /**
712 * Toggle maintenance mode for the site.
713 *
714 * Creates/deletes the maintenance file to enable/disable maintenance mode.
715 *
716 * @since v.1.4.6
717 *
718 * @global WP_Filesystem_Base $wp_filesystem Subclass
719 *
720 * @param bool $enable True to enable maintenance mode, false to disable.
721 */
722 if ( ! function_exists( 'tutor_maintenance_mode' ) ) {
723 function tutor_maintenance_mode( $enable = false ) {
724 $file = ABSPATH . '.tutor_maintenance';
725 if ( $enable ) {
726 // Create maintenance file to signal that we are upgrading
727 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
728
729 if ( ! file_exists( $file ) ) {
730 file_put_contents( $file, $maintenance_string );
731 }
732 } else {
733 if ( file_exists( $file ) ) {
734 unlink( $file );
735 }
736 }
737 }
738 }
739
740 /**
741 * @return bool
742 *
743 * Check if the current page is course single page
744 *
745 * @since v.1.6.0
746 */
747
748 if ( ! function_exists( 'is_single_course' ) ) {
749 function is_single_course() {
750 global $wp_query;
751 $course_post_type = tutor()->course_post_type;
752
753 if ( is_single() && ! empty( $wp_query->query['post_type'] ) && $wp_query->query['post_type'] === $course_post_type ) {
754 return true;
755 }
756 return false;
757 }
758 }
759
760 /**
761 * Require wp_date form return js date format
762 *
763 * this is helpfull for date picker
764 *
765 * @return string
766 *
767 * @since 1.9.7
768 */
769 if ( ! function_exists( 'tutor_js_date_format_against_wp' ) ) {
770 function tutor_js_date_format_against_wp() {
771 $wp_date_format = get_option( 'date_format' );
772 $default_format = 'yy-mm-dd';
773
774 $formats = array(
775 'Y-m-d' => 'yy-mm-dd',
776 'm/d/Y' => 'mm-dd-yy',
777 'd/m/Y' => 'dd-mm-yy',
778 'F j, Y' => 'MM dd, yy',
779 );
780 return isset( $formats[ $wp_date_format ] ) ? $formats[ $wp_date_format ] : $default_format;
781 }
782 }
783
784 /**
785 * Convert date to desire format
786 *
787 * @param $format string
788 *
789 * @param $date string
790 *
791 * @return string ( date )
792 */
793 if ( ! function_exists( 'tutor_get_formated_date' ) ) {
794 function tutor_get_formated_date( string $require_format, string $user_date ) {
795 return date( $require_format, strtotime( $user_date ) );
796 }
797 }
798
799 if(!function_exists('tutor_kses_allowed_html')) {
800 function tutor_kses_allowed_html($allowed_tags, $context) {
801 $tags = array('input', 'style', 'script', 'select', 'form', 'option', 'optgroup', 'iframe', 'bdi', 'source');
802 $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');
803
804 foreach($tags as $tag) {
805 $tag_attrs = array();
806
807 foreach($atts as $att) {
808 $tag_attrs[$att] = true;
809 }
810
811 $allowed_tags[$tag] = $tag_attrs;
812 }
813
814 return $allowed_tags;
815 }
816 }
817
818 if(!function_exists('tutor_kses_allowed_css')) {
819 function tutor_kses_allowed_css( $styles ) {
820 $styles[] = 'display';
821 return $styles;
822 }
823 }
824
825 if(!function_exists('tutor_kses_html')) {
826 function tutor_kses_html( $content ) {
827 add_filter( 'wp_kses_allowed_html', 'tutor_kses_allowed_html', 10, 2 );
828 add_filter( 'safe_style_css', 'tutor_kses_allowed_css' );
829
830 $content = preg_replace('/<!--(.|\s)*?-->/', '', $content);
831 $content = wp_kses_post( $content );
832 $content = str_replace('&amp;', '&', $content);
833
834 remove_filter( 'safe_style_css', 'tutor_kses_allowed_css' );
835 remove_filter( 'wp_kses_allowed_html', 'tutor_kses_allowed_html' );
836
837 return $content;
838 }
839 }