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