PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 2.0.8
Tutor LMS – eLearning and online course solution v2.0.8
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
1412 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
468 ob_start();
469
470 $course_id = get_the_ID();
471 $can_continue = tutor_utils()->is_enrolled($course_id) || get_post_meta($course_id, '_tutor_is_public_course', true)=='yes';
472
473 // Check for further access type like course content access settings
474 if(!$can_continue){
475 $can_continue = tutor_utils()->has_user_course_content_access(get_current_user_id(), $course_id);
476 }
477
478 if( $can_continue ){
479 tutor_load_template( 'loop.course-continue' );
480
481 } else if(tutor_utils()->is_course_added_to_cart($course_id)){
482 tutor_load_template( 'loop.course-in-cart' );
483
484 } else {
485 $tutor_course_sell_by = apply_filters('tutor_course_sell_by', null);
486
487 if ($tutor_course_sell_by){
488 tutor_load_template( 'loop.course-price-'.$tutor_course_sell_by );
489 } else {
490 tutor_load_template( 'loop.course-price' );
491 }
492 }
493
494 echo apply_filters( 'tutor_course_loop_price', ob_get_clean() );
495 }
496 }
497
498 /**
499 * Get Course rating
500 *
501 * @since v.1.0.0
502 * @updated v.1.4.5
503 */
504
505 if ( ! function_exists( 'tutor_course_loop_rating' ) ) {
506 function tutor_course_loop_rating() {
507
508 $disable = !get_tutor_option('enable_course_review');
509 if ($disable){
510 return;
511 }
512
513 ob_start();
514 tutor_load_template( 'loop.rating' );
515 $output = apply_filters( 'tutor_course_loop_rating', ob_get_clean() );
516
517 echo tutor_kses_html( $output );
518 }
519 }
520
521 /**
522 * @param bool $echo
523 *
524 * @return mixed|void
525 *
526 * Get add to cart form
527 */
528
529 if ( ! function_exists( 'tutor_course_loop_add_to_cart' ) ) {
530 function tutor_course_loop_add_to_cart( $echo = true ) {
531 ob_start();
532 $tutor_course_sell_by = apply_filters( 'tutor_course_sell_by', null );
533
534 if ( $tutor_course_sell_by ) {
535 tutor_load_template( 'loop.add-to-cart-' . $tutor_course_sell_by );
536 }
537
538 $output = apply_filters( 'tutor_course_loop_add_to_cart_link', ob_get_clean() );
539
540 if ( $echo ) {
541 echo wp_kses_post($output);
542 }
543 return $output;
544 }
545 }
546
547 if ( ! function_exists( 'tutor_course_price' ) ) {
548 function tutor_course_price() {
549 ob_start();
550 tutor_load_template( 'single.course.wc-price-html' );
551 $output = apply_filters( 'tutor_course_price', ob_get_clean() );
552
553 echo $output;
554 }
555 }
556
557 /**
558 * @param int $post_id
559 *
560 * echo the excerpt of TUTOR post type
561 *
562 * @since: v.1.0.0
563 */
564 if ( ! function_exists( 'tutor_the_excerpt' ) ) {
565 function tutor_the_excerpt( $post_id = 0 ) {
566 if ( ! $post_id ) {
567 $post_id = get_the_ID();
568 }
569 echo tutor_get_the_excerpt( $post_id );
570 }
571 }
572 /**
573 * @param int $post_id
574 *
575 * @return mixed
576 *
577 * Return excerpt of TUTOR post type
578 *
579 * @since: v.1.0.0
580 */
581 if ( ! function_exists( 'tutor_get_the_excerpt' ) ) {
582 function tutor_get_the_excerpt( $post_id = 0 ) {
583 if ( ! $post_id ) {
584 $post_id = get_the_ID();
585 }
586
587 $get_post = get_post( $post_id );
588 return apply_filters( 'tutor_get_the_excerpt', $get_post->post_excerpt );
589 }
590 }
591
592 /**
593 * @return mixed
594 *
595 * return course author
596 *
597 * @since: v.1.0.0
598 */
599
600 if ( ! function_exists( 'get_tutor_course_author' ) ) {
601 function get_tutor_course_author() {
602 global $post;
603 return apply_filters( 'get_tutor_course_author', get_the_author_meta( 'display_name', $post->post_author ) );
604 }
605 }
606
607 function get_tutor_course_author_id() {
608 global $post;
609 return (int) $post->post_author;
610 }
611
612 /**
613 * @param int $course_id
614 *
615 * @return mixed
616 * Course benefits return array
617 *
618 * @since: v.1.0.0
619 */
620
621 if ( ! function_exists( 'tutor_course_benefits' ) ) {
622 function tutor_course_benefits( $course_id = 0 ) {
623 if ( ! $course_id ) {
624 $course_id = get_the_ID();
625 }
626 $benefits = get_post_meta( $course_id, '_tutor_course_benefits', true );
627
628 $benefits_array = array();
629 if ( $benefits ) {
630 $benefits_array = explode( "\n", $benefits );
631 }
632
633 $array = array_filter( array_map( 'trim', $benefits_array ) );
634
635 return apply_filters( 'tutor_course/single/benefits', $array, $course_id );
636 }
637 }
638
639 /**
640 * @param bool $echo
641 *
642 * @return mixed
643 *
644 * Course single page benefits
645 *
646 * @since: v.1.0.0
647 */
648
649 if ( ! function_exists( 'tutor_course_benefits_html' ) ) {
650 function tutor_course_benefits_html( $echo = true ) {
651 ob_start();
652 tutor_load_template( 'single.course.course-benefits' );
653 $output = apply_filters( 'tutor_course/single/benefits_html', ob_get_clean() );
654
655 if ( $echo ) {
656 echo wp_kses_post($output);
657 }
658 return $output;
659 }
660 }
661
662 /**
663 * @param bool $echo
664 *
665 * @return mixed|void
666 *
667 * Return Topics HTML
668 *
669 * @since: v.1.0.0
670 */
671 if ( ! function_exists( 'tutor_course_topics' ) ) {
672 function tutor_course_topics( $echo = true ) {
673 ob_start();
674 tutor_load_template( 'single.course.course-topics' );
675 $output = apply_filters( 'tutor_course/single/topics', ob_get_clean() );
676 wp_reset_postdata();
677
678 if ( $echo ) {
679 echo tutor_kses_html( $output );
680 }
681
682 return $output;
683 }
684 }
685
686 /**
687 * @param int $course_id
688 *
689 * @return mixed|void
690 *
691 * return course requirements in array
692 *
693 * @since: v.1.0.0
694 */
695 if ( ! function_exists( 'tutor_course_requirements' ) ) {
696 function tutor_course_requirements( $course_id = 0 ) {
697 if ( ! $course_id ) {
698 $course_id = get_the_ID();
699 }
700 $requirements = get_post_meta( $course_id, '_tutor_course_requirements', true );
701
702 $requirements_array = array();
703 if ( $requirements ) {
704 $requirements_array = explode( "\n", $requirements );
705 }
706
707 $array = array_filter( array_map( 'trim', $requirements_array ) );
708 return apply_filters( 'tutor_course/single/requirements', $array, $course_id );
709 }
710 }
711
712 /**
713 * @param bool $echo
714 *
715 * @return mixed|void
716 *
717 * Return course requirements in course single page
718 *
719 * @since: v.1.0.0
720 */
721 if ( ! function_exists('tutor_course_requirements_html')) {
722 function tutor_course_requirements_html($echo = true) {
723 ob_start();
724 tutor_course_material_includes_html();
725 tutor_load_template( 'single.course.course-requirements' );
726 $output = apply_filters( 'tutor_course/single/requirements_html', ob_get_clean() );
727
728 if ( $echo ) {
729 echo tutor_kses_html( $output );
730 }
731 return $output;
732 }
733 }
734
735
736 /**
737 * @param int $course_id
738 *
739 * @return mixed|void
740 *
741 * Return target audience in course single page
742 *
743 * @since: v.1.0.0
744 */
745 if ( ! function_exists( 'tutor_course_target_audience' ) ) {
746 function tutor_course_target_audience( $course_id = 0 ) {
747 if ( ! $course_id ) {
748 $course_id = get_the_ID();
749 }
750 $target_audience = get_post_meta( $course_id, '_tutor_course_target_audience', true );
751
752 $target_audience_array = array();
753 if ( $target_audience ) {
754 $target_audience_array = explode( "\n", $target_audience );
755 }
756
757 $array = array_filter( array_map( 'trim', $target_audience_array ) );
758 return apply_filters( 'tutor_course/single/target_audience', $array, $course_id );
759 }
760 }
761
762 /**
763 * @param bool $echo
764 *
765 * @return mixed|void
766 *
767 * Return target audience in course single page
768 *
769 * @since: v.1.0.0
770 */
771 if ( ! function_exists( 'tutor_course_target_audience_html' ) ) {
772 function tutor_course_target_audience_html( $echo = true ) {
773 ob_start();
774 tutor_load_template( 'single.course.course-target-audience' );
775 $output = apply_filters( 'tutor_course/single/audience_html', ob_get_clean() );
776
777 if ( $echo ) {
778 echo tutor_kses_html( $output );
779 }
780 return $output;
781 }
782 }
783
784
785 if ( ! function_exists( 'tutor_course_material_includes' ) ) {
786 function tutor_course_material_includes( $course_id = 0 ) {
787 if ( ! $course_id ) {
788 $course_id = get_the_ID();
789 }
790 $target_audience = get_post_meta( $course_id, '_tutor_course_material_includes', true );
791
792 $target_audience_array = array();
793 if ( $target_audience ) {
794 $target_audience_array = explode( "\n", $target_audience );
795 }
796
797 $array = array_filter( array_map( 'trim', $target_audience_array ) );
798 return apply_filters( 'tutor_course/single/material_includes', $array, $course_id );
799 }
800 }
801
802 if ( ! function_exists( 'tutor_course_material_includes_html' ) ) {
803 function tutor_course_material_includes_html( $echo = true ) {
804 ob_start();
805 tutor_load_template( 'single.course.material-includes' );
806 $output = apply_filters( 'tutor_course/single/material_includes', ob_get_clean() );
807
808 if ( $echo ) {
809 echo tutor_kses_html( $output );
810 }
811 return $output;
812 }
813 }
814
815 // tutor_course_material_includes_html
816
817
818 if ( ! function_exists( 'tutor_course_instructors_html' ) ) {
819 function tutor_course_instructors_html( $echo = true ) {
820 $display_course_instructors = tutor_utils()->get_option( 'display_course_instructors' );
821 if ( ! $display_course_instructors ) {
822 return null;
823 }
824
825 ob_start();
826 tutor_load_template( 'single.course.instructors' );
827 $output = apply_filters( 'tutor_course/single/instructors_html', ob_get_clean() );
828
829 if ( $echo ) {
830 echo tutor_kses_html( $output );
831 }
832 return $output;
833 }
834 }
835
836 if ( ! function_exists('tutor_course_target_reviews_html')) {
837 function tutor_course_target_reviews_html($echo = true) {
838 ob_start();
839 tutor_load_template( 'single.course.reviews' );
840
841 $output = apply_filters( 'tutor_course/single/reviews_html', ob_get_clean() );
842
843 if ( $echo ) {
844 echo tutor_kses_html( $output );
845 }
846 return $output;
847 }
848 }
849
850 /**
851 * @param bool $echo
852 *
853 * @return mixed
854 *
855 * Course single page main content / description
856 *
857 * @since: v.1.0.0
858 */
859 if ( ! function_exists( 'tutor_course_content' ) ) {
860 function tutor_course_content( $echo = true ) {
861 ob_start();
862 tutor_load_template( 'single.course.course-content' );
863 $output = apply_filters( 'tutor_course/single/content', ob_get_clean() );
864
865 if ( $echo ) {
866 echo tutor_kses_html( $output );
867 }
868
869 return $output;
870 }
871 }
872
873 /**
874 * Course single page lead info
875 *
876 * @since: v.1.0.0
877 */
878 if ( ! function_exists( 'tutor_course_lead_info' ) ) {
879 function tutor_course_lead_info( $echo = true ) {
880 ob_start();
881
882 // exit('failed');
883
884 $course_id = get_the_ID();
885 $course_post_type = tutor()->course_post_type;
886 $queryCourse = new WP_Query(
887 array(
888 'p' => $course_id,
889 'post_type' => $course_post_type,
890 )
891 );
892
893 if ( $queryCourse->have_posts() ) {
894 while ( $queryCourse->have_posts() ) {
895 $queryCourse->the_post();
896 tutor_load_template( 'single.course.lead-info' );
897 }
898 wp_reset_postdata();
899 }
900
901 $output = apply_filters( 'tutor_course/single/lead_info', ob_get_clean() );
902
903 if ( $echo ) {
904 echo tutor_kses_html( $output );
905 }
906 return $output;
907 }
908 }
909
910 /**
911 * @param bool $echo
912 *
913 * @return mixed|void
914 */
915
916 if ( ! function_exists('tutor_course_enrolled_lead_info')) {
917 function tutor_course_enrolled_lead_info( $echo = true ) {
918 ob_start();
919
920 $course_id = get_the_ID();
921 $course_post_type = tutor()->course_post_type;
922 $queryCourse = new WP_Query( array( 'p' => $course_id, 'post_type' => $course_post_type ) );
923
924 if ( $queryCourse->have_posts() ) {
925 while ( $queryCourse->have_posts() ) {
926 $queryCourse->the_post();
927 tutor_load_template( 'single.course.lead-info' );
928 }
929 wp_reset_postdata();
930 }
931
932 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
933
934 if ( $echo ) {
935 echo tutor_kses_html( $output );
936 }
937
938 return $output;
939 }
940 }
941
942 if ( ! function_exists('tutor_lesson_lead_info')) {
943 function tutor_lesson_lead_info( $lesson_id = 0, $echo = true ) {
944 if ( ! $lesson_id ) {
945 $lesson_id = get_the_ID();
946 }
947
948 ob_start();
949 $course_id = tutor_utils()->get_course_id_by( 'lesson', $lesson_id );
950 $course_post_type = tutor()->course_post_type;
951 $queryCourse = new WP_Query( array( 'p' => $course_id, 'post_type' => $course_post_type ) );
952
953 if ( $queryCourse->have_posts() ) {
954 while ( $queryCourse->have_posts() ) {
955 $queryCourse->the_post();
956 tutor_load_template( 'single.course.lead-info' );
957 }
958 wp_reset_postdata();
959 }
960 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
961
962 if ( $echo ) {
963 echo $output;
964 }
965
966 return $output;
967
968 }
969 }
970
971 if ( ! function_exists( 'tutor_course_video' ) ) {
972 function tutor_course_video( $echo = true ) {
973 ob_start();
974 tutor_load_template( 'single.video.video' );
975 $output = apply_filters( 'tutor_course/single/video', ob_get_clean() );
976
977 if ( $echo ) {
978 echo $output;
979 }
980 return $output;
981 }
982 }
983
984 if ( ! function_exists( 'tutor_lesson_video' ) ) {
985 function tutor_lesson_video( $echo = true ) {
986 ob_start();
987 tutor_load_template( 'single.video.video' );
988 $output = apply_filters( 'tutor_lesson/single/video', ob_get_clean() );
989
990 if ( $echo ) {
991 echo tutor_kses_html( $output );
992 }
993 return $output;
994 }
995 }
996
997 /**
998 *
999 * Get all lessons attachments
1000 *
1001 * @param bool $echo
1002 *
1003 * @return mixed
1004 *
1005 * @since v.1.0.0
1006 */
1007 if ( ! function_exists( 'get_tutor_posts_attachments' ) ) {
1008 function get_tutor_posts_attachments( $echo = true ) {
1009 ob_start();
1010 tutor_load_template( 'global.attachments' );
1011 $output = apply_filters( 'tutor_lesson/single/attachments', ob_get_clean() );
1012
1013 if ( $echo ) {
1014 echo tutor_kses_html( $output );
1015 }
1016 return $output;
1017 }
1018 }
1019
1020 /**
1021 * @param bool $echo
1022 *
1023 * @return mixed
1024 *
1025 * Render Lesson Main Content
1026 * @since v.1.0.0
1027 */
1028 if ( ! function_exists( 'tutor_lesson_content' ) ) {
1029 function tutor_lesson_content( $echo = true ) {
1030 ob_start();
1031 tutor_load_template( 'single.lesson.content' );
1032 $output = apply_filters( 'tutor_lesson/single/content', ob_get_clean() );
1033
1034 if ( $echo ) {
1035 echo $output;
1036 }
1037
1038 return $output;
1039 }
1040 }
1041
1042 if ( ! function_exists( 'tutor_lesson_mark_complete_html' ) ) {
1043 function tutor_lesson_mark_complete_html( $echo = true ) {
1044 ob_start();
1045 tutor_load_template( 'single.lesson.complete_form' );
1046 $output = apply_filters( 'tutor_lesson/single/complete_form', ob_get_clean() );
1047
1048 if ( $echo ) {
1049 echo tutor_kses_html( $output );
1050 }
1051
1052 return $output;
1053 }
1054 }
1055
1056 function tutor_course_question_and_answer( $echo = true ) {
1057 ob_start();
1058 tutor_load_template( 'single.course.enrolled.question_and_answer' );
1059 $output = apply_filters( 'tutor_course/single/question_and_answer', ob_get_clean() );
1060
1061 if ( $echo ) {
1062 echo $output;
1063 }
1064
1065 return $output;
1066 }
1067
1068 /**
1069 * @param bool $echo
1070 *
1071 * @return mixed
1072 *
1073 * @show progress bar about course complete
1074 *
1075 * @since v.2.0.0
1076 *
1077 * Course Curriculum added
1078 *
1079 * @since v2.0.5
1080 */
1081
1082 function tutor_course_info_tab() {
1083 tutor_course_content();
1084 tutor_course_benefits_html();
1085 tutor_course_topics();
1086 }
1087
1088
1089 function tutor_course_announcements( $echo = true ) {
1090 ob_start();
1091 tutor_load_template( 'single.course.enrolled.announcements' );
1092 $output = apply_filters( 'tutor_course/single/announcements', ob_get_clean() );
1093
1094 if ( $echo ) {
1095 echo $output;
1096 }
1097
1098 return $output;
1099 }
1100
1101 function tutor_single_quiz_top( $echo = true ) {
1102 ob_start();
1103 tutor_load_template( 'single.quiz.top' );
1104 $output = apply_filters( 'tutor_single_quiz/top', ob_get_clean() );
1105
1106 if ( $echo ) {
1107 echo $output;
1108 }
1109 return $output;
1110 }
1111
1112 function tutor_single_quiz_body( $echo = true ) {
1113 ob_start();
1114 tutor_load_template( 'single.quiz.body' );
1115 $output = apply_filters( 'tutor_single_quiz/body', ob_get_clean() );
1116
1117 if ( $echo ) {
1118 echo $output;
1119 }
1120 return $output;
1121 }
1122
1123 /**
1124 * @param bool $echo
1125 *
1126 * @return mixed|void
1127 *
1128 * Get the quiz description
1129 */
1130 function tutor_single_quiz_content( $echo = true ) {
1131 ob_start();
1132 tutor_load_template( 'single.quiz.content' );
1133 $output = apply_filters( 'tutor_single_quiz/content', ob_get_clean() );
1134
1135 if ( $echo ) {
1136 echo $output;
1137 }
1138 return $output;
1139 }
1140
1141
1142 function tutor_single_quiz_no_course_belongs( $echo = true ) {
1143 ob_start();
1144 tutor_load_template( 'single.quiz.no_course_belongs' );
1145 $output = apply_filters( 'tutor_single_quiz/no_course_belongs', ob_get_clean() );
1146
1147 if ( $echo ) {
1148 echo $output;
1149 }
1150 return $output;
1151 }
1152
1153 function single_quiz_contents( $echo = true ) {
1154
1155 ob_start();
1156 tutor_load_template( 'single.quiz.single_quiz_contents' );
1157 $output = apply_filters( 'tutor_single_quiz/single_quiz_contents', ob_get_clean() );
1158
1159 if ( $echo ) {
1160 echo $output;
1161 }
1162 return $output;
1163 }
1164
1165 function get_tutor_course_level( $course_id = 0 ) {
1166 if ( ! $course_id ) {
1167 $course_id = get_the_ID();
1168 }
1169 if ( ! $course_id ) {
1170 return '';
1171 }
1172
1173 $course_level = get_post_meta( $course_id, '_tutor_course_level', true );
1174
1175 if ( $course_level ) {
1176 return tutor_utils()->course_levels( $course_level );
1177 }
1178 return false;
1179 }
1180
1181 if ( ! function_exists('get_tutor_course_duration_context')) {
1182 function get_tutor_course_duration_context( $course_id = 0, $short_form = false ) {
1183 if ( ! $course_id ) {
1184 $course_id = get_the_ID();
1185 }
1186 if ( ! $course_id ) {
1187 return '';
1188 }
1189 $duration = get_post_meta( $course_id, '_course_duration', true );
1190 $durationHours = tutor_utils()->avalue_dot( 'hours', $duration );
1191 $durationMinutes = tutor_utils()->avalue_dot( 'minutes', $duration );
1192 $durationSeconds = tutor_utils()->avalue_dot( 'seconds', $duration );
1193
1194 $hour_format = $short_form ? __( 'h', 'tutor' ) : ' '.($durationHours>1 ? __('hours', 'tutor') : __( 'hour', 'tutor' ));
1195 $minute_format = $short_form ? __( 'm', 'tutor' ) : ' '.($durationMinutes>1 ? __('minutes', 'tutor') : __( 'minute', 'tutor' ));
1196 $second_format = $short_form ? __( 's', 'tutor' ) : ' '.($durationSeconds>1 ? __('seconds', 'tutor') : __( 'second', 'tutor' ));
1197
1198 if ( $duration ) {
1199 $output = '';
1200 if ( $durationHours > 0 ) {
1201 $output .= '<span class="tutor-meta-level">' . ' ' . $durationHours . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $hour_format . '</span>';
1202 }
1203
1204 if ( $durationMinutes > 0 ) {
1205 $output .= '<span class="tutor-meta-level">' . ' ' . $durationMinutes . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $minute_format . '</span>';
1206 }
1207
1208 if ( !$durationHours && !$durationMinutes && $durationSeconds > 0 ) {
1209 $output .= '<span class="tutor-meta-level">' . ' ' . $durationSeconds . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $second_format . '</span>';
1210 }
1211
1212 return $output;
1213 }
1214
1215 return false;
1216 }
1217 }
1218 if ( ! function_exists( 'get_tutor_course_categories' ) ) {
1219 function get_tutor_course_categories( $course_id = 0 ) {
1220 if ( ! $course_id ) {
1221 $course_id = get_the_ID();
1222 }
1223 $terms = get_the_terms( $course_id, 'course-category' );
1224
1225 return $terms;
1226 }
1227 }
1228
1229 /**
1230 * @param int $course_id
1231 *
1232 * @return array|false|WP_Error
1233 *
1234 * Get course tags
1235 */
1236
1237 if ( ! function_exists( 'get_tutor_course_tags' ) ) {
1238 function get_tutor_course_tags( $course_id = 0 ) {
1239 if ( ! $course_id ) {
1240 $course_id = get_the_ID();
1241 }
1242 $terms = get_the_terms( $course_id, 'course-tag' );
1243
1244 return $terms;
1245 }
1246 }
1247
1248 /**
1249 * @param bool $echo
1250 *
1251 * @return mixed|void
1252 *
1253 * Template for course tags html
1254 */
1255
1256 if ( ! function_exists( 'tutor_course_tags_html' ) ) {
1257 function tutor_course_tags_html( $echo = true ) {
1258 ob_start();
1259 tutor_load_template( 'single.course.tags' );
1260 $output = apply_filters( 'tutor_course/single/tags_html', ob_get_clean() );
1261
1262 if ( $echo ) {
1263 echo tutor_kses_html( $output );
1264 }
1265
1266 return $output;
1267 }
1268 }
1269
1270 /**
1271 * @param bool $echo
1272 *
1273 * @return mixed
1274 *
1275 * Get Q&A in lesson sidebar
1276 */
1277
1278 if ( ! function_exists( 'tutor_lesson_sidebar_question_and_answer' ) ) {
1279 function tutor_lesson_sidebar_question_and_answer( $echo = true ) {
1280 ob_start();
1281 tutor_load_template( 'single.lesson.sidebar_question_and_answer' );
1282 $output = apply_filters( 'tutor_lesson/single/sidebar_question_and_answer', ob_get_clean() );
1283
1284 if ( $echo ) {
1285 echo tutor_kses_html( $output );
1286 }
1287
1288 return $output;
1289 }
1290 }
1291
1292 /**
1293 * @param bool $echo
1294 *
1295 * @return mixed
1296 *
1297 * Get Assignment content
1298 *
1299 * @since v.1.3.3
1300 */
1301
1302 if ( ! function_exists( 'tutor_assignment_content' ) ) {
1303 function tutor_assignment_content( $echo = true ) {
1304 ob_start();
1305 tutor_load_template( 'single.assignment.content' );
1306 $output = apply_filters( 'tutor_assignment/single/content', ob_get_clean() );
1307
1308 if ( $echo ) {
1309 echo tutor_kses_html( $output );
1310 }
1311
1312 return $output;
1313 }
1314 }
1315
1316 /**
1317 * @param string $msg
1318 * @param string $title
1319 * @param string $type
1320 *
1321 * @return string
1322 *
1323 * @since v.1.4.0
1324 */
1325
1326 if ( ! function_exists( 'get_tnotice' ) ) {
1327 function get_tnotice( $msg = '', $title = 'Success', $type = 'success' ) {
1328
1329 $output = '<div class="tnotice tnotice--' . $type . '">
1330 <div class="tnotice__icon">&iexcl;</div>
1331 <div class="tnotice__content">';
1332
1333 if ( $title ) {
1334 $output .= '<p class="tnotice__type">' . $title . '</p>';
1335 }
1336 $output .= '<p class="tnotice__message">' . $msg . '</p>
1337 </div>
1338 </div>';
1339
1340 return $output;
1341 }
1342 }
1343
1344 /**
1345 * @param int $course_content_id
1346 * @param bool $echo
1347 *
1348 * @return mixed|void
1349 *
1350 * Next Previous Pagination
1351 *
1352 * @since v.1.4.7
1353 */
1354
1355 function tutor_next_previous_pagination($course_content_id = 0, $echo = true){
1356 $content_id = tutor_utils()->get_post_id($course_content_id);
1357 $contents = tutor_utils()->get_course_prev_next_contents_by_id($content_id);
1358 $previous_id = $contents->previous_id;
1359 $next_id = $contents->next_id;
1360
1361 ob_start();
1362 do_action( 'tutor_lesson_next_previous_pagination_before' );
1363 tutor_load_template( 'single.next-previous-pagination', compact( 'previous_id', 'next_id' ) );
1364 do_action( 'tutor_lesson_next_previous_pagination_after' );
1365 $output = apply_filters( 'tutor/single/next_previous_pagination', ob_get_clean() );
1366
1367 if ( $echo ) {
1368 echo tutor_kses_html( $output );
1369 }
1370
1371 return $output;
1372 }
1373
1374 /**
1375 * Load custom template from any given file
1376 *
1377 * Pass parameter as wish
1378 *
1379 * @since 1.9.8
1380 */
1381 if ( ! function_exists('tutor_load_template_from_custom_path')) {
1382 function tutor_load_template_from_custom_path( $template = null, $data = array(), $once = true ) {
1383 do_action('tutor_load_template_from_custom_path_before', $template, $data);
1384 if ( file_exists($template) ) {
1385 if($once) {
1386 include_once $template;
1387 }
1388 else {
1389 include $template;
1390 }
1391 }
1392 do_action('tutor_load_template_from_custom_path_after', $template, $data);
1393 }
1394 }
1395
1396 /**
1397 * Load enrolled course progress template
1398 *
1399 * This template will be used on only dashboard enrolled course page
1400 *
1401 * @since v2.0.0
1402 */
1403 if ( ! function_exists( 'tutor_enrolled_course_progress' ) ) {
1404 function tutor_enrolled_course_progress() {
1405 global $wp_query;
1406 $query_vars = $wp_query->query_vars;
1407 if ( isset( $query_vars[ 'tutor_dashboard_page' ] ) && 'enrolled-courses' === $query_vars['tutor_dashboard_page'] ) {
1408 tutor_load_template_from_custom_path( tutor()->path . 'templates/loop/enrolled-course-progress.php', '', false );
1409 }
1410 }
1411 }
1412