PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 2.0.3
Tutor LMS – eLearning and online course solution v2.0.3
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-template-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-template-functions.php
1401 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit;
5 }
6
7 /**
8 * @param null $template
9 * @param bool $tutor_pro
10 *
11 * @return bool|string
12 *
13 * Load template with override file system
14 *
15 * @since v.1.0.0
16 * @updated v.1.4.2
17 * @updated v.1.4.3
18 */
19
20 if ( ! function_exists( 'tutor_get_template' ) ) {
21 function tutor_get_template( $template = null, $tutor_pro = false ) {
22 if ( ! $template ) {
23 return false;
24 }
25 $template = str_replace( '.', DIRECTORY_SEPARATOR, $template );
26
27 /**
28 * Get template first from child-theme if exists
29 * If child theme not exists, then get template from parent theme
30 */
31 $template_location = trailingslashit( get_stylesheet_directory() ) . "tutor/{$template}.php";
32 if ( ! file_exists( $template_location ) ) {
33 $template_location = trailingslashit( get_template_directory() ) . "tutor/{$template}.php";
34 }
35 $file_in_theme = $template_location;
36 if ( ! file_exists( $template_location ) ) {
37 $template_location = trailingslashit( tutor()->path ) . "templates/{$template}.php";
38
39 if ( $tutor_pro && function_exists( 'tutor_pro' ) ) {
40 $pro_template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
41 if ( file_exists( $pro_template_location ) ) {
42 $template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
43 }
44 }
45
46 if ( ! file_exists( $template_location ) ) {
47 echo '<div class="tutor-notice-warning"> ' . __( sprintf( 'The file you are trying to load does not exist in your theme or Tutor LMS plugin location. If you are extending the Tutor LMS plugin, please create a php file here: %s ', '<code>' . $file_in_theme . '</code>' ), 'tutor' ) . ' </div>';
48 }
49 }
50
51 return apply_filters( 'tutor_get_template_path', $template_location, $template );
52 }
53 }
54
55 /**
56 * @param null $template
57 * @param bool $tutor_pro
58 *
59 * @return bool|mixed|void
60 *
61 * Get only template path without any warning...
62 *
63 * @since v.1.4.2
64 */
65 if ( ! function_exists( 'tutor_get_template_path' ) ) {
66 function tutor_get_template_path( $template = null, $tutor_pro = false ) {
67 if ( ! $template ) {
68 return false;
69 }
70 $template = str_replace( '.', DIRECTORY_SEPARATOR, $template );
71
72 /**
73 * Get template first from child-theme if exists
74 * If child theme not exists, then get template from parent theme
75 */
76 $template_location = trailingslashit( get_stylesheet_directory() ) . "tutor/{$template}.php";
77 if ( ! file_exists( $template_location ) ) {
78 $template_location = trailingslashit( get_template_directory() ) . "tutor/{$template}.php";
79 }
80 if ( ! file_exists( $template_location ) ) {
81 $template_location = trailingslashit( tutor()->path ) . "templates/{$template}.php";
82 }
83 if ( ! file_exists( $template_location ) && $tutor_pro && function_exists( 'tutor_pro' ) ) {
84 $template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
85 }
86
87 return apply_filters( 'tutor_get_template_path', $template_location, $template );
88 }
89 }
90
91 /**
92 * @param null $template
93 *
94 * @param array $variables
95 *
96 * Load template for TUTOR
97 *
98 * @since v.1.0.0
99 *
100 * @updated v.1.1.2
101 */
102
103 if ( ! function_exists( 'tutor_load_template' ) ) {
104 function tutor_load_template( $template = null, $variables = array(), $tutor_pro = false ) {
105 $variables = (array) $variables;
106 $variables = apply_filters( 'get_tutor_load_template_variables', $variables );
107 extract( $variables );
108
109 $isLoad = apply_filters( 'should_tutor_load_template', true, $template, $variables );
110 if ( ! $isLoad ) {
111 return;
112 }
113
114 do_action( 'tutor_load_template_before', $template, $variables );
115 include tutor_get_template( $template, $tutor_pro );
116 do_action( 'tutor_load_template_after', $template, $variables );
117 }
118 }
119
120 /**
121 * @param null $template
122 * @param array $variables
123 * @param bool $tutor_pro
124 *
125 * @since v.1.4.3
126 */
127
128 if ( ! function_exists( 'tutor_load_template_part' ) ) {
129 function tutor_load_template_part( $template = null, $variables = array(), $tutor_pro = false ) {
130 $variables = (array) $variables;
131 $variables = apply_filters( 'get_tutor_load_template_variables', $variables );
132 extract( $variables );
133
134 /**
135 * Get template first from child-theme if exists
136 * If child theme not exists, then get template from parent theme
137 */
138 $template_location = trailingslashit( get_stylesheet_directory() ) . 'tutor/template.php';
139 if ( ! file_exists( $template_location ) ) {
140 $template_location = trailingslashit( get_template_directory() ) . 'tutor/template.php';
141 }
142
143 if ( ! file_exists( $template_location ) ) {
144 $template_location = trailingslashit( tutor()->path ) . 'templates/template.php';
145 if ( ! file_exists( $template_location ) && $tutor_pro && function_exists( 'tutor_pro' ) ) {
146 $template_location = trailingslashit( tutor_pro()->path ) . 'templates/template.php';
147 }
148 }
149
150 include apply_filters( 'tutor_get_template_part_path', $template_location, $template );
151 }
152 }
153
154 /**
155 * @param $template_name
156 * @param array $variables
157 *
158 * @return string
159 *
160 * @since v.1.4.3
161 */
162
163 if ( ! function_exists( 'tutor_get_template_html' ) ) {
164 function tutor_get_template_html( $template_name, $variables = array(), $tutor_pro = false ) {
165 ob_start();
166 tutor_load_template( $template_name, $variables, $tutor_pro );
167
168 return ob_get_clean();
169 }
170 }
171
172 if ( ! function_exists( 'tutor_course_loop_start' ) ) {
173 function tutor_course_loop_start( $echo = true ) {
174 ob_start();
175 tutor_load_template( 'loop.loop-start' );
176 $output = apply_filters( 'tutor_course_loop_start', ob_get_clean() );
177
178 if ( $echo ) {
179 echo tutor_kses_html( $output );
180 }
181 return $output;
182 }
183 }
184
185 if ( ! function_exists( 'tutor_course_loop_end' ) ) {
186 function tutor_course_loop_end( $echo = true ) {
187 ob_start();
188 tutor_load_template( 'loop.loop-end' );
189
190 $output = apply_filters( 'tutor_course_loop_end', ob_get_clean() );
191 if ( $echo ) {
192 echo tutor_kses_html( $output );
193 }
194
195 return $output;
196 }
197 }
198
199 function tutor_course_loop_before_content() {
200 ob_start();
201 tutor_load_template( 'loop.loop-before-content' );
202
203 $output = apply_filters( 'tutor_course_loop_before_content', ob_get_clean() );
204 echo tutor_kses_html( $output );
205 }
206
207 function tutor_course_loop_after_content() {
208 ob_start();
209 tutor_load_template( 'loop.loop-after-content' );
210
211 $output = apply_filters( 'tutor_course_loop_after_content', ob_get_clean() );
212 echo tutor_kses_html( $output );
213 }
214
215 if ( ! function_exists( 'tutor_course_loop_title' ) ) {
216 function tutor_course_loop_title() {
217 ob_start();
218 tutor_load_template( 'loop.title' );
219 $output = apply_filters( 'tutor_course_loop_title', ob_get_clean() );
220
221 echo tutor_kses_html( $output );
222 }
223 }
224
225
226 if ( ! function_exists( 'tutor_course_loop_header' ) ) {
227 function tutor_course_loop_header() {
228 ob_start();
229 tutor_load_template( 'loop.header' );
230 $output = apply_filters( 'tutor_course_loop_header', ob_get_clean() );
231
232 echo tutor_kses_html( $output );
233 }
234 }
235
236 if ( ! function_exists( 'tutor_course_loop_footer' ) ) {
237 function tutor_course_loop_footer() {
238 ob_start();
239 tutor_load_template( 'loop.footer' );
240 $output = apply_filters( 'tutor_course_loop_footer', ob_get_clean() );
241
242 echo tutor_kses_html( $output );
243 }
244 }
245
246 // tutor_course_loop_footer
247
248
249 if ( ! function_exists( 'tutor_course_loop_start_content_wrap' ) ) {
250 function tutor_course_loop_start_content_wrap() {
251 ob_start();
252 tutor_load_template( 'loop.start_content_wrap' );
253 $output = apply_filters( 'tutor_course_loop_start_content_wrap', ob_get_clean() );
254
255 echo tutor_kses_html( $output );
256 }
257 }
258
259 if ( ! function_exists( 'tutor_course_loop_end_content_wrap' ) ) {
260 function tutor_course_loop_end_content_wrap() {
261 ob_start();
262 tutor_load_template( 'loop.end_content_wrap' );
263 $output = apply_filters( 'tutor_course_loop_end_content_wrap', ob_get_clean() );
264
265 echo tutor_kses_html( $output );
266 }
267 }
268
269 if ( ! function_exists( 'tutor_course_loop_thumbnail' ) ) {
270 function tutor_course_loop_thumbnail( $echo = true ) {
271 ob_start();
272 tutor_load_template( 'loop.thumbnail' );
273 $output = apply_filters( 'tutor_course_loop_thumbnail', ob_get_clean() );
274
275 if ( $echo ) {
276 echo tutor_kses_html( $output );
277 } else {
278 return $output;
279 }
280 }
281 }
282
283 if ( ! function_exists( 'tutor_course_loop_wrap_classes' ) ) {
284 function tutor_course_loop_wrap_classes( $echo = true ) {
285 $courseID = get_the_ID();
286 $classes = apply_filters(
287 'tutor_course_loop_wrap_classes',
288 array(
289 'tutor-course',
290 'tutor-course-loop',
291 'tutor-course-loop-' . $courseID,
292 )
293 );
294
295 $class = implode( ' ', $classes );
296 if ( $echo ) {
297 echo esc_attr( $class );
298 }
299
300 return esc_attr( $class );
301 }
302 }
303
304 if ( ! function_exists( 'tutor_course_loop_col_classes' ) ) {
305 function tutor_course_loop_col_classes( $echo = true ) {
306 $course_filter = (bool) tutor_utils()->get_option( 'course_archive_filter', false );
307 $course_archive_arg = isset( $GLOBALS['tutor_course_archive_arg'] ) ? $GLOBALS['tutor_course_archive_arg']['column_per_row'] : null;
308 $course_cols = $course_archive_arg === null ? tutor_utils()->get_option( 'courses_col_per_row', 3 ) : $course_archive_arg;
309 $classes = apply_filters(
310 'tutor_course_loop_col_classes',
311 array(
312 'tutor-col-' . $course_cols,
313 )
314 );
315
316 $class = implode( ' ', $classes );
317 if ( $echo ) {
318 echo esc_attr( $class );
319 }
320
321 return esc_attr( $class );
322 }
323 }
324
325
326 if ( ! function_exists('tutor_container_classes')) {
327 function tutor_container_classes( $echo = true ) {
328
329 $classes = apply_filters( 'tutor_container_classes', array(
330 'tutor-wrap tutor-courses-wrap',
331 'tutor-container'
332 ) );
333
334 $classes = apply_filters(
335 'tutor_container_classes',
336 array(
337 'tutor-wrap tutor-courses-wrap',
338 'tutor-container',
339 )
340 );
341
342 $class = implode( ' ', $classes );
343
344 if ( $echo ) {
345 echo esc_attr( $class );
346 }
347
348 return esc_attr( $class );
349 }
350 }
351 if ( ! function_exists( 'tutor_post_class' ) ) {
352 function tutor_post_class( $default = '' ) {
353 $classes = apply_filters(
354 'tutor_post_class',
355 array(
356 'tutor-wrap',
357 $default,
358 )
359 );
360
361 post_class( $classes );
362 }
363 }
364
365 /**
366 *
367 * Get classes for widget loop single course wrap
368 *
369 * @param bool $echo
370 *
371 * @return string
372 *
373 * @since v.1.3.1
374 */
375 if ( ! function_exists( 'tutor_widget_course_loop_classes' ) ) {
376 function tutor_widget_course_loop_classes( $echo = true ) {
377
378 $classes = apply_filters(
379 'tutor_widget_course_loop_classes',
380 array(
381 'tutor-widget-course-loop',
382 'tutor-widget-course',
383 'tutor-widget-course-' . get_the_ID(),
384 )
385 );
386
387 $class = implode( ' ', $classes );
388 if ( $echo ) {
389 echo esc_attr( $class );
390 }
391
392 return esc_attr( $class );
393 }
394 }
395
396 /**
397 * Get the post thumbnail
398 */
399 if ( ! function_exists('get_tutor_course_thumbnail')) {
400 function get_tutor_course_thumbnail($size = 'post-thumbnail', $url = false) {
401 $post_id = get_the_ID();
402 $size = apply_filters( 'tutor_course_thumbnail_size', $size, $post_id );
403 $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id );
404 $placeHolderUrl = tutor()->url . 'assets/images/placeholder.svg';
405 $thumb_url = $post_thumbnail_id ? wp_get_attachment_image_url($post_thumbnail_id, $size) : $placeHolderUrl;
406
407 if($url) {
408 return $thumb_url;
409 }
410
411 echo '<div class="tutor-course-thumbnail">
412 <img src="' . $thumb_url . '" />
413 </div>';
414 }
415 }
416 /**
417 * Get the course/post thumbnail src
418 */
419 if ( ! function_exists( 'get_tutor_course_thumbnail_src' ) ) {
420 function get_tutor_course_thumbnail_src( $size = 'post-thumbnail' ) {
421 $post_id = get_the_ID();
422 $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id );
423
424 if ( $post_thumbnail_id ) {
425 $size = apply_filters( 'tutor_course_thumbnail_size', $size, $post_id );
426 $src = wp_get_attachment_image_url( $post_thumbnail_id, $size, false );
427 } else {
428 $src = tutor()->url . 'assets/images/placeholder.svg';
429 }
430
431 return $src;
432 }
433 }
434
435 if ( ! function_exists( 'tutor_course_loop_meta' ) ) {
436 function tutor_course_loop_meta() {
437 ob_start();
438 tutor_load_template( 'loop.meta' );
439 $output = apply_filters( 'tutor_course_loop_meta', ob_get_clean() );
440
441 echo tutor_kses_html( $output );
442 }
443 }
444
445 /**
446 * Get course author name in loop
447 *
448 * @since: v.1.0.0
449 */
450
451 if ( ! function_exists( 'tutor_course_loop_author' ) ) {
452 function tutor_course_loop_author() {
453 ob_start();
454 tutor_load_template( 'loop.course-author' );
455 $output = apply_filters( 'tutor_course_loop_author', ob_get_clean() );
456
457 echo $output;
458 }
459 }
460
461 /**
462 * Get formatted price with cart form
463 */
464
465 if ( ! function_exists('tutor_course_loop_price')) {
466 function tutor_course_loop_price() {
467 $course_id = get_the_ID();
468
469 ob_start();
470
471 if(tutor_utils()->is_enrolled($course_id) || get_post_meta($course_id, '_tutor_is_public_course', true)=='yes'){
472 tutor_load_template( 'loop.course-continue' );
473
474 } else if(tutor_utils()->is_course_added_to_cart($course_id)){
475 tutor_load_template( 'loop.course-in-cart' );
476
477 } else {
478 $tutor_course_sell_by = apply_filters('tutor_course_sell_by', null);
479
480 if ($tutor_course_sell_by){
481 tutor_load_template( 'loop.course-price-'.$tutor_course_sell_by );
482 } else {
483 tutor_load_template( 'loop.course-price' );
484 }
485 }
486
487 echo apply_filters( 'tutor_course_loop_price', ob_get_clean() );
488 }
489 }
490
491 /**
492 * Get Course rating
493 *
494 * @since v.1.0.0
495 * @updated v.1.4.5
496 */
497
498 if ( ! function_exists( 'tutor_course_loop_rating' ) ) {
499 function tutor_course_loop_rating() {
500
501 $disable = !get_tutor_option('enable_course_review');
502 if ($disable){
503 return;
504 }
505
506 ob_start();
507 tutor_load_template( 'loop.rating' );
508 $output = apply_filters( 'tutor_course_loop_rating', ob_get_clean() );
509
510 echo tutor_kses_html( $output );
511 }
512 }
513
514 /**
515 * @param bool $echo
516 *
517 * @return mixed|void
518 *
519 * Get add to cart form
520 */
521
522 if ( ! function_exists( 'tutor_course_loop_add_to_cart' ) ) {
523 function tutor_course_loop_add_to_cart( $echo = true ) {
524 ob_start();
525 $tutor_course_sell_by = apply_filters( 'tutor_course_sell_by', null );
526
527 if ( $tutor_course_sell_by ) {
528 tutor_load_template( 'loop.add-to-cart-' . $tutor_course_sell_by );
529 }
530
531 $output = apply_filters( 'tutor_course_loop_add_to_cart_link', ob_get_clean() );
532
533 if ( $echo ) {
534 echo wp_kses_post($output);
535 }
536 return $output;
537 }
538 }
539
540 if ( ! function_exists( 'tutor_course_price' ) ) {
541 function tutor_course_price() {
542 ob_start();
543 tutor_load_template( 'single.course.wc-price-html' );
544 $output = apply_filters( 'tutor_course_price', ob_get_clean() );
545
546 echo $output;
547 }
548 }
549
550 /**
551 * @param int $post_id
552 *
553 * echo the excerpt of TUTOR post type
554 *
555 * @since: v.1.0.0
556 */
557 if ( ! function_exists( 'tutor_the_excerpt' ) ) {
558 function tutor_the_excerpt( $post_id = 0 ) {
559 if ( ! $post_id ) {
560 $post_id = get_the_ID();
561 }
562 echo tutor_get_the_excerpt( $post_id );
563 }
564 }
565 /**
566 * @param int $post_id
567 *
568 * @return mixed
569 *
570 * Return excerpt of TUTOR post type
571 *
572 * @since: v.1.0.0
573 */
574 if ( ! function_exists( 'tutor_get_the_excerpt' ) ) {
575 function tutor_get_the_excerpt( $post_id = 0 ) {
576 if ( ! $post_id ) {
577 $post_id = get_the_ID();
578 }
579
580 $get_post = get_post( $post_id );
581 return apply_filters( 'tutor_get_the_excerpt', $get_post->post_excerpt );
582 }
583 }
584
585 /**
586 * @return mixed
587 *
588 * return course author
589 *
590 * @since: v.1.0.0
591 */
592
593 if ( ! function_exists( 'get_tutor_course_author' ) ) {
594 function get_tutor_course_author() {
595 global $post;
596 return apply_filters( 'get_tutor_course_author', get_the_author_meta( 'display_name', $post->post_author ) );
597 }
598 }
599
600 function get_tutor_course_author_id() {
601 global $post;
602 return (int) $post->post_author;
603 }
604
605 /**
606 * @param int $course_id
607 *
608 * @return mixed
609 * Course benefits return array
610 *
611 * @since: v.1.0.0
612 */
613
614 if ( ! function_exists( 'tutor_course_benefits' ) ) {
615 function tutor_course_benefits( $course_id = 0 ) {
616 if ( ! $course_id ) {
617 $course_id = get_the_ID();
618 }
619 $benefits = get_post_meta( $course_id, '_tutor_course_benefits', true );
620
621 $benefits_array = array();
622 if ( $benefits ) {
623 $benefits_array = explode( "\n", $benefits );
624 }
625
626 $array = array_filter( array_map( 'trim', $benefits_array ) );
627
628 return apply_filters( 'tutor_course/single/benefits', $array, $course_id );
629 }
630 }
631
632 /**
633 * @param bool $echo
634 *
635 * @return mixed
636 *
637 * Course single page benefits
638 *
639 * @since: v.1.0.0
640 */
641
642 if ( ! function_exists( 'tutor_course_benefits_html' ) ) {
643 function tutor_course_benefits_html( $echo = true ) {
644 ob_start();
645 tutor_load_template( 'single.course.course-benefits' );
646 $output = apply_filters( 'tutor_course/single/benefits_html', ob_get_clean() );
647
648 if ( $echo ) {
649 echo wp_kses_post($output);
650 }
651 return $output;
652 }
653 }
654
655 /**
656 * @param bool $echo
657 *
658 * @return mixed|void
659 *
660 * Return Topics HTML
661 *
662 * @since: v.1.0.0
663 */
664 if ( ! function_exists( 'tutor_course_topics' ) ) {
665 function tutor_course_topics( $echo = true ) {
666 ob_start();
667 tutor_load_template( 'single.course.course-topics' );
668 $output = apply_filters( 'tutor_course/single/topics', ob_get_clean() );
669 wp_reset_postdata();
670
671 if ( $echo ) {
672 echo tutor_kses_html( $output );
673 }
674
675 return $output;
676 }
677 }
678
679 /**
680 * @param int $course_id
681 *
682 * @return mixed|void
683 *
684 * return course requirements in array
685 *
686 * @since: v.1.0.0
687 */
688 if ( ! function_exists( 'tutor_course_requirements' ) ) {
689 function tutor_course_requirements( $course_id = 0 ) {
690 if ( ! $course_id ) {
691 $course_id = get_the_ID();
692 }
693 $requirements = get_post_meta( $course_id, '_tutor_course_requirements', true );
694
695 $requirements_array = array();
696 if ( $requirements ) {
697 $requirements_array = explode( "\n", $requirements );
698 }
699
700 $array = array_filter( array_map( 'trim', $requirements_array ) );
701 return apply_filters( 'tutor_course/single/requirements', $array, $course_id );
702 }
703 }
704
705 /**
706 * @param bool $echo
707 *
708 * @return mixed|void
709 *
710 * Return course requirements in course single page
711 *
712 * @since: v.1.0.0
713 */
714 if ( ! function_exists('tutor_course_requirements_html')) {
715 function tutor_course_requirements_html($echo = true) {
716 ob_start();
717 tutor_course_material_includes_html();
718 tutor_load_template( 'single.course.course-requirements' );
719 $output = apply_filters( 'tutor_course/single/requirements_html', ob_get_clean() );
720
721 if ( $echo ) {
722 echo tutor_kses_html( $output );
723 }
724 return $output;
725 }
726 }
727
728
729 /**
730 * @param int $course_id
731 *
732 * @return mixed|void
733 *
734 * Return target audience in course single page
735 *
736 * @since: v.1.0.0
737 */
738 if ( ! function_exists( 'tutor_course_target_audience' ) ) {
739 function tutor_course_target_audience( $course_id = 0 ) {
740 if ( ! $course_id ) {
741 $course_id = get_the_ID();
742 }
743 $target_audience = get_post_meta( $course_id, '_tutor_course_target_audience', true );
744
745 $target_audience_array = array();
746 if ( $target_audience ) {
747 $target_audience_array = explode( "\n", $target_audience );
748 }
749
750 $array = array_filter( array_map( 'trim', $target_audience_array ) );
751 return apply_filters( 'tutor_course/single/target_audience', $array, $course_id );
752 }
753 }
754
755 /**
756 * @param bool $echo
757 *
758 * @return mixed|void
759 *
760 * Return target audience in course single page
761 *
762 * @since: v.1.0.0
763 */
764 if ( ! function_exists( 'tutor_course_target_audience_html' ) ) {
765 function tutor_course_target_audience_html( $echo = true ) {
766 ob_start();
767 tutor_load_template( 'single.course.course-target-audience' );
768 $output = apply_filters( 'tutor_course/single/audience_html', ob_get_clean() );
769
770 if ( $echo ) {
771 echo tutor_kses_html( $output );
772 }
773 return $output;
774 }
775 }
776
777
778 if ( ! function_exists( 'tutor_course_material_includes' ) ) {
779 function tutor_course_material_includes( $course_id = 0 ) {
780 if ( ! $course_id ) {
781 $course_id = get_the_ID();
782 }
783 $target_audience = get_post_meta( $course_id, '_tutor_course_material_includes', true );
784
785 $target_audience_array = array();
786 if ( $target_audience ) {
787 $target_audience_array = explode( "\n", $target_audience );
788 }
789
790 $array = array_filter( array_map( 'trim', $target_audience_array ) );
791 return apply_filters( 'tutor_course/single/material_includes', $array, $course_id );
792 }
793 }
794
795 if ( ! function_exists( 'tutor_course_material_includes_html' ) ) {
796 function tutor_course_material_includes_html( $echo = true ) {
797 ob_start();
798 tutor_load_template( 'single.course.material-includes' );
799 $output = apply_filters( 'tutor_course/single/material_includes', ob_get_clean() );
800
801 if ( $echo ) {
802 echo tutor_kses_html( $output );
803 }
804 return $output;
805 }
806 }
807
808 // tutor_course_material_includes_html
809
810
811 if ( ! function_exists( 'tutor_course_instructors_html' ) ) {
812 function tutor_course_instructors_html( $echo = true ) {
813 $display_course_instructors = tutor_utils()->get_option( 'display_course_instructors' );
814 if ( ! $display_course_instructors ) {
815 return null;
816 }
817
818 ob_start();
819 tutor_load_template( 'single.course.instructors' );
820 $output = apply_filters( 'tutor_course/single/instructors_html', ob_get_clean() );
821
822 if ( $echo ) {
823 echo tutor_kses_html( $output );
824 }
825 return $output;
826 }
827 }
828
829 if ( ! function_exists('tutor_course_target_reviews_html')) {
830 function tutor_course_target_reviews_html($echo = true) {
831 ob_start();
832 tutor_load_template( 'single.course.reviews' );
833
834 $output = apply_filters( 'tutor_course/single/reviews_html', ob_get_clean() );
835
836 if ( $echo ) {
837 echo tutor_kses_html( $output );
838 }
839 return $output;
840 }
841 }
842
843 /**
844 * @param bool $echo
845 *
846 * @return mixed
847 *
848 * Course single page main content / description
849 *
850 * @since: v.1.0.0
851 */
852 if ( ! function_exists( 'tutor_course_content' ) ) {
853 function tutor_course_content( $echo = true ) {
854 ob_start();
855 tutor_load_template( 'single.course.course-content' );
856 $output = apply_filters( 'tutor_course/single/content', ob_get_clean() );
857
858 if ( $echo ) {
859 echo tutor_kses_html( $output );
860 }
861
862 return $output;
863 }
864 }
865
866 /**
867 * Course single page lead info
868 *
869 * @since: v.1.0.0
870 */
871 if ( ! function_exists( 'tutor_course_lead_info' ) ) {
872 function tutor_course_lead_info( $echo = true ) {
873 ob_start();
874
875 // exit('failed');
876
877 $course_id = get_the_ID();
878 $course_post_type = tutor()->course_post_type;
879 $queryCourse = new WP_Query(
880 array(
881 'p' => $course_id,
882 'post_type' => $course_post_type,
883 )
884 );
885
886 if ( $queryCourse->have_posts() ) {
887 while ( $queryCourse->have_posts() ) {
888 $queryCourse->the_post();
889 tutor_load_template( 'single.course.lead-info' );
890 }
891 wp_reset_postdata();
892 }
893
894 $output = apply_filters( 'tutor_course/single/lead_info', ob_get_clean() );
895
896 if ( $echo ) {
897 echo tutor_kses_html( $output );
898 }
899 return $output;
900 }
901 }
902
903 /**
904 * @param bool $echo
905 *
906 * @return mixed|void
907 */
908
909 if ( ! function_exists('tutor_course_enrolled_lead_info')) {
910 function tutor_course_enrolled_lead_info( $echo = true ) {
911 ob_start();
912
913 $course_id = get_the_ID();
914 $course_post_type = tutor()->course_post_type;
915 $queryCourse = new WP_Query( array( 'p' => $course_id, 'post_type' => $course_post_type ) );
916
917 if ( $queryCourse->have_posts() ) {
918 while ( $queryCourse->have_posts() ) {
919 $queryCourse->the_post();
920 tutor_load_template( 'single.course.lead-info' );
921 }
922 wp_reset_postdata();
923 }
924
925 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
926
927 if ( $echo ) {
928 echo tutor_kses_html( $output );
929 }
930
931 return $output;
932 }
933 }
934
935 if ( ! function_exists('tutor_lesson_lead_info')) {
936 function tutor_lesson_lead_info( $lesson_id = 0, $echo = true ) {
937 if ( ! $lesson_id ) {
938 $lesson_id = get_the_ID();
939 }
940
941 ob_start();
942 $course_id = tutor_utils()->get_course_id_by( 'lesson', $lesson_id );
943 $course_post_type = tutor()->course_post_type;
944 $queryCourse = new WP_Query( array( 'p' => $course_id, 'post_type' => $course_post_type ) );
945
946 if ( $queryCourse->have_posts() ) {
947 while ( $queryCourse->have_posts() ) {
948 $queryCourse->the_post();
949 tutor_load_template( 'single.course.lead-info' );
950 }
951 wp_reset_postdata();
952 }
953 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
954
955 if ( $echo ) {
956 echo $output;
957 }
958
959 return $output;
960
961 }
962 }
963
964 if ( ! function_exists( 'tutor_course_video' ) ) {
965 function tutor_course_video( $echo = true ) {
966 ob_start();
967 tutor_load_template( 'single.video.video' );
968 $output = apply_filters( 'tutor_course/single/video', ob_get_clean() );
969
970 if ( $echo ) {
971 echo $output;
972 }
973 return $output;
974 }
975 }
976
977 if ( ! function_exists( 'tutor_lesson_video' ) ) {
978 function tutor_lesson_video( $echo = true ) {
979 ob_start();
980 tutor_load_template( 'single.video.video' );
981 $output = apply_filters( 'tutor_lesson/single/video', ob_get_clean() );
982
983 if ( $echo ) {
984 echo tutor_kses_html( $output );
985 }
986 return $output;
987 }
988 }
989
990 /**
991 *
992 * Get all lessons attachments
993 *
994 * @param bool $echo
995 *
996 * @return mixed
997 *
998 * @since v.1.0.0
999 */
1000 if ( ! function_exists( 'get_tutor_posts_attachments' ) ) {
1001 function get_tutor_posts_attachments( $echo = true ) {
1002 ob_start();
1003 tutor_load_template( 'global.attachments' );
1004 $output = apply_filters( 'tutor_lesson/single/attachments', ob_get_clean() );
1005
1006 if ( $echo ) {
1007 echo tutor_kses_html( $output );
1008 }
1009 return $output;
1010 }
1011 }
1012
1013 /**
1014 * @param bool $echo
1015 *
1016 * @return mixed
1017 *
1018 * Render Lesson Main Content
1019 * @since v.1.0.0
1020 */
1021 if ( ! function_exists( 'tutor_lesson_content' ) ) {
1022 function tutor_lesson_content( $echo = true ) {
1023 ob_start();
1024 tutor_load_template( 'single.lesson.content' );
1025 $output = apply_filters( 'tutor_lesson/single/content', ob_get_clean() );
1026
1027 if ( $echo ) {
1028 echo $output;
1029 }
1030
1031 return $output;
1032 }
1033 }
1034
1035 if ( ! function_exists( 'tutor_lesson_mark_complete_html' ) ) {
1036 function tutor_lesson_mark_complete_html( $echo = true ) {
1037 ob_start();
1038 tutor_load_template( 'single.lesson.complete_form' );
1039 $output = apply_filters( 'tutor_lesson/single/complete_form', ob_get_clean() );
1040
1041 if ( $echo ) {
1042 echo tutor_kses_html( $output );
1043 }
1044
1045 return $output;
1046 }
1047 }
1048
1049 function tutor_course_question_and_answer( $echo = true ) {
1050 ob_start();
1051 tutor_load_template( 'single.course.enrolled.question_and_answer' );
1052 $output = apply_filters( 'tutor_course/single/question_and_answer', ob_get_clean() );
1053
1054 if ( $echo ) {
1055 echo $output;
1056 }
1057
1058 return $output;
1059 }
1060
1061 /**
1062 * @param bool $echo
1063 *
1064 * @return mixed
1065 *
1066 * @show progress bar about course complete
1067 *
1068 * @since v.2.0.0
1069 */
1070
1071 function tutor_course_info_tab() {
1072 tutor_course_content();
1073 tutor_course_benefits_html();
1074 tutor_course_instructors_html();
1075 }
1076
1077
1078 function tutor_course_announcements( $echo = true ) {
1079 ob_start();
1080 tutor_load_template( 'single.course.enrolled.announcements' );
1081 $output = apply_filters( 'tutor_course/single/announcements', ob_get_clean() );
1082
1083 if ( $echo ) {
1084 echo $output;
1085 }
1086
1087 return $output;
1088 }
1089
1090 function tutor_single_quiz_top( $echo = true ) {
1091 ob_start();
1092 tutor_load_template( 'single.quiz.top' );
1093 $output = apply_filters( 'tutor_single_quiz/top', ob_get_clean() );
1094
1095 if ( $echo ) {
1096 echo $output;
1097 }
1098 return $output;
1099 }
1100
1101 function tutor_single_quiz_body( $echo = true ) {
1102 ob_start();
1103 tutor_load_template( 'single.quiz.body' );
1104 $output = apply_filters( 'tutor_single_quiz/body', ob_get_clean() );
1105
1106 if ( $echo ) {
1107 echo $output;
1108 }
1109 return $output;
1110 }
1111
1112 /**
1113 * @param bool $echo
1114 *
1115 * @return mixed|void
1116 *
1117 * Get the quiz description
1118 */
1119 function tutor_single_quiz_content( $echo = true ) {
1120 ob_start();
1121 tutor_load_template( 'single.quiz.content' );
1122 $output = apply_filters( 'tutor_single_quiz/content', ob_get_clean() );
1123
1124 if ( $echo ) {
1125 echo $output;
1126 }
1127 return $output;
1128 }
1129
1130
1131 function tutor_single_quiz_no_course_belongs( $echo = true ) {
1132 ob_start();
1133 tutor_load_template( 'single.quiz.no_course_belongs' );
1134 $output = apply_filters( 'tutor_single_quiz/no_course_belongs', ob_get_clean() );
1135
1136 if ( $echo ) {
1137 echo $output;
1138 }
1139 return $output;
1140 }
1141
1142 function single_quiz_contents( $echo = true ) {
1143
1144 ob_start();
1145 tutor_load_template( 'single.quiz.single_quiz_contents' );
1146 $output = apply_filters( 'tutor_single_quiz/single_quiz_contents', ob_get_clean() );
1147
1148 if ( $echo ) {
1149 echo $output;
1150 }
1151 return $output;
1152 }
1153
1154 function get_tutor_course_level( $course_id = 0 ) {
1155 if ( ! $course_id ) {
1156 $course_id = get_the_ID();
1157 }
1158 if ( ! $course_id ) {
1159 return '';
1160 }
1161
1162 $course_level = get_post_meta( $course_id, '_tutor_course_level', true );
1163
1164 if ( $course_level ) {
1165 return tutor_utils()->course_levels( $course_level );
1166 }
1167 return false;
1168 }
1169
1170 if ( ! function_exists('get_tutor_course_duration_context')) {
1171 function get_tutor_course_duration_context( $course_id = 0, $short_form = false ) {
1172 if ( ! $course_id ) {
1173 $course_id = get_the_ID();
1174 }
1175 if ( ! $course_id ) {
1176 return '';
1177 }
1178 $duration = get_post_meta( $course_id, '_course_duration', true );
1179 $durationHours = tutor_utils()->avalue_dot( 'hours', $duration );
1180 $durationMinutes = tutor_utils()->avalue_dot( 'minutes', $duration );
1181 $durationSeconds = tutor_utils()->avalue_dot( 'seconds', $duration );
1182
1183 $hour_format = $short_form ? __( 'h', 'tutor' ) : ' '.($durationHours>1 ? __('hours', 'tutor') : __( 'hour', 'tutor' ));
1184 $minute_format = $short_form ? __( 'm', 'tutor' ) : ' '.($durationMinutes>1 ? __('minutes', 'tutor') : __( 'minute', 'tutor' ));
1185 $second_format = $short_form ? __( 's', 'tutor' ) : ' '.($durationSeconds>1 ? __('seconds', 'tutor') : __( 'second', 'tutor' ));
1186
1187 if ( $duration ) {
1188 $output = '';
1189 if ( $durationHours > 0 ) {
1190 $output .= '<span class="tutor-meta-level">' . ' ' . $durationHours . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $hour_format . '</span>';
1191 }
1192
1193 if ( $durationMinutes > 0 ) {
1194 $output .= '<span class="tutor-meta-level">' . ' ' . $durationMinutes . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $minute_format . '</span>';
1195 }
1196
1197 if ( !$durationHours && !$durationMinutes && $durationSeconds > 0 ) {
1198 $output .= '<span class="tutor-meta-level">' . ' ' . $durationSeconds . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $second_format . '</span>';
1199 }
1200
1201 return $output;
1202 }
1203
1204 return false;
1205 }
1206 }
1207 if ( ! function_exists( 'get_tutor_course_categories' ) ) {
1208 function get_tutor_course_categories( $course_id = 0 ) {
1209 if ( ! $course_id ) {
1210 $course_id = get_the_ID();
1211 }
1212 $terms = get_the_terms( $course_id, 'course-category' );
1213
1214 return $terms;
1215 }
1216 }
1217
1218 /**
1219 * @param int $course_id
1220 *
1221 * @return array|false|WP_Error
1222 *
1223 * Get course tags
1224 */
1225
1226 if ( ! function_exists( 'get_tutor_course_tags' ) ) {
1227 function get_tutor_course_tags( $course_id = 0 ) {
1228 if ( ! $course_id ) {
1229 $course_id = get_the_ID();
1230 }
1231 $terms = get_the_terms( $course_id, 'course-tag' );
1232
1233 return $terms;
1234 }
1235 }
1236
1237 /**
1238 * @param bool $echo
1239 *
1240 * @return mixed|void
1241 *
1242 * Template for course tags html
1243 */
1244
1245 if ( ! function_exists( 'tutor_course_tags_html' ) ) {
1246 function tutor_course_tags_html( $echo = true ) {
1247 ob_start();
1248 tutor_load_template( 'single.course.tags' );
1249 $output = apply_filters( 'tutor_course/single/tags_html', ob_get_clean() );
1250
1251 if ( $echo ) {
1252 echo tutor_kses_html( $output );
1253 }
1254
1255 return $output;
1256 }
1257 }
1258
1259 /**
1260 * @param bool $echo
1261 *
1262 * @return mixed
1263 *
1264 * Get Q&A in lesson sidebar
1265 */
1266
1267 if ( ! function_exists( 'tutor_lesson_sidebar_question_and_answer' ) ) {
1268 function tutor_lesson_sidebar_question_and_answer( $echo = true ) {
1269 ob_start();
1270 tutor_load_template( 'single.lesson.sidebar_question_and_answer' );
1271 $output = apply_filters( 'tutor_lesson/single/sidebar_question_and_answer', ob_get_clean() );
1272
1273 if ( $echo ) {
1274 echo tutor_kses_html( $output );
1275 }
1276
1277 return $output;
1278 }
1279 }
1280
1281 /**
1282 * @param bool $echo
1283 *
1284 * @return mixed
1285 *
1286 * Get Assignment content
1287 *
1288 * @since v.1.3.3
1289 */
1290
1291 if ( ! function_exists( 'tutor_assignment_content' ) ) {
1292 function tutor_assignment_content( $echo = true ) {
1293 ob_start();
1294 tutor_load_template( 'single.assignment.content' );
1295 $output = apply_filters( 'tutor_assignment/single/content', ob_get_clean() );
1296
1297 if ( $echo ) {
1298 echo tutor_kses_html( $output );
1299 }
1300
1301 return $output;
1302 }
1303 }
1304
1305 /**
1306 * @param string $msg
1307 * @param string $title
1308 * @param string $type
1309 *
1310 * @return string
1311 *
1312 * @since v.1.4.0
1313 */
1314
1315 if ( ! function_exists( 'get_tnotice' ) ) {
1316 function get_tnotice( $msg = '', $title = 'Success', $type = 'success' ) {
1317
1318 $output = '<div class="tnotice tnotice--' . $type . '">
1319 <div class="tnotice__icon">&iexcl;</div>
1320 <div class="tnotice__content">';
1321
1322 if ( $title ) {
1323 $output .= '<p class="tnotice__type">' . $title . '</p>';
1324 }
1325 $output .= '<p class="tnotice__message">' . $msg . '</p>
1326 </div>
1327 </div>';
1328
1329 return $output;
1330 }
1331 }
1332
1333 /**
1334 * @param int $course_content_id
1335 * @param bool $echo
1336 *
1337 * @return mixed|void
1338 *
1339 * Next Previous Pagination
1340 *
1341 * @since v.1.4.7
1342 */
1343
1344 function tutor_next_previous_pagination($course_content_id = 0, $echo = true){
1345 $content_id = tutor_utils()->get_post_id($course_content_id);
1346 $contents = tutor_utils()->get_course_prev_next_contents_by_id($content_id);
1347 $previous_id = $contents->previous_id;
1348 $next_id = $contents->next_id;
1349
1350 ob_start();
1351 do_action( 'tutor_lesson_next_previous_pagination_before' );
1352 tutor_load_template( 'single.next-previous-pagination', compact( 'previous_id', 'next_id' ) );
1353 do_action( 'tutor_lesson_next_previous_pagination_after' );
1354 $output = apply_filters( 'tutor/single/next_previous_pagination', ob_get_clean() );
1355
1356 if ( $echo ) {
1357 echo tutor_kses_html( $output );
1358 }
1359
1360 return $output;
1361 }
1362
1363 /**
1364 * Load custom template from any given file
1365 *
1366 * Pass parameter as wish
1367 *
1368 * @since 1.9.8
1369 */
1370 if ( ! function_exists('tutor_load_template_from_custom_path')) {
1371 function tutor_load_template_from_custom_path( $template = null, $data = array(), $once = true ) {
1372 do_action('tutor_load_template_from_custom_path_before', $template, $data);
1373 if ( file_exists($template) ) {
1374 if($once) {
1375 include_once $template;
1376 }
1377 else {
1378 include $template;
1379 }
1380 }
1381 do_action('tutor_load_template_from_custom_path_after', $template, $data);
1382 }
1383 }
1384
1385 /**
1386 * Load enrolled course progress template
1387 *
1388 * This template will be used on only dashboard enrolled course page
1389 *
1390 * @since v2.0.0
1391 */
1392 if ( ! function_exists( 'tutor_enrolled_course_progress' ) ) {
1393 function tutor_enrolled_course_progress() {
1394 global $wp_query;
1395 $query_vars = $wp_query->query_vars;
1396 if ( isset( $query_vars[ 'tutor_dashboard_page' ] ) && 'enrolled-courses' === $query_vars['tutor_dashboard_page'] ) {
1397 tutor_load_template_from_custom_path( tutor()->path . 'templates/loop/enrolled-course-progress.php', '', false );
1398 }
1399 }
1400 }
1401