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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 5 years ago tutor-general-functions.php 5 years ago tutor-template-functions.php 5 years ago tutor-template-hook.php 5 years ago
tutor-general-functions.php
580 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 * @param $categories
87 * @param string $parent_name
88 *
89 * @return string
90 *
91 * Get selecting options, recursive supports
92 *
93 * @since v.1.3.4
94 */
95
96 if ( ! function_exists('_generate_categories_dropdown_option')){
97 function _generate_categories_dropdown_option($post_ID = 0, $categories = array(), $args = array(), $depth = 0){
98 $output = '';
99
100 if (!tutor_utils()->count($categories)) return $output;
101
102 if (!is_numeric($post_ID) || $post_ID < 1) return $output;
103
104 foreach ( $categories as $category_id => $category ) {
105 if (!$category->parent) $depth = 0;
106
107 $childrens = tutor_utils()->array_get( 'children', $category );
108 $has_in_term = has_term( $category->term_id, 'course-category', $post_ID );
109
110 $depth_seperator = '';
111 if ($depth){
112 for ($depth_i = 0; $depth_i < $depth; $depth_i++){
113 $depth_seperator.='-';
114 }
115 }
116
117 $output .= "<option value='{$category->term_id}' ".selected($has_in_term, true, false)." > {$depth_seperator} {$category->name}</option> ";
118
119 if ( tutor_utils()->count( $childrens ) ) {
120 $depth++;
121 $output .= _generate_categories_dropdown_option($post_ID,$childrens, $args, $depth);
122 }
123 }
124
125 return $output;
126 }
127 }
128
129 /**
130 * @param array $args
131 *
132 * @return string
133 *
134 * Generate course categories checkbox
135 * @since v.1.3.4
136 */
137
138 if ( ! function_exists('tutor_course_categories_checkbox')){
139 function tutor_course_categories_checkbox($post_ID = 0, $args = array()){
140 $default = array(
141 'name' => 'tax_input[course-category]',
142 );
143
144 $args = apply_filters('tutor_course_categories_checkbox_args', array_merge($default, $args));
145
146 if (isset($args['name'])){
147 $args['name'] = $args['name'].'[]';
148 }
149
150 extract($args);
151
152 $categories = tutor_utils()->get_course_categories();
153 $output = '';
154 $output .= __tutor_generate_categories_checkbox($post_ID, $categories, $args);
155
156 return $output;
157 }
158 }
159
160 /**
161 * @param $categories
162 * @param string $parent_name
163 * @param array $args
164 *
165 * @return string
166 *
167 * Internal function to generate course categories checkbox
168 *
169 * @since v.1.3.4
170 */
171 if ( ! function_exists('__tutor_generate_categories_checkbox')){
172 function __tutor_generate_categories_checkbox($post_ID = 0, $categories, $args = array()){
173 $output = '';
174 $input_name = tutor_utils()->array_get('name', $args);
175
176 if (tutor_utils()->count($categories)) {
177 $output .= "<ul class='tax-input-course-category'>";
178 foreach ( $categories as $category_id => $category ) {
179 $childrens = tutor_utils()->array_get( 'children', $category );
180 $has_in_term = has_term( $category->term_id, 'course-category', $post_ID );
181
182 $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>";
183
184 if ( tutor_utils()->count( $childrens ) ) {
185 $output .= __tutor_generate_categories_checkbox($post_ID,$childrens, $args);
186 }
187 $output .= " </li>";
188 }
189 $output .= "</ul>";
190 }
191 return $output;
192 }
193 }
194
195 /**
196 * @param string $content
197 * @param string $title
198 *
199 * @return string
200 *
201 * Wrap course builder sections within div for frontend
202 *
203 * @since v.1.3.4
204 */
205
206 if ( ! function_exists('course_builder_section_wrap')) {
207 function course_builder_section_wrap( $content = '', $title = '', $echo = true ) {
208 ob_start();
209 ?>
210 <div class="tutor-course-builder-section">
211 <div class="tutor-course-builder-section-title">
212 <h3><i class="tutor-icon-down"></i> <span><?php echo $title; ?></span></h3>
213 </div>
214 <div class="tutor-course-builder-section-content">
215 <?php echo $content; ?>
216 </div>
217 </div>
218 <?php
219 $html = ob_get_clean();
220
221 if ($echo){
222 echo $html;
223 }else{
224 return $html;
225 }
226 }
227 }
228
229
230 if ( ! function_exists('get_tutor_header')){
231 function get_tutor_header($fullScreen = false){
232 $enable_spotlight_mode = tutor_utils()->get_option('enable_spotlight_mode');
233
234 if ($enable_spotlight_mode || $fullScreen){
235 ?>
236 <!doctype html>
237 <html <?php language_attributes(); ?>>
238 <head>
239 <meta charset="<?php bloginfo( 'charset' ); ?>" />
240 <meta name="viewport" content="width=device-width, initial-scale=1" />
241 <link rel="profile" href="https://gmpg.org/xfn/11" />
242 <?php wp_head(); ?>
243 </head>
244 <body <?php body_class(); ?>>
245 <div id="tutor-page-wrap" class="tutor-site-wrap site">
246 <?php
247 }else{
248 get_header();
249 }
250
251 }
252 }
253
254 if (! function_exists('get_tutor_footer')){
255 function get_tutor_footer($fullScreen = false){
256 $enable_spotlight_mode = tutor_utils()->get_option('enable_spotlight_mode');
257 if ($enable_spotlight_mode || $fullScreen){
258 ?>
259 </div>
260 <?php wp_footer(); ?>
261
262 </body>
263 </html>
264 <?php
265 }else{
266 get_footer();
267 }
268 }
269 }
270
271 /**
272 * @param int $parent_id
273 * @param array $level_categories
274 *
275 * Generate Courses categories for Paid Memberships Pro
276 *
277 * @since v.1.3.6
278 */
279 if ( ! function_exists('generate_categories_for_pmpro')) {
280 function generate_categories_for_pmpro( $parent_id = 0, $level_categories = array() ) {
281 $args = array(
282 'taxonomy' => 'course-category',
283 'parent' => $parent_id,
284 'hide_empty' => false,
285 );
286 $cats = get_categories( apply_filters( 'course_categories_pmpro_args', $args ) );
287 if ( $cats ) {
288 foreach ( $cats as $cat ) {
289 $name = 'membershipcategory_' . $cat->term_id;
290 if ( ! empty( $level_categories ) ) {
291 $checked = checked( in_array( $cat->term_id, $level_categories ), true, false );
292 } else {
293 $checked = '';
294 }
295 echo "<ul><li class=membershipcategory><input type=checkbox name={$name} id={$name} value=yes {$checked}><label for={$name}>{$cat->name}</label>";
296 generate_categories_for_pmpro( $cat->term_id, $level_categories );
297 echo '</li></ul>';
298 }
299 }
300 }
301 }
302
303 /**
304 * @param null $key
305 * @param bool $default
306 *
307 * @return array|bool|mixed
308 *
309 * Get tutor option by this helper function
310 *
311 * @since v.1.3.6
312 */
313 if ( ! function_exists('get_tutor_option')){
314 function get_tutor_option($key = null, $default = false){
315 return tutils()->get_option($key, $default);
316 }
317 }
318
319 /**
320 * @param null $key
321 * @param bool $value
322 *
323 * Update tutor option by this helper function
324 *
325 * @since v.1.3.6
326 */
327 if ( ! function_exists('update_tutor_option')){
328 function update_tutor_option($key = null, $value = false){
329 tutils()->update_option($key, $value);
330 }
331 }
332 /**
333 * @param int $course_id
334 * @param null $key
335 * @param bool $default
336 *
337 * @return array|bool|mixed
338 *
339 * Get tutor course settings by course ID
340 *
341 * @since v.1.4.1
342 */
343 if ( ! function_exists('get_tutor_course_settings')) {
344 function get_tutor_course_settings( $course_id = 0, $key = null, $default = false ) {
345 return tutils()->get_course_settings( $course_id, $key, $default );
346 }
347 }
348
349 /**
350 * @param int $lesson_id
351 * @param null $key
352 * @param bool $default
353 *
354 * @return array|bool|mixed
355 *
356 * Get lesson content drip settings
357 */
358
359 if ( ! function_exists('get_item_content_drip_settings')){
360 function get_item_content_drip_settings($lesson_id = 0, $key = null, $default = false){
361 return tutils()->get_item_content_drip_settings( $lesson_id, $key, $default );
362 }
363 }
364
365 /**
366 * @param null $msg
367 * @param string $type
368 * @param bool $echo
369 *
370 * @return string
371 *
372 * Print Alert by tutor_alert()
373 *
374 * @since v.1.4.1
375 */
376 if ( ! function_exists('tutor_alert')){
377 function tutor_alert($msg = null, $type = 'warning', $echo = true){
378 if ( ! $msg){
379
380 if ($type === 'any'){
381 if ( ! $msg){
382 $type = 'warning';
383 $msg = tutor_flash_get($type);
384 }
385 if ( ! $msg){
386 $type = 'danger';
387 $msg = tutor_flash_get($type);
388 }
389 if ( ! $msg){
390 $type = 'success';
391 $msg = tutor_flash_get($type);
392 }
393
394 }else{
395 $msg = tutor_flash_get($type);
396 }
397
398
399 }
400 if ( ! $msg){
401 return $msg;
402 }
403
404 $html = "<div class='tutor-alert tutor-alert-{$type}'>{$msg}</div>";
405 if ($echo){
406 echo $html;
407 }
408 return $html;
409 }
410 }
411
412
413 /**
414 * @param bool $echo
415 *
416 * Simply call tutor_nonce_field() to generate nonce field
417 *
418 * @since v.1.4.2
419 */
420
421 if ( ! function_exists('tutor_nonce_field')) {
422 function tutor_nonce_field( $echo = true ) {
423 wp_nonce_field( tutor()->nonce_action, tutor()->nonce, $echo );
424 }
425 }
426
427 /**
428 * @param null $key
429 * @param string $message
430 *
431 * Set Flash Message
432 */
433
434 if ( ! function_exists('tutor_flash_set')) {
435 function tutor_flash_set( $key = null, $message = '' ) {
436 if ( ! $key ) {
437 return;
438 }
439 // ensure session is started
440 if ( session_status() !== PHP_SESSION_ACTIVE ) {
441 session_start();
442 }
443 $_SESSION[ $key ] = $message;
444 }
445 }
446
447 /**
448 * @param null $key
449 *
450 * @return array|bool|mixed|null
451 *
452 * @since v.1.4.2
453 *
454 * Get flash message
455 */
456
457 if ( ! function_exists('tutor_flash_get')) {
458 function tutor_flash_get( $key = null ) {
459 if ( $key ) {
460 // ensure session is started
461 if ( session_status() !== PHP_SESSION_ACTIVE ) {
462 @session_start();
463 }
464 if ( empty( $_SESSION ) ) {
465 return null;
466 }
467 $message = tutils()->array_get( $key, $_SESSION );
468 if ( $message ) {
469 unset( $_SESSION[ $key ] );
470 }
471 return $message;
472 }
473 return $key;
474 }
475 }
476
477 if ( ! function_exists('tutor_redirect_back')) {
478 /**
479 * @param null $url
480 *
481 * Redirect to back or a specific URL and terminate
482 *
483 * @since v.1.4.3
484 */
485 function tutor_redirect_back( $url = null ) {
486 if ( ! $url ) {
487 $url = tutils()->referer();
488 }
489 wp_safe_redirect( $url );
490 exit();
491 }
492 }
493
494 /**
495 * @param string $action
496 * @param bool $echo
497 *
498 * @return string
499 *
500 * @since v.1.4.3
501 */
502
503 if ( ! function_exists('tutor_action_field')) {
504 function tutor_action_field( $action = '', $echo = true ) {
505 $output = '';
506 if ( $action ) {
507 $output = "<input type='hidden' name='tutor_action' value='{$action}'>";
508 }
509
510 if ( $echo ) {
511 echo $output;
512 } else {
513 return $output;
514 }
515 }
516 }
517
518 /**
519 * @return int|string
520 *
521 * Return current Time from wordpress time
522 *
523 * @since v.1.4.3
524 */
525
526 if ( ! function_exists('tutor_time')) {
527 function tutor_time() {
528 //return current_time( 'timestamp' );
529 return time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
530 }
531 }
532
533 /**
534 * Toggle maintenance mode for the site.
535 *
536 * Creates/deletes the maintenance file to enable/disable maintenance mode.
537 *
538 * @since v.1.4.6
539 *
540 * @global WP_Filesystem_Base $wp_filesystem Subclass
541 *
542 * @param bool $enable True to enable maintenance mode, false to disable.
543 */
544 if ( ! function_exists('tutor_maintenance_mode')) {
545 function tutor_maintenance_mode( $enable = false ) {
546 $file = ABSPATH . '.tutor_maintenance';
547 if ( $enable ) {
548 // Create maintenance file to signal that we are upgrading
549 $maintenance_string = '<?php $upgrading = ' . time() . '; ?>';
550
551 if ( ! file_exists($file)){
552 file_put_contents($file, $maintenance_string);
553 }
554 } else{
555 if (file_exists($file)){
556 unlink($file);
557 }
558 }
559 }
560 }
561
562 /**
563 * @return bool
564 *
565 * Check if the current page is course single page
566 *
567 * @since v.1.6.0
568 */
569
570 if ( ! function_exists('is_single_course')) {
571 function is_single_course(){
572 global $wp_query;
573 $course_post_type = tutor()->course_post_type;
574
575 if (is_single() && !empty($wp_query->query['post_type']) && $wp_query->query['post_type'] === $course_post_type) {
576 return true;
577 }
578 return false;
579 }
580 }