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