PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 4.0.6
Tutor LMS – eLearning and online course solution v4.0.6
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 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
droip 2 months ago kirki 2 months ago theme-compatibility 1 month ago country.php 1 month ago ecommerce-functions.php 1 month ago tinymce_translate.php 1 month ago translate-text.php 1 month ago tutor-general-functions.php 1 month ago tutor-template-functions.php 1 week ago tutor-template-hook.php 4 years ago
tutor-template-functions.php
1827 lines
1 <?php
2 /**
3 * Tutor template functions
4 *
5 * @package TutorFunctions
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 1.0.0
9 */
10
11 defined( 'ABSPATH' ) || exit;
12
13 use Tutor\Models\CourseModel;
14 use Tutor\Models\EnrollmentModel;
15
16 if ( ! function_exists( 'tutor_get_template' ) ) {
17 /**
18 * Load template with override file system.
19 *
20 * @since 1.0.0
21 *
22 * @param string $template template name.
23 * @param bool $tutor_pro whether to load from tutor pro.
24 *
25 * @return bool|string
26 */
27 function tutor_get_template( $template = null, $tutor_pro = false ) {
28 if ( ! $template ) {
29 return false;
30 }
31 $template = str_replace( '.', DIRECTORY_SEPARATOR, $template );
32
33 /**
34 * Get template first from child-theme if exists
35 * If child theme not exists, then get template from parent theme
36 */
37 $template_location = trailingslashit( get_stylesheet_directory() ) . "tutor/{$template}.php";
38 if ( ! file_exists( $template_location ) ) {
39 $template_location = trailingslashit( get_template_directory() ) . "tutor/{$template}.php";
40 }
41 $file_in_theme = $template_location;
42 if ( ! file_exists( $template_location ) ) {
43 $template_location = trailingslashit( tutor()->path ) . "templates/{$template}.php";
44
45 if ( $tutor_pro && function_exists( 'tutor_pro' ) ) {
46 $pro_template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
47 if ( file_exists( $pro_template_location ) ) {
48 $template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
49 }
50 }
51
52 if ( ! file_exists( $template_location ) ) {
53 $warning_msg = __( '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: ', 'tutor' );
54 $warning_msg = $warning_msg . "<code>$file_in_theme</code>";
55 $warning_msg = apply_filters( 'tutor_not_found_template_warning_msg', $warning_msg );
56 echo wp_kses( $warning_msg, array( 'code' => true ) );
57 ?>
58 <?php
59 }
60 }
61
62 return apply_filters( 'tutor_get_template_path', $template_location, $template );
63 }
64 }
65
66 if ( ! function_exists( 'tutor_get_template_path' ) ) {
67 /**
68 * Get only template path without any warning.
69 *
70 * @since 1.4.2
71 *
72 * @param string $template template name.
73 * @param bool $tutor_pro whether to load from tutor pro.
74 *
75 * @return bool|string
76 */
77 function tutor_get_template_path( $template = null, $tutor_pro = false ) {
78 if ( ! $template ) {
79 return false;
80 }
81 $template = str_replace( '.', DIRECTORY_SEPARATOR, $template );
82
83 /**
84 * Get template first from child-theme if exists
85 * If child theme not exists, then get template from parent theme
86 */
87 $template_location = trailingslashit( get_stylesheet_directory() ) . "tutor/{$template}.php";
88 if ( ! file_exists( $template_location ) ) {
89 $template_location = trailingslashit( get_template_directory() ) . "tutor/{$template}.php";
90 }
91 if ( ! file_exists( $template_location ) ) {
92 $template_location = trailingslashit( tutor()->path ) . "templates/{$template}.php";
93 }
94 if ( ! file_exists( $template_location ) && $tutor_pro && function_exists( 'tutor_pro' ) ) {
95 $template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
96 }
97
98 return apply_filters( 'tutor_get_template_path', $template_location, $template );
99 }
100 }
101
102 if ( ! function_exists( 'tutor_load_template' ) ) {
103 /**
104 * Load template for TUTOR.
105 *
106 * @since 1.0.0
107 * @since 1.1.2 updated.
108 *
109 * @param string $template template name.
110 * @param array $variables variables.
111 * @param bool $tutor_pro whether to load from tutor pro.
112 *
113 * @return void
114 */
115 function tutor_load_template( $template = null, $variables = array(), $tutor_pro = false ) {
116 $variables = (array) $variables;
117 $variables = apply_filters( 'get_tutor_load_template_variables', $variables );
118 // EXTR_SKIP keeps $template and other locals from being overwritten by caller data.
119 extract( $variables, EXTR_SKIP ); //phpcs:ignore
120
121 $is_load = apply_filters( 'should_tutor_load_template', true, $template, $variables );
122 if ( ! $is_load ) {
123 return;
124 }
125
126 do_action( 'tutor_load_template_before', $template, $variables );
127 $template_file = tutor_get_template( $template, $tutor_pro );
128 if ( file_exists( $template_file ) ) {
129 include tutor_get_template( $template, $tutor_pro );
130 } else {
131 do_action( 'tutor_after_template_not_found', $template );
132 }
133 do_action( 'tutor_load_template_after', $template, $variables );
134 }
135 }
136
137 if ( ! function_exists( 'tutor_load_template_part' ) ) {
138 /**
139 * Load tutor template part.
140 *
141 * @since 1.4.3
142 *
143 * @param string $template template name.
144 * @param array $variables variables.
145 * @param bool $tutor_pro whether to load from tutor pro.
146 *
147 * @return void
148 */
149 function tutor_load_template_part( $template = null, $variables = array(), $tutor_pro = false ) {
150 $variables = (array) $variables;
151 $variables = apply_filters( 'get_tutor_load_template_variables', $variables );
152 // EXTR_SKIP keeps $template and other locals from being overwritten by caller data.
153 extract( $variables, EXTR_SKIP ); //phpcs:ignore
154
155 /**
156 * Get template first from child-theme if exists
157 * If child theme not exists, then get template from parent theme
158 */
159 $template_location = trailingslashit( get_stylesheet_directory() ) . 'tutor/template.php';
160 if ( ! file_exists( $template_location ) ) {
161 $template_location = trailingslashit( get_template_directory() ) . 'tutor/template.php';
162 }
163
164 if ( ! file_exists( $template_location ) ) {
165 $template_location = trailingslashit( tutor()->path ) . 'templates/template.php';
166 if ( ! file_exists( $template_location ) && $tutor_pro && function_exists( 'tutor_pro' ) ) {
167 $template_location = trailingslashit( tutor_pro()->path ) . 'templates/template.php';
168 }
169 }
170
171 include apply_filters( 'tutor_get_template_part_path', $template_location, $template );
172 }
173 }
174
175 if ( ! function_exists( 'tutor_get_template_html' ) ) {
176 /**
177 * Tutor get template HTML.
178 *
179 * @since 1.4.3
180 *
181 * @param string $template_name template name.
182 * @param array $variables variables.
183 * @param bool $tutor_pro is tutor pro.
184 *
185 * @return string
186 */
187 function tutor_get_template_html( $template_name, $variables = array(), $tutor_pro = false ) {
188 ob_start();
189 tutor_load_template( $template_name, $variables, $tutor_pro );
190
191 return ob_get_clean();
192 }
193 }
194
195 if ( ! function_exists( 'tutor_course_loop_start' ) ) {
196 /**
197 * Tutor course loop start.
198 *
199 * @since 1.0.0
200 *
201 * @param bool $echo whether to echo content.
202 *
203 * @return string
204 */
205 function tutor_course_loop_start( $echo = true ) {
206 ob_start();
207 tutor_load_template( 'loop.loop-start' );
208 $output = apply_filters( 'tutor_course_loop_start', ob_get_clean() );
209
210 if ( $echo ) {
211 echo tutor_kses_html( $output ); //phpcs:ignore
212 }
213 return $output;
214 }
215 }
216
217 if ( ! function_exists( 'tutor_course_loop_end' ) ) {
218 /**
219 * Tutor course loop end.
220 *
221 * @since 1.0.0
222 *
223 * @param bool $echo whether to echo content.
224 *
225 * @return string
226 */
227 function tutor_course_loop_end( $echo = true ) {
228 ob_start();
229 tutor_load_template( 'loop.loop-end' );
230
231 $output = apply_filters( 'tutor_course_loop_end', ob_get_clean() );
232 if ( $echo ) {
233 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
234 }
235
236 return $output;
237 }
238 }
239
240 if ( ! function_exists( 'tutor_course_loop_before_content' ) ) {
241 /**
242 * Tutor course loop before content.
243 *
244 * @since 1.0.0
245 *
246 * @return void
247 */
248 function tutor_course_loop_before_content() {
249 ob_start();
250 tutor_load_template( 'loop.loop-before-content' );
251
252 $output = apply_filters( 'tutor_course_loop_before_content', ob_get_clean() );
253 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
254 }
255 }
256
257 if ( ! function_exists( 'tutor_course_loop_after_content' ) ) {
258 /**
259 * Tutor course loop after content.
260 *
261 * @since 1.0.0
262 *
263 * @return void
264 */
265 function tutor_course_loop_after_content() {
266 ob_start();
267 tutor_load_template( 'loop.loop-after-content' );
268
269 $output = apply_filters( 'tutor_course_loop_after_content', ob_get_clean() );
270 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
271 }
272 }
273
274 if ( ! function_exists( 'tutor_course_loop_title' ) ) {
275 /**
276 * Tutor course loop title.
277 *
278 * @since 1.0.0
279 *
280 * @return void
281 */
282 function tutor_course_loop_title() {
283 ob_start();
284 tutor_load_template( 'loop.title' );
285 $output = apply_filters( 'tutor_course_loop_title', ob_get_clean() );
286
287 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
288 }
289 }
290
291
292 if ( ! function_exists( 'tutor_course_loop_header' ) ) {
293 /**
294 * Tutor course loop header.
295 *
296 * @since 1.0.0
297 *
298 * @return void
299 */
300 function tutor_course_loop_header() {
301 ob_start();
302 tutor_load_template( 'loop.header' );
303 $output = apply_filters( 'tutor_course_loop_header', ob_get_clean() );
304
305 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
306 }
307 }
308
309 if ( ! function_exists( 'tutor_course_loop_footer' ) ) {
310 /**
311 * Tutor course loop footer.
312 *
313 * @since 1.0.0
314 *
315 * @return void
316 */
317 function tutor_course_loop_footer() {
318 ob_start();
319 tutor_load_template( 'loop.footer' );
320 $output = apply_filters( 'tutor_course_loop_footer', ob_get_clean() );
321
322 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
323 }
324 }
325
326 if ( ! function_exists( 'tutor_course_loop_start_content_wrap' ) ) {
327 /**
328 * Tutor course loop start content wrap.
329 *
330 * @since 1.0.0
331 *
332 * @return void
333 */
334 function tutor_course_loop_start_content_wrap() {
335 ob_start();
336 tutor_load_template( 'loop.start_content_wrap' );
337 $output = apply_filters( 'tutor_course_loop_start_content_wrap', ob_get_clean() );
338
339 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
340 }
341 }
342
343 if ( ! function_exists( 'tutor_course_loop_end_content_wrap' ) ) {
344 /**
345 * Tutor course loop end content wrap.
346 *
347 * @since 1.0.0
348 *
349 * @return void
350 */
351 function tutor_course_loop_end_content_wrap() {
352 ob_start();
353 tutor_load_template( 'loop.end_content_wrap' );
354 $output = apply_filters( 'tutor_course_loop_end_content_wrap', ob_get_clean() );
355
356 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
357 }
358 }
359
360 if ( ! function_exists( 'tutor_course_loop_thumbnail' ) ) {
361 /**
362 * Tutor course loop thumbnail.
363 *
364 * @since 1.0.0
365 *
366 * @param bool $echo whether to echo content.
367 *
368 * @return mixed
369 */
370 function tutor_course_loop_thumbnail( $echo = true ) {
371 ob_start();
372 tutor_load_template( 'loop.thumbnail' );
373 $output = apply_filters( 'tutor_course_loop_thumbnail', ob_get_clean() );
374
375 if ( $echo ) {
376 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
377 } else {
378 return $output;
379 }
380 }
381 }
382
383 if ( ! function_exists( 'tutor_course_loop_wrap_classes' ) ) {
384 /**
385 * Tutor course loop wrap classes.
386 *
387 * @since 1.0.0
388 *
389 * @param bool $echo whether to echo.
390 *
391 * @return mixed
392 */
393 function tutor_course_loop_wrap_classes( $echo = true ) {
394 $course_id = get_the_ID();
395 $classes = apply_filters(
396 'tutor_course_loop_wrap_classes',
397 array(
398 'tutor-course',
399 'tutor-course-loop',
400 'tutor-course-loop-' . $course_id,
401 )
402 );
403
404 $class = implode( ' ', $classes );
405 if ( $echo ) {
406 echo esc_attr( $class );
407 }
408
409 return esc_attr( $class );
410 }
411 }
412
413 if ( ! function_exists( 'tutor_course_loop_col_classes' ) ) {
414 /**
415 * Tutor course loop col classes.
416 *
417 * @since 1.0.0
418 *
419 * @param bool $echo whether to echo.
420 *
421 * @return mixed
422 */
423 function tutor_course_loop_col_classes( $echo = true ) {
424 $course_filter = (bool) tutor_utils()->get_option( 'course_archive_filter', false );
425 $course_archive_arg = isset( $GLOBALS['tutor_course_archive_arg'] ) ? $GLOBALS['tutor_course_archive_arg']['column_per_row'] : null;
426 $course_cols = null === $course_archive_arg ? tutor_utils()->get_option( 'courses_col_per_row', 3 ) : $course_archive_arg;
427 $classes = apply_filters(
428 'tutor_course_loop_col_classes',
429 array(
430 'tutor-col-' . $course_cols,
431 )
432 );
433
434 $class = implode( ' ', $classes );
435 if ( $echo ) {
436 echo esc_attr( $class );
437 }
438
439 return esc_attr( $class );
440 }
441 }
442
443
444 if ( ! function_exists( 'tutor_container_classes' ) ) {
445 /**
446 * Tutor container classes.
447 *
448 * @since 1.0.0
449 *
450 * @param bool $echo whether to echo.
451 *
452 * @return mixed
453 */
454 function tutor_container_classes( $echo = true ) {
455
456 $classes = apply_filters(
457 'tutor_container_classes',
458 array(
459 'tutor-wrap tutor-courses-wrap',
460 'tutor-container',
461 )
462 );
463
464 $classes = apply_filters(
465 'tutor_container_classes',
466 array(
467 'tutor-wrap tutor-courses-wrap',
468 'tutor-container',
469 )
470 );
471
472 $class = implode( ' ', $classes );
473
474 if ( $echo ) {
475 echo esc_attr( $class );
476 }
477
478 return esc_attr( $class );
479 }
480 }
481 if ( ! function_exists( 'tutor_post_class' ) ) {
482 /**
483 * Tutor post class.
484 *
485 * @since 1.0.0
486 *
487 * @param string $default default class.
488 *
489 * @return void
490 */
491 function tutor_post_class( $default = '' ) {
492 $classes = apply_filters(
493 'tutor_post_class',
494 array(
495 'tutor-wrap',
496 $default,
497 )
498 );
499
500 post_class( $classes );
501 }
502 }
503
504 if ( ! function_exists( 'tutor_widget_course_loop_classes' ) ) {
505 /**
506 * Get classes for widget loop single course wrap.
507 *
508 * @since 1.3.1
509 *
510 * @param bool $echo whether to echo content.
511 *
512 * @return string
513 */
514 function tutor_widget_course_loop_classes( $echo = true ) {
515
516 $classes = apply_filters(
517 'tutor_widget_course_loop_classes',
518 array(
519 'tutor-widget-course-loop',
520 'tutor-widget-course',
521 'tutor-widget-course-' . get_the_ID(),
522 )
523 );
524
525 $class = implode( ' ', $classes );
526 if ( $echo ) {
527 echo esc_attr( $class );
528 }
529
530 return esc_attr( $class );
531 }
532 }
533
534 if ( ! function_exists( 'get_tutor_course_thumbnail' ) ) {
535 /**
536 * Get course thumbnail.
537 *
538 * @since 1.0.0
539 *
540 * @param string $size size.
541 * @param bool $url whether to return url only.
542 *
543 * @return string
544 */
545 function get_tutor_course_thumbnail( $size = 'post-thumbnail', $url = false ) {
546 $post_id = get_the_ID();
547 $size = apply_filters( 'tutor_course_thumbnail_size', $size, $post_id );
548 $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id );
549 $placeholder_url = tutor()->url . 'assets/images/placeholder.svg';
550 $thumb_url = $post_thumbnail_id ? wp_get_attachment_image_url( $post_thumbnail_id, $size ) : $placeholder_url;
551 $thumb_url = apply_filters( 'tutor_course_thumb_url', $thumb_url, $post_id, $size, $post_thumbnail_id );
552
553 if ( $url ) {
554 return $thumb_url;
555 }
556
557 echo '<div class="tutor-course-thumbnail">
558 <img src="' . esc_url( $thumb_url ) . '" />
559 </div>';
560 }
561 }
562
563 if ( ! function_exists( 'get_tutor_course_thumbnail_src' ) ) {
564 /**
565 * Get the course/post thumbnail src.
566 *
567 * @since 1.0.0
568 * @since 2.2.0 $id param added to provide post id to access outside of post loop.
569 *
570 * @since 3.4.1 Attachment src fallback added to show placeholder image
571 *
572 * @param string $size size of thumb.
573 * @param int $id post id.
574 *
575 * @return string src of the post thumbnail | default placeholder
576 */
577 function get_tutor_course_thumbnail_src( $size = 'post-thumbnail', $id = 0 ) {
578 $post_id = $id ? $id : get_the_ID();
579 $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id );
580 $placeholder_url = tutor()->url . 'assets/images/placeholder.svg';
581
582 if ( $post_thumbnail_id ) {
583 $size = apply_filters( 'tutor_course_thumbnail_size', $size, $post_id );
584 $src = wp_get_attachment_image_url( $post_thumbnail_id, $size, false );
585 if ( ! $src ) {
586 $src = $placeholder_url;
587 }
588 } else {
589 $src = apply_filters( 'tutor_course_thumbnail_placeholder', $placeholder_url, $post_id );
590 }
591
592 $src = apply_filters( 'tutor_course_thumb_url', $src, $post_id, $size, $post_thumbnail_id );
593
594 return $src;
595 }
596 }
597
598 if ( ! function_exists( 'tutor_course_loop_meta' ) ) {
599 /**
600 * Course loop meta.
601 *
602 * @since 1.0.0
603 *
604 * @return void
605 */
606 function tutor_course_loop_meta() {
607 ob_start();
608 tutor_load_template( 'loop.meta' );
609 $output = apply_filters( 'tutor_course_loop_meta', ob_get_clean() );
610
611 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
612 }
613 }
614
615 if ( ! function_exists( 'tutor_course_loop_author' ) ) {
616 /**
617 * Get course author name in loop.
618 *
619 * @since 1.0.0
620 *
621 * @return void
622 */
623 function tutor_course_loop_author() {
624 ob_start();
625 tutor_load_template( 'loop.course-author' );
626 $output = apply_filters( 'tutor_course_loop_author', ob_get_clean() );
627
628 echo $output; //phpcs:ignore -- data already escaped inside template file
629 }
630 }
631
632 if ( ! function_exists( 'tutor_course_loop_price' ) ) {
633 /**
634 * Course loop price.
635 *
636 * @since 1.0.0
637 *
638 * @return void
639 */
640 function tutor_course_loop_price() {
641
642 ob_start();
643
644 $course_id = get_the_ID();
645 $can_continue = EnrollmentModel::is_enrolled( $course_id ) || get_post_meta( $course_id, '_tutor_is_public_course', true ) == 'yes';
646
647 // Check for further access type like course content access settings.
648 if ( ! $can_continue ) {
649 $can_continue = tutor_utils()->has_user_course_content_access( get_current_user_id(), $course_id );
650 }
651
652 if ( $can_continue ) {
653 tutor_load_template( 'loop.course-continue' );
654
655 } elseif ( tutor_utils()->is_course_added_to_cart( $course_id ) ) {
656 tutor_load_template( 'loop.course-in-cart' );
657
658 } else {
659 $tutor_course_sell_by = apply_filters( 'tutor_course_sell_by', null );
660
661 if ( $tutor_course_sell_by && ( tutor_utils()->is_course_purchasable( $course_id ) || ! is_user_logged_in() ) ) {
662 tutor_load_template( 'loop.course-price-' . $tutor_course_sell_by );
663 } else {
664 tutor_load_template( 'loop.course-price' );
665 }
666 }
667 echo apply_filters( 'tutor_course_loop_price', ob_get_clean(), $course_id ); //phpcs:ignore -- already escaped inside template file
668 }
669 }
670
671 if ( ! function_exists( 'tutor_course_loop_rating' ) ) {
672 /**
673 * Get Course rating.
674 *
675 * @since 1.0.0
676 * @since 1.4.5 updated.
677 *
678 * @return void
679 */
680 function tutor_course_loop_rating() {
681
682 $disable = ! get_tutor_option( 'enable_course_review' );
683 if ( $disable ) {
684 return;
685 }
686
687 ob_start();
688 tutor_load_template( 'loop.rating' );
689 $output = apply_filters( 'tutor_course_loop_rating', ob_get_clean() );
690
691 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
692 }
693 }
694
695 if ( ! function_exists( 'tutor_course_loop_add_to_cart' ) ) {
696 /**
697 * Get add to cart form.
698 *
699 * @since 1.0.0
700 *
701 * @param bool $echo whether to echo content.
702 *
703 * @return string
704 */
705 function tutor_course_loop_add_to_cart( $echo = true ) {
706 ob_start();
707 $tutor_course_sell_by = apply_filters( 'tutor_course_sell_by', null );
708
709 if ( $tutor_course_sell_by ) {
710 tutor_load_template( 'loop.add-to-cart-' . $tutor_course_sell_by );
711 }
712
713 $output = apply_filters( 'tutor_course_loop_add_to_cart_link', ob_get_clean() );
714
715 if ( $echo ) {
716 echo wp_kses_post( $output );
717 }
718 return $output;
719 }
720 }
721
722 if ( ! function_exists( 'tutor_course_price' ) ) {
723 /**
724 * Get course price.
725 *
726 * @since 1.0.0
727 *
728 * @return void
729 */
730 function tutor_course_price() {
731 ob_start();
732 tutor_load_template( 'single.course.wc-price-html' );
733 $output = apply_filters( 'tutor_course_price', ob_get_clean() );
734
735 echo $output; //phpcs:ignore -- data already escaped inside template file
736 }
737 }
738
739 if ( ! function_exists( 'tutor_the_excerpt' ) ) {
740 /**
741 * Echo the excerpt of TUTOR post type.
742 *
743 * @since 1.0.0
744 *
745 * @param int $post_id post ID.
746 *
747 * @return void
748 */
749 function tutor_the_excerpt( $post_id = 0 ) {
750 if ( ! $post_id ) {
751 $post_id = get_the_ID();
752 }
753 echo esc_textarea( tutor_get_the_excerpt( $post_id ) );
754 }
755 }
756 if ( ! function_exists( 'tutor_get_the_excerpt' ) ) {
757 /**
758 * Return excerpt of TUTOR post type.
759 *
760 * @since 1.0.0
761 *
762 * @param int $post_id post ID.
763 *
764 * @return mixed
765 */
766 function tutor_get_the_excerpt( $post_id = 0 ) {
767 if ( ! $post_id ) {
768 $post_id = get_the_ID();
769 }
770
771 $get_post = get_post( $post_id );
772 return apply_filters( 'tutor_get_the_excerpt', $get_post->post_excerpt );
773 }
774 }
775
776 if ( ! function_exists( 'get_tutor_course_author' ) ) {
777 /**
778 * Return course author.
779 *
780 * @since 1.0.0
781 *
782 * @return string
783 */
784 function get_tutor_course_author() {
785 global $post;
786 return apply_filters( 'get_tutor_course_author', get_the_author_meta( 'display_name', $post->post_author ) );
787 }
788 }
789
790 /**
791 * Get course author ID.
792 *
793 * @since 1.0.0
794 *
795 * @return int
796 */
797 function get_tutor_course_author_id() {
798 global $post;
799 return (int) $post->post_author;
800 }
801
802 if ( ! function_exists( 'tutor_course_benefits' ) ) {
803 /**
804 * Course benefits return array.
805 *
806 * @since 1.0.0
807 *
808 * @param int $course_id course ID.
809 *
810 * @return array
811 */
812 function tutor_course_benefits( $course_id = 0 ) {
813 if ( ! $course_id ) {
814 $course_id = get_the_ID();
815 }
816 $benefits = get_post_meta( $course_id, '_tutor_course_benefits', true );
817
818 $benefits_array = array();
819 if ( $benefits ) {
820 $benefits_array = explode( "\n", $benefits );
821 }
822
823 $array = array_filter( array_map( 'trim', $benefits_array ) );
824
825 return apply_filters( 'tutor_course/single/benefits', $array, $course_id );
826 }
827 }
828
829 if ( ! function_exists( 'tutor_course_benefits_html' ) ) {
830 /**
831 * Course single page benefits.
832 *
833 * @since 1.0.0
834 *
835 * @param bool $echo whether to echo content.
836 *
837 * @return string
838 */
839 function tutor_course_benefits_html( $echo = true ) {
840 ob_start();
841 tutor_load_template( 'single.course.course-benefits' );
842 $output = apply_filters( 'tutor_course/single/benefits_html', ob_get_clean() );
843
844 if ( $echo ) {
845 echo wp_kses_post( $output );
846 }
847 return $output;
848 }
849 }
850
851 if ( ! function_exists( 'tutor_course_topics' ) ) {
852 /**
853 * Return Topics HTML.
854 *
855 * @since 1.0.0
856 *
857 * @param bool $echo whether to echo content.
858 *
859 * @return string
860 */
861 function tutor_course_topics( $echo = true ) {
862 ob_start();
863 tutor_load_template( 'single.course.course-topics' );
864 $output = apply_filters( 'tutor_course/single/topics', ob_get_clean() );
865 wp_reset_postdata();
866
867 if ( $echo ) {
868 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
869 }
870
871 return $output;
872 }
873 }
874
875 if ( ! function_exists( 'tutor_course_requirements' ) ) {
876 /**
877 * Return course requirements in array.
878 *
879 * @since 1.0.0
880 *
881 * @param int $course_id course ID.
882 *
883 * @return array
884 */
885 function tutor_course_requirements( $course_id = 0 ) {
886 if ( ! $course_id ) {
887 $course_id = get_the_ID();
888 }
889 $requirements = get_post_meta( $course_id, '_tutor_course_requirements', true );
890
891 $requirements_array = array();
892 if ( $requirements ) {
893 $requirements_array = explode( "\n", $requirements );
894 }
895
896 $array = array_filter( array_map( 'trim', $requirements_array ) );
897 return apply_filters( 'tutor_course/single/requirements', $array, $course_id );
898 }
899 }
900
901 if ( ! function_exists( 'tutor_course_requirements_html' ) ) {
902 /**
903 * Return course requirements in course single page.
904 *
905 * @since 1.0.0
906 *
907 * @param bool $echo whether to echo content.
908 *
909 * @return string
910 */
911 function tutor_course_requirements_html( $echo = true ) {
912 ob_start();
913 tutor_course_material_includes_html();
914 tutor_load_template( 'single.course.course-requirements' );
915 $output = apply_filters( 'tutor_course/single/requirements_html', ob_get_clean() );
916
917 if ( $echo ) {
918 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
919 }
920 return $output;
921 }
922 }
923
924
925 if ( ! function_exists( 'tutor_course_target_audience' ) ) {
926 /**
927 * Return target audience in course single page.
928 *
929 * @since 1.0.0
930 *
931 * @param int $course_id course ID.
932 *
933 * @return array
934 */
935 function tutor_course_target_audience( $course_id = 0 ) {
936 if ( ! $course_id ) {
937 $course_id = get_the_ID();
938 }
939 $target_audience = get_post_meta( $course_id, '_tutor_course_target_audience', true );
940
941 $target_audience_array = array();
942 if ( $target_audience ) {
943 $target_audience_array = explode( "\n", $target_audience );
944 }
945
946 $array = array_filter( array_map( 'trim', $target_audience_array ) );
947 return apply_filters( 'tutor_course/single/target_audience', $array, $course_id );
948 }
949 }
950
951 if ( ! function_exists( 'tutor_course_target_audience_html' ) ) {
952 /**
953 * Return target audience in course single page.
954 *
955 * @since 1.0.0
956 *
957 * @param bool $echo whether to echo content.
958 *
959 * @return string|void
960 */
961 function tutor_course_target_audience_html( $echo = true ) {
962 ob_start();
963 tutor_load_template( 'single.course.course-target-audience' );
964 $output = apply_filters( 'tutor_course/single/audience_html', ob_get_clean() );
965
966 if ( $echo ) {
967 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
968 }
969 return $output;
970 }
971 }
972
973
974 if ( ! function_exists( 'tutor_course_material_includes' ) ) {
975 /**
976 * Return course material includes.
977 *
978 * @since 1.0.0
979 *
980 * @param int $course_id course ID.
981 *
982 * @return array
983 */
984 function tutor_course_material_includes( $course_id = 0 ) {
985 if ( ! $course_id ) {
986 $course_id = get_the_ID();
987 }
988 $target_audience = get_post_meta( $course_id, '_tutor_course_material_includes', true );
989
990 $target_audience_array = array();
991 if ( $target_audience ) {
992 $target_audience_array = explode( "\n", $target_audience );
993 }
994
995 $array = array_filter( array_map( 'trim', $target_audience_array ) );
996 return apply_filters( 'tutor_course/single/material_includes', $array, $course_id );
997 }
998 }
999
1000 if ( ! function_exists( 'tutor_course_material_includes_html' ) ) {
1001 /**
1002 * Return course material includes HTML.
1003 *
1004 * @since 1.0.0
1005 *
1006 * @param bool $echo whether to echo content.
1007 *
1008 * @return string
1009 */
1010 function tutor_course_material_includes_html( $echo = true ) {
1011 ob_start();
1012 tutor_load_template( 'single.course.material-includes' );
1013 $output = apply_filters( 'tutor_course/single/material_includes', ob_get_clean() );
1014
1015 if ( $echo ) {
1016 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1017 }
1018 return $output;
1019 }
1020 }
1021
1022
1023 if ( ! function_exists( 'tutor_course_instructors_html' ) ) {
1024 /**
1025 * Return course instructors HTML.
1026 *
1027 * @since 1.0.0
1028 *
1029 * @param bool $echo whether to echo content.
1030 *
1031 * @return string|void
1032 */
1033 function tutor_course_instructors_html( $echo = true ) {
1034 $display_course_instructors = tutor_utils()->get_option( 'display_course_instructors' );
1035 if ( ! $display_course_instructors ) {
1036 return null;
1037 }
1038
1039 ob_start();
1040 tutor_load_template( 'single.course.instructors' );
1041 $output = apply_filters( 'tutor_course/single/instructors_html', ob_get_clean() );
1042
1043 if ( $echo ) {
1044 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1045 }
1046 return $output;
1047 }
1048 }
1049
1050 if ( ! function_exists( 'tutor_course_target_reviews_html' ) ) {
1051 /**
1052 * Return course reviews HTML.
1053 *
1054 * @since 1.0.0
1055 *
1056 * @param bool $echo whether to echo content.
1057 *
1058 * @return string|void
1059 */
1060 function tutor_course_target_reviews_html( $echo = true ) {
1061 ob_start();
1062 tutor_load_template( 'single.course.reviews' );
1063
1064 $output = apply_filters( 'tutor_course/single/reviews_html', ob_get_clean() );
1065
1066 if ( $echo ) {
1067 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1068 }
1069 return $output;
1070 }
1071 }
1072
1073 if ( ! function_exists( 'tutor_course_content' ) ) {
1074 /**
1075 * Course single page main content / description.
1076 *
1077 * @since 1.0.0
1078 *
1079 * @param bool $echo whether to echo content.
1080 *
1081 * @return string|void
1082 */
1083 function tutor_course_content( $echo = true ) {
1084 ob_start();
1085 tutor_load_template( 'single.course.course-content' );
1086 $output = apply_filters( 'tutor_course/single/content', ob_get_clean() );
1087
1088 if ( $echo ) {
1089 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1090 }
1091
1092 return $output;
1093 }
1094 }
1095
1096 if ( ! function_exists( 'tutor_course_lead_info' ) ) {
1097 /**
1098 * Course single page lead info.
1099 *
1100 * @since 1.0.0
1101 *
1102 * @param bool $echo whether to echo content.
1103 *
1104 * @return string|void
1105 */
1106 function tutor_course_lead_info( $echo = true ) {
1107 ob_start();
1108
1109 $course_id = get_the_ID();
1110 $course_post_type = tutor()->course_post_type;
1111 $query_course = new WP_Query(
1112 apply_filters(
1113 'tutor_course_lead_info_args',
1114 array(
1115 'p' => $course_id,
1116 'post_type' => $course_post_type,
1117 )
1118 )
1119 );
1120
1121 if ( $query_course->have_posts() ) {
1122 while ( $query_course->have_posts() ) {
1123 $query_course->the_post();
1124 tutor_load_template( 'single.course.lead-info' );
1125 }
1126 wp_reset_postdata();
1127 }
1128
1129 $output = apply_filters( 'tutor_course/single/lead_info', ob_get_clean() );
1130
1131 if ( $echo ) {
1132 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1133 }
1134 return $output;
1135 }
1136 }
1137
1138 if ( ! function_exists( 'tutor_course_enrolled_lead_info' ) ) {
1139 /**
1140 * Course enrolled lead info.
1141 *
1142 * @since 1.0.0
1143 *
1144 * @param bool $echo whether to echo content.
1145 *
1146 * @return string|void
1147 */
1148 function tutor_course_enrolled_lead_info( $echo = true ) {
1149 ob_start();
1150
1151 $course_id = get_the_ID();
1152 $course_post_type = tutor()->course_post_type;
1153 $query_course = new WP_Query(
1154 array(
1155 'p' => $course_id,
1156 'post_type' => $course_post_type,
1157 )
1158 );
1159
1160 if ( $query_course->have_posts() ) {
1161 while ( $query_course->have_posts() ) {
1162 $query_course->the_post();
1163 tutor_load_template( 'single.course.lead-info' );
1164 }
1165 wp_reset_postdata();
1166 }
1167
1168 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
1169
1170 if ( $echo ) {
1171 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1172 }
1173
1174 return $output;
1175 }
1176 }
1177
1178 if ( ! function_exists( 'tutor_lesson_lead_info' ) ) {
1179 /**
1180 * Lesson lead info.
1181 *
1182 * @since 1.0.0
1183 *
1184 * @param int $lesson_id lesson id.
1185 * @param bool $echo whether to echo content.
1186 *
1187 * @return string|void
1188 */
1189 function tutor_lesson_lead_info( $lesson_id = 0, $echo = true ) {
1190 if ( ! $lesson_id ) {
1191 $lesson_id = get_the_ID();
1192 }
1193
1194 ob_start();
1195 $course_id = tutor_utils()->get_course_id_by( 'lesson', $lesson_id );
1196 $course_post_type = tutor()->course_post_type;
1197 $query_course = new WP_Query(
1198 array(
1199 'p' => $course_id,
1200 'post_type' => $course_post_type,
1201 )
1202 );
1203
1204 if ( $query_course->have_posts() ) {
1205 while ( $query_course->have_posts() ) {
1206 $query_course->the_post();
1207 tutor_load_template( 'single.course.lead-info' );
1208 }
1209 wp_reset_postdata();
1210 }
1211 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
1212
1213 if ( $echo ) {
1214 echo $output; //phpcs:ignore -- already escaped inside template file
1215 }
1216
1217 return $output;
1218 }
1219 }
1220
1221 if ( ! function_exists( 'tutor_course_video' ) ) {
1222 /**
1223 * Course video.
1224 *
1225 * @since 1.0.0
1226 *
1227 * @param bool $echo whether to echo content.
1228 *
1229 * @return string|void
1230 */
1231 function tutor_course_video( $echo = true ) {
1232 ob_start();
1233 tutor_load_template( 'single.video.video' );
1234 $output = apply_filters( 'tutor_course/single/video', ob_get_clean() );
1235
1236 if ( $echo ) {
1237 echo $output; //phpcs:ignore -- already escaped inside template file
1238 }
1239 return $output;
1240 }
1241 }
1242
1243 if ( ! function_exists( 'tutor_lesson_video' ) ) {
1244 /**
1245 * Lesson video.
1246 *
1247 * @since 1.0.0
1248 *
1249 * @param bool $echo whether to echo content.
1250 *
1251 * @return string|void
1252 */
1253 function tutor_lesson_video( $echo = true ) {
1254 ob_start();
1255 tutor_load_template( 'single.video.video' );
1256 $output = apply_filters( 'tutor_lesson/single/video', ob_get_clean() );
1257
1258 if ( $echo ) {
1259 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1260 }
1261 return $output;
1262 }
1263 }
1264
1265 if ( ! function_exists( 'get_tutor_posts_attachments' ) ) {
1266 /**
1267 * Get all lessons attachments.
1268 *
1269 * @since 1.0.0
1270 *
1271 * @param bool $echo whether to echo content.
1272 *
1273 * @return string|void
1274 */
1275 function get_tutor_posts_attachments( $echo = true ) {
1276 ob_start();
1277 tutor_load_template( 'global.attachments' );
1278 $output = apply_filters( 'tutor_lesson/single/attachments', ob_get_clean() );
1279
1280 if ( $echo ) {
1281 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1282 }
1283 return $output;
1284 }
1285 }
1286
1287 if ( ! function_exists( 'tutor_lesson_content' ) ) {
1288 /**
1289 * Render Lesson Main Content.
1290 *
1291 * @since 1.0.0
1292 *
1293 * @param bool $echo whether to echo content.
1294 *
1295 * @return string|void
1296 */
1297 function tutor_lesson_content( $echo = true ) {
1298 ob_start();
1299 tutor_load_template( 'single.lesson.content' );
1300 $output = apply_filters( 'tutor_lesson/single/content', ob_get_clean() );
1301
1302 if ( $echo ) {
1303 echo $output; //phpcs:ignore -- already escaped inside template file
1304 }
1305
1306 return $output;
1307 }
1308 }
1309
1310 if ( ! function_exists( 'tutor_lesson_mark_complete_html' ) ) {
1311 /**
1312 * Lesson mark complete HTML.
1313 *
1314 * @since 1.0.0
1315 *
1316 * @param bool $echo whether to echo content.
1317 *
1318 * @return string|void
1319 */
1320 function tutor_lesson_mark_complete_html( $echo = true ) {
1321 ob_start();
1322 tutor_load_template( 'single.lesson.complete_form' );
1323 $output = apply_filters( 'tutor_lesson/single/complete_form', ob_get_clean() );
1324
1325 if ( $echo ) {
1326 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1327 }
1328
1329 return $output;
1330 }
1331 }
1332
1333 /**
1334 * Course question and answer.
1335 *
1336 * @since 1.0.0
1337 *
1338 * @param bool $echo whether to echo content.
1339 *
1340 * @return string|void
1341 */
1342 function tutor_course_question_and_answer( $echo = true ) {
1343 ob_start();
1344 tutor_load_template( 'single.course.enrolled.question_and_answer' );
1345 $output = apply_filters( 'tutor_course/single/question_and_answer', ob_get_clean() );
1346
1347 if ( $echo ) {
1348 echo $output; //phpcs:ignore -- already escaped inside template file
1349 }
1350
1351 return $output;
1352 }
1353
1354 /**
1355 * Render course info tab content.
1356 *
1357 * @since 2.0.0
1358 * @since 2.0.5 updated.
1359 *
1360 * @return void
1361 */
1362 function tutor_course_info_tab() {
1363 tutor_course_content();
1364 tutor_course_benefits_html();
1365 tutor_course_topics();
1366 }
1367
1368
1369 /**
1370 * Course announcements.
1371 *
1372 * @since 1.0.0
1373 *
1374 * @param bool $echo whether to echo content.
1375 *
1376 * @return string|void
1377 */
1378 function tutor_course_announcements( $echo = true ) {
1379 ob_start();
1380 tutor_load_template( 'single.course.enrolled.announcements' );
1381 $output = apply_filters( 'tutor_course/single/announcements', ob_get_clean() );
1382
1383 if ( $echo ) {
1384 echo $output; //phpcs:ignore -- already escaped inside template file
1385 }
1386
1387 return $output;
1388 }
1389
1390 /**
1391 * Single quiz top.
1392 *
1393 * @since 1.0.0
1394 *
1395 * @param bool $echo whether to echo content.
1396 *
1397 * @return string|void
1398 */
1399 function tutor_single_quiz_top( $echo = true ) {
1400 ob_start();
1401 tutor_load_template( 'single.quiz.top' );
1402 $output = apply_filters( 'tutor_single_quiz/top', ob_get_clean() );
1403
1404 if ( $echo ) {
1405 echo $output; //phpcs:ignore -- already escaped inside template file
1406 }
1407 return $output;
1408 }
1409
1410 /**
1411 * Single quiz body.
1412 *
1413 * @since 1.0.0
1414 *
1415 * @param bool $echo whether to echo content.
1416 *
1417 * @return string|void
1418 */
1419 function tutor_single_quiz_body( $echo = true ) {
1420 ob_start();
1421 tutor_load_template( 'single.quiz.body' );
1422 $output = apply_filters( 'tutor_single_quiz/body', ob_get_clean() );
1423
1424 if ( $echo ) {
1425 echo $output; //phpcs:ignore -- data already escaped inside template file
1426 }
1427 return $output;
1428 }
1429
1430 /**
1431 * Get the quiz description.
1432 *
1433 * @since 1.0.0
1434 *
1435 * @param bool $echo whether to echo content.
1436 *
1437 * @return string|void
1438 */
1439 function tutor_single_quiz_content( $echo = true ) {
1440 ob_start();
1441 tutor_load_template( 'single.quiz.content' );
1442 $output = apply_filters( 'tutor_single_quiz/content', ob_get_clean() );
1443
1444 if ( $echo ) {
1445 echo $output; //phpcs:ignore -- already escaped inside template file
1446 }
1447 return $output;
1448 }
1449
1450
1451 /**
1452 * Single quiz no course belongs.
1453 *
1454 * @since 1.0.0
1455 *
1456 * @param bool $echo whether to echo content.
1457 *
1458 * @return string|void
1459 */
1460 function tutor_single_quiz_no_course_belongs( $echo = true ) {
1461 ob_start();
1462 tutor_load_template( 'single.quiz.no_course_belongs' );
1463 $output = apply_filters( 'tutor_single_quiz/no_course_belongs', ob_get_clean() );
1464
1465 if ( $echo ) {
1466 echo $output; //phpcs:ignore -- already escaped inside template file
1467 }
1468 return $output;
1469 }
1470
1471 /**
1472 * Single quiz contents.
1473 *
1474 * @since 1.0.0
1475 *
1476 * @param bool $echo whether to echo content.
1477 *
1478 * @return string|void
1479 */
1480 function single_quiz_contents( $echo = true ) {
1481
1482 ob_start();
1483 tutor_load_template( 'single.quiz.single_quiz_contents' );
1484 $output = apply_filters( 'tutor_single_quiz/single_quiz_contents', ob_get_clean() );
1485
1486 if ( $echo ) {
1487 echo $output; //phpcs:ignore -- already escaped inside template file
1488 }
1489 return $output;
1490 }
1491
1492 /**
1493 * Get course level.
1494 *
1495 * @since 1.0.0
1496 *
1497 * @param int $course_id course ID.
1498 *
1499 * @return string|bool
1500 */
1501 function get_tutor_course_level( $course_id = 0 ) {
1502 if ( ! $course_id ) {
1503 $course_id = get_the_ID();
1504 }
1505 if ( ! $course_id ) {
1506 return '';
1507 }
1508
1509 $course_level = get_post_meta( $course_id, '_tutor_course_level', true );
1510
1511 if ( $course_level ) {
1512 return tutor_utils()->course_levels( $course_level );
1513 }
1514 return false;
1515 }
1516
1517 if ( ! function_exists( 'get_tutor_course_duration_context' ) ) {
1518 /**
1519 * Get course duration context.
1520 *
1521 * @since 1.0.0
1522 *
1523 * @param int $course_id course ID.
1524 * @param bool $short_form whether to use short form.
1525 *
1526 * @return string|bool
1527 */
1528 function get_tutor_course_duration_context( $course_id = 0, $short_form = false ) {
1529 if ( ! $course_id ) {
1530 $course_id = get_the_ID();
1531 }
1532 if ( ! $course_id ) {
1533 return '';
1534 }
1535
1536 $duration = get_post_meta( $course_id, '_course_duration', true );
1537 $duration_hours = tutor_utils()->avalue_dot( 'hours', $duration );
1538 $duration_minutes = tutor_utils()->avalue_dot( 'minutes', $duration );
1539 $duration_seconds = tutor_utils()->avalue_dot( 'seconds', $duration );
1540
1541 $hour_format = $short_form ? __( 'h', 'tutor' ) : ' ' . ( $duration_hours > 1 ? __( 'hours', 'tutor' ) : __( 'hour', 'tutor' ) );
1542 $minute_format = $short_form ? __( 'm', 'tutor' ) : ' ' . ( $duration_minutes > 1 ? __( 'minutes', 'tutor' ) : __( 'minute', 'tutor' ) );
1543 $second_format = $short_form ? __( 's', 'tutor' ) : ' ' . ( $duration_seconds > 1 ? __( 'seconds', 'tutor' ) : __( 'second', 'tutor' ) );
1544
1545 if ( $duration ) {
1546 $output = '';
1547 if ( $duration_hours > 0 ) {
1548 $output .= '<span class="tutor-meta-level">' . $duration_hours . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $hour_format . '</span>';
1549 }
1550
1551 if ( $duration_minutes > 0 ) {
1552 $output .= '<span class="tutor-meta-level">' . $duration_minutes . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $minute_format . '</span>';
1553 }
1554
1555 if ( ! $duration_hours && ! $duration_minutes && $duration_seconds > 0 ) {
1556 $output .= '<span class="tutor-meta-level">' . $duration_seconds . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $second_format . '</span>';
1557 }
1558
1559 return $output;
1560 }
1561
1562 return false;
1563 }
1564 }
1565 if ( ! function_exists( 'get_tutor_course_categories' ) ) {
1566 /**
1567 * Get course categories.
1568 *
1569 * @since 1.0.0
1570 *
1571 * @param int $course_id course ID.
1572 *
1573 * @return array|bool|WP_Error
1574 */
1575 function get_tutor_course_categories( $course_id = 0 ) {
1576 if ( ! $course_id ) {
1577 $course_id = get_the_ID();
1578 }
1579 $terms = get_the_terms( $course_id, CourseModel::COURSE_CATEGORY );
1580
1581 return $terms;
1582 }
1583 }
1584
1585 if ( ! function_exists( 'get_tutor_course_tags' ) ) {
1586 /**
1587 * Get course tags.
1588 *
1589 * @since 1.0.0
1590 *
1591 * @param int $course_id course ID.
1592 *
1593 * @return array|false|WP_Error
1594 */
1595 function get_tutor_course_tags( $course_id = 0 ) {
1596 if ( ! $course_id ) {
1597 $course_id = get_the_ID();
1598 }
1599 $terms = get_the_terms( $course_id, CourseModel::COURSE_TAG );
1600
1601 return $terms;
1602 }
1603 }
1604
1605 if ( ! function_exists( 'tutor_course_tags_html' ) ) {
1606 /**
1607 * Template for course tags html.
1608 *
1609 * @since 1.0.0
1610 *
1611 * @param bool $echo whether to echo content.
1612 *
1613 * @return string
1614 */
1615 function tutor_course_tags_html( $echo = true ) {
1616 ob_start();
1617 tutor_load_template( 'single.course.tags' );
1618 $output = apply_filters( 'tutor_course/single/tags_html', ob_get_clean() );
1619
1620 if ( $echo ) {
1621 echo tutor_kses_html( $output ); //phpcs:ignore
1622 }
1623
1624 return $output;
1625 }
1626 }
1627
1628 if ( ! function_exists( 'tutor_lesson_sidebar_question_and_answer' ) ) {
1629 /**
1630 * Get Q&A in lesson sidebar.
1631 *
1632 * @since 1.0.0
1633 *
1634 * @param bool $echo whether to echo content.
1635 *
1636 * @return string|void
1637 */
1638 function tutor_lesson_sidebar_question_and_answer( $echo = true ) {
1639 ob_start();
1640 tutor_load_template( 'single.lesson.sidebar_question_and_answer' );
1641 $output = apply_filters( 'tutor_lesson/single/sidebar_question_and_answer', ob_get_clean() );
1642
1643 if ( $echo ) {
1644 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1645 }
1646
1647 return $output;
1648 }
1649 }
1650
1651 if ( ! function_exists( 'tutor_assignment_content' ) ) {
1652 /**
1653 * Get Assignment content.
1654 *
1655 * @since 1.3.3
1656 *
1657 * @param bool $echo whether to echo content.
1658 *
1659 * @return string|void
1660 */
1661 function tutor_assignment_content( $echo = true ) {
1662 $output = apply_filters( 'tutor_assignment/single/content', '' );
1663
1664 if ( $echo ) {
1665 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1666 }
1667
1668 return $output;
1669 }
1670 }
1671
1672 if ( ! function_exists( 'get_tnotice' ) ) {
1673 /**
1674 * Get notice.
1675 *
1676 * @since 1.4.0
1677 *
1678 * @param string $msg message.
1679 * @param string $title title.
1680 * @param string $type type.
1681 *
1682 * @return string
1683 */
1684 function get_tnotice( $msg = '', $title = 'Success', $type = 'success' ) {
1685
1686 $output = '<div class="tnotice tnotice--' . $type . '">
1687 <div class="tnotice__icon">&iexcl;</div>
1688 <div class="tnotice__content">';
1689
1690 if ( $title ) {
1691 $output .= '<p class="tnotice__type">' . $title . '</p>';
1692 }
1693 $output .= '<p class="tnotice__message">' . $msg . '</p>
1694 </div>
1695 </div>';
1696
1697 return $output;
1698 }
1699 }
1700
1701 /**
1702 * Next Previous Pagination.
1703 *
1704 * @since 1.4.7
1705 *
1706 * @param int $course_content_id course content ID.
1707 * @param bool $echo whether to echo content.
1708 *
1709 * @return string|void
1710 */
1711 function tutor_next_previous_pagination( $course_content_id = 0, $echo = true ) {
1712 $content_id = tutor_utils()->get_post_id( $course_content_id );
1713 $contents = tutor_utils()->get_course_prev_next_contents_by_id( $content_id );
1714 $previous_id = $contents->previous_id;
1715 $next_id = $contents->next_id;
1716
1717 ob_start();
1718 do_action( 'tutor_lesson_next_previous_pagination_before' );
1719 tutor_load_template( 'single.next-previous-pagination', compact( 'previous_id', 'next_id' ) );
1720 do_action( 'tutor_lesson_next_previous_pagination_after' );
1721 $output = apply_filters( 'tutor/single/next_previous_pagination', ob_get_clean() );
1722
1723 if ( $echo ) {
1724 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1725 }
1726
1727 return $output;
1728 }
1729
1730 if ( ! function_exists( 'tutor_load_template_from_custom_path' ) ) {
1731 /**
1732 * Load custom template from any given file.
1733 *
1734 * @since 1.9.8
1735 *
1736 * @param string $template template path.
1737 * @param array $data data to pass.
1738 * @param bool $once whether to include once.
1739 *
1740 * @return void
1741 */
1742 function tutor_load_template_from_custom_path( $template = null, $data = array(), $once = true ) {
1743 do_action( 'tutor_load_template_from_custom_path_before', $template, $data );
1744 if ( file_exists( $template ) ) {
1745 if ( $once ) {
1746 include_once $template;
1747 } else {
1748 include $template;
1749 }
1750 }
1751 do_action( 'tutor_load_template_from_custom_path_after', $template, $data );
1752 }
1753 }
1754
1755 if ( ! function_exists( 'tutor_enrolled_course_progress' ) ) {
1756 /**
1757 * Load enrolled course progress template.
1758 *
1759 * @since 2.0.0
1760 *
1761 * @return void
1762 */
1763 function tutor_enrolled_course_progress() {
1764 global $wp_query;
1765 $query_vars = $wp_query->query_vars;
1766 if ( isset( $query_vars['tutor_dashboard_page'] ) && 'enrolled-courses' === $query_vars['tutor_dashboard_page'] ) {
1767 tutor_load_template_from_custom_path( tutor()->path . 'templates/loop/enrolled-course-progress.php', '', false );
1768 }
1769 }
1770 }
1771
1772 if ( ! function_exists( 'tutor_permission_denied_template' ) ) {
1773 /**
1774 * Load permission denied template.
1775 *
1776 * It will load permission denied template & return so not code
1777 * after this will execute
1778 *
1779 * @since 2.2.0
1780 *
1781 * @param integer $post_id post id if 0 then current post id will be used.
1782 *
1783 * @return void
1784 */
1785 function tutor_permission_denied_template( int $post_id = 0 ) {
1786 if ( ! $post_id ) {
1787 $post_id = get_the_ID();
1788 }
1789
1790 $args = array(
1791 'headline' => __( 'Permission Denied', 'tutor' ),
1792 'message' => __( 'You don\'t have the right to edit this course', 'tutor' ),
1793 'description' => __( 'Please make sure you are logged in to correct account', 'tutor' ),
1794 'button' => array(
1795 'url' => get_permalink( $post_id ),
1796 'text' => __( 'View Course', 'tutor' ),
1797 ),
1798 );
1799
1800 tutor_load_template( 'permission-denied', $args );
1801 return;
1802 }
1803 }
1804
1805 if ( ! function_exists( 'get_template_buffer' ) ) {
1806 /**
1807 * Render a template and return its output as a string.
1808 *
1809 * @since 4.0.0
1810 *
1811 * @param string $template Template file path or slug.
1812 * @param array $data Data to be passed to the template.
1813 * @param bool $once Whether the template should be loaded only once.
1814 * Defaults to true.
1815 *
1816 * @return string Rendered template output.
1817 */
1818 function get_template_buffer( $template, $data, $once = true ) {
1819
1820 ob_start();
1821
1822 tutor_load_template_from_custom_path( $template, $data, $once );
1823
1824 return ob_get_clean();
1825 }
1826 }
1827