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