PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.4.0
Tutor LMS – eLearning and online course solution v3.4.0
3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / includes / tutor-template-functions.php
tutor / includes Last commit date
theme-compatibility 4 years ago country.php 1 year ago tinymce_translate.php 1 year ago translate-text.php 1 year ago tutor-general-functions.php 1 year ago tutor-template-functions.php 1 year ago tutor-template-hook.php 4 years ago
tutor-template-functions.php
1622 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 use Tutor\Models\CourseModel;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17
18 if ( ! function_exists( 'tutor_get_template' ) ) {
19 /**
20 * Load template with override file system
21 *
22 * @since 1.0.0
23 *
24 * @param null $template template.
25 * @param bool $tutor_pro is tutor pro.
26 *
27 * @return bool|string
28 */
29 function tutor_get_template( $template = null, $tutor_pro = false ) {
30 if ( ! $template ) {
31 return false;
32 }
33 $template = str_replace( '.', DIRECTORY_SEPARATOR, $template );
34
35 /**
36 * Get template first from child-theme if exists
37 * If child theme not exists, then get template from parent theme
38 */
39 $template_location = trailingslashit( get_stylesheet_directory() ) . "tutor/{$template}.php";
40 if ( ! file_exists( $template_location ) ) {
41 $template_location = trailingslashit( get_template_directory() ) . "tutor/{$template}.php";
42 }
43 $file_in_theme = $template_location;
44 if ( ! file_exists( $template_location ) ) {
45 $template_location = trailingslashit( tutor()->path ) . "templates/{$template}.php";
46
47 if ( $tutor_pro && function_exists( 'tutor_pro' ) ) {
48 $pro_template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
49 if ( file_exists( $pro_template_location ) ) {
50 $template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
51 }
52 }
53
54 if ( ! file_exists( $template_location ) ) {
55 $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' );
56 $warning_msg = $warning_msg . "<code>$file_in_theme</code>";
57 $warning_msg = apply_filters( 'tutor_not_found_template_warning_msg', $warning_msg );
58 echo wp_kses( $warning_msg, array( 'code' => true ) );
59 ?>
60 <?php
61 }
62 }
63
64 return apply_filters( 'tutor_get_template_path', $template_location, $template );
65 }
66 }
67
68 if ( ! function_exists( 'tutor_get_template_path' ) ) {
69 /**
70 * Get only template path without any warning...
71 *
72 * @since 1.4.2
73 *
74 * @param null $template template.
75 * @param bool $tutor_pro is tutor pro.
76 *
77 * @return bool|mixed|void
78 */
79 function tutor_get_template_path( $template = null, $tutor_pro = false ) {
80 if ( ! $template ) {
81 return false;
82 }
83 $template = str_replace( '.', DIRECTORY_SEPARATOR, $template );
84
85 /**
86 * Get template first from child-theme if exists
87 * If child theme not exists, then get template from parent theme
88 */
89 $template_location = trailingslashit( get_stylesheet_directory() ) . "tutor/{$template}.php";
90 if ( ! file_exists( $template_location ) ) {
91 $template_location = trailingslashit( get_template_directory() ) . "tutor/{$template}.php";
92 }
93 if ( ! file_exists( $template_location ) ) {
94 $template_location = trailingslashit( tutor()->path ) . "templates/{$template}.php";
95 }
96 if ( ! file_exists( $template_location ) && $tutor_pro && function_exists( 'tutor_pro' ) ) {
97 $template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
98 }
99
100 return apply_filters( 'tutor_get_template_path', $template_location, $template );
101 }
102 }
103
104 if ( ! function_exists( 'tutor_load_template' ) ) {
105 /**
106 * Load template for TUTOR
107 *
108 * @since 1.0.0
109 * @since 1.1.2 updated
110 *
111 * @param null $template template.
112 * @param array $variables variables.
113 * @param bool $tutor_pro is tutor pro.
114 *
115 * @return void
116 */
117 function tutor_load_template( $template = null, $variables = array(), $tutor_pro = false ) {
118 $variables = (array) $variables;
119 $variables = apply_filters( 'get_tutor_load_template_variables', $variables );
120 extract( $variables );
121
122 $isLoad = apply_filters( 'should_tutor_load_template', true, $template, $variables );
123 if ( ! $isLoad ) {
124 return;
125 }
126
127 do_action( 'tutor_load_template_before', $template, $variables );
128 $template_file = tutor_get_template( $template, $tutor_pro );
129 if ( file_exists( $template_file ) ) {
130 include tutor_get_template( $template, $tutor_pro );
131 } else {
132 do_action( 'tutor_after_template_not_found', $template );
133 }
134 do_action( 'tutor_load_template_after', $template, $variables );
135 }
136 }
137
138 if ( ! function_exists( 'tutor_load_template_part' ) ) {
139 /**
140 * Load tutor template part.
141 *
142 * @since 1.4.3
143 *
144 * @param null $template template.
145 * @param array $variables variables.
146 * @param bool $tutor_pro is tutor pro.
147 *
148 * @return void
149 */
150 function tutor_load_template_part( $template = null, $variables = array(), $tutor_pro = false ) {
151 $variables = (array) $variables;
152 $variables = apply_filters( 'get_tutor_load_template_variables', $variables );
153 extract( $variables );
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 null $template template.
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 boolean $echo echo.
202 *
203 * @return mixed
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 boolean $echo echo.
224 *
225 * @return mixed
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 /**
241 * Tutor course loop before content.
242 *
243 * @since 1.0.0
244 *
245 * @return void
246 */
247 function tutor_course_loop_before_content() {
248 ob_start();
249 tutor_load_template( 'loop.loop-before-content' );
250
251 $output = apply_filters( 'tutor_course_loop_before_content', ob_get_clean() );
252 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
253 }
254
255 /**
256 * Tutor course loop after content.
257 *
258 * @since 1.0.0
259 *
260 * @return void
261 */
262 function tutor_course_loop_after_content() {
263 ob_start();
264 tutor_load_template( 'loop.loop-after-content' );
265
266 $output = apply_filters( 'tutor_course_loop_after_content', ob_get_clean() );
267 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
268 }
269
270 if ( ! function_exists( 'tutor_course_loop_title' ) ) {
271 /**
272 * Tutor course loop title.
273 *
274 * @since 1.0.0
275 *
276 * @return void
277 */
278 function tutor_course_loop_title() {
279 ob_start();
280 tutor_load_template( 'loop.title' );
281 $output = apply_filters( 'tutor_course_loop_title', ob_get_clean() );
282
283 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
284 }
285 }
286
287
288 if ( ! function_exists( 'tutor_course_loop_header' ) ) {
289 /**
290 * Tutor course loop header.
291 *
292 * @since 1.0.0
293 *
294 * @return void
295 */
296 function tutor_course_loop_header() {
297 ob_start();
298 tutor_load_template( 'loop.header' );
299 $output = apply_filters( 'tutor_course_loop_header', ob_get_clean() );
300
301 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
302 }
303 }
304
305 if ( ! function_exists( 'tutor_course_loop_footer' ) ) {
306 /**
307 * Tutor course loop footer.
308 *
309 * @since 1.0.0
310 *
311 * @return void
312 */
313 function tutor_course_loop_footer() {
314 ob_start();
315 tutor_load_template( 'loop.footer' );
316 $output = apply_filters( 'tutor_course_loop_footer', ob_get_clean() );
317
318 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
319 }
320 }
321
322 if ( ! function_exists( 'tutor_course_loop_start_content_wrap' ) ) {
323 /**
324 * Tutor course loop start content wrap.
325 *
326 * @since 1.0.0
327 *
328 * @return void
329 */
330 function tutor_course_loop_start_content_wrap() {
331 ob_start();
332 tutor_load_template( 'loop.start_content_wrap' );
333 $output = apply_filters( 'tutor_course_loop_start_content_wrap', ob_get_clean() );
334
335 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
336 }
337 }
338
339 if ( ! function_exists( 'tutor_course_loop_end_content_wrap' ) ) {
340 /**
341 * Tutor course loop end content wrap.
342 *
343 * @since 1.0.0
344 *
345 * @return void
346 */
347 function tutor_course_loop_end_content_wrap() {
348 ob_start();
349 tutor_load_template( 'loop.end_content_wrap' );
350 $output = apply_filters( 'tutor_course_loop_end_content_wrap', ob_get_clean() );
351
352 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
353 }
354 }
355
356 if ( ! function_exists( 'tutor_course_loop_thumbnail' ) ) {
357 /**
358 * Tutor course loop thumbnail.
359 *
360 * @since 1.0.0
361 *
362 * @param boolean $echo echo.
363 *
364 * @return mixed
365 */
366 function tutor_course_loop_thumbnail( $echo = true ) {
367 ob_start();
368 tutor_load_template( 'loop.thumbnail' );
369 $output = apply_filters( 'tutor_course_loop_thumbnail', ob_get_clean() );
370
371 if ( $echo ) {
372 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
373 } else {
374 return $output;
375 }
376 }
377 }
378
379 if ( ! function_exists( 'tutor_course_loop_wrap_classes' ) ) {
380 /**
381 * Tutor course loop wrap classes.
382 *
383 * @since 1.0.0
384 *
385 * @param boolean $echo echo.
386 *
387 * @return mixed
388 */
389 function tutor_course_loop_wrap_classes( $echo = true ) {
390 $courseID = get_the_ID();
391 $classes = apply_filters(
392 'tutor_course_loop_wrap_classes',
393 array(
394 'tutor-course',
395 'tutor-course-loop',
396 'tutor-course-loop-' . $courseID,
397 )
398 );
399
400 $class = implode( ' ', $classes );
401 if ( $echo ) {
402 echo esc_attr( $class );
403 }
404
405 return esc_attr( $class );
406 }
407 }
408
409 if ( ! function_exists( 'tutor_course_loop_col_classes' ) ) {
410 /**
411 * Tutor course loop col classes.
412 *
413 * @since 1.0.0
414 *
415 * @param boolean $echo echo.
416 *
417 * @return mixed
418 */
419 function tutor_course_loop_col_classes( $echo = true ) {
420 $course_filter = (bool) tutor_utils()->get_option( 'course_archive_filter', false );
421 $course_archive_arg = isset( $GLOBALS['tutor_course_archive_arg'] ) ? $GLOBALS['tutor_course_archive_arg']['column_per_row'] : null;
422 $course_cols = $course_archive_arg === null ? tutor_utils()->get_option( 'courses_col_per_row', 3 ) : $course_archive_arg;
423 $classes = apply_filters(
424 'tutor_course_loop_col_classes',
425 array(
426 'tutor-col-' . $course_cols,
427 )
428 );
429
430 $class = implode( ' ', $classes );
431 if ( $echo ) {
432 echo esc_attr( $class );
433 }
434
435 return esc_attr( $class );
436 }
437 }
438
439
440 if ( ! function_exists( 'tutor_container_classes' ) ) {
441 /**
442 * Tutor container classes.
443 *
444 * @since 1.0.0
445 *
446 * @param boolean $echo echo.
447 *
448 * @return mixed
449 */
450 function tutor_container_classes( $echo = true ) {
451
452 $classes = apply_filters(
453 'tutor_container_classes',
454 array(
455 'tutor-wrap tutor-courses-wrap',
456 'tutor-container',
457 )
458 );
459
460 $classes = apply_filters(
461 'tutor_container_classes',
462 array(
463 'tutor-wrap tutor-courses-wrap',
464 'tutor-container',
465 )
466 );
467
468 $class = implode( ' ', $classes );
469
470 if ( $echo ) {
471 echo esc_attr( $class );
472 }
473
474 return esc_attr( $class );
475 }
476 }
477 if ( ! function_exists( 'tutor_post_class' ) ) {
478 /**
479 * Tutor post class.
480 *
481 * @since 1.0.0
482 *
483 * @param string $default default class.
484 *
485 * @return void
486 */
487 function tutor_post_class( $default = '' ) {
488 $classes = apply_filters(
489 'tutor_post_class',
490 array(
491 'tutor-wrap',
492 $default,
493 )
494 );
495
496 post_class( $classes );
497 }
498 }
499
500 if ( ! function_exists( 'tutor_widget_course_loop_classes' ) ) {
501 /**
502 * Get classes for widget loop single course wrap
503 *
504 * @since 1.3.1
505 *
506 * @param bool $echo echo.
507 *
508 * @return string
509 */
510 function tutor_widget_course_loop_classes( $echo = true ) {
511
512 $classes = apply_filters(
513 'tutor_widget_course_loop_classes',
514 array(
515 'tutor-widget-course-loop',
516 'tutor-widget-course',
517 'tutor-widget-course-' . get_the_ID(),
518 )
519 );
520
521 $class = implode( ' ', $classes );
522 if ( $echo ) {
523 echo esc_attr( $class );
524 }
525
526 return esc_attr( $class );
527 }
528 }
529
530 if ( ! function_exists( 'get_tutor_course_thumbnail' ) ) {
531 /**
532 * Get course thumbnail.
533 *
534 * @since 1.0.0
535 *
536 * @param string $size size.
537 * @param boolean $url url.
538 *
539 * @return string
540 */
541 function get_tutor_course_thumbnail( $size = 'post-thumbnail', $url = false ) {
542 $post_id = get_the_ID();
543 $size = apply_filters( 'tutor_course_thumbnail_size', $size, $post_id );
544 $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id );
545 $placeholder_url = tutor()->url . 'assets/images/placeholder.svg';
546 $thumb_url = $post_thumbnail_id ? wp_get_attachment_image_url( $post_thumbnail_id, $size ) : $placeholder_url;
547 $thumb_url = apply_filters( 'tutor_course_thumb_url', $thumb_url, $post_id, $size, $post_thumbnail_id );
548
549 if ( $url ) {
550 return $thumb_url;
551 }
552
553 echo '<div class="tutor-course-thumbnail">
554 <img src="' . esc_url( $thumb_url ) . '" />
555 </div>';
556 }
557 }
558
559 if ( ! function_exists( 'get_tutor_course_thumbnail_src' ) ) {
560 /**
561 * Get the course/post thumbnail src.
562 *
563 * @since 1.0.0
564 * @since 2.2.0 $id param added to provide post id to access outside of post loop.
565 *
566 * @param string $size size of thumb.
567 * @param int $id post id.
568 *
569 * @return string src of the post thumbnail | default placeholder
570 */
571 function get_tutor_course_thumbnail_src( $size = 'post-thumbnail', $id = 0 ) {
572 $post_id = $id ? $id : get_the_ID();
573 $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id );
574
575 if ( $post_thumbnail_id ) {
576 $size = apply_filters( 'tutor_course_thumbnail_size', $size, $post_id );
577 $src = wp_get_attachment_image_url( $post_thumbnail_id, $size, false );
578 } else {
579 $placeholder_url = tutor()->url . 'assets/images/placeholder.svg';
580 $src = apply_filters( 'tutor_course_thumbnail_placeholder', $placeholder_url, $post_id );
581 }
582
583 $src = apply_filters( 'tutor_course_thumb_url', $src, $post_id, $size, $post_thumbnail_id );
584
585 return $src;
586 }
587 }
588
589 if ( ! function_exists( 'tutor_course_loop_meta' ) ) {
590 /**
591 * Course loop meta.
592 *
593 * @since 1.0.0
594 *
595 * @return void
596 */
597 function tutor_course_loop_meta() {
598 ob_start();
599 tutor_load_template( 'loop.meta' );
600 $output = apply_filters( 'tutor_course_loop_meta', ob_get_clean() );
601
602 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
603 }
604 }
605
606 if ( ! function_exists( 'tutor_course_loop_author' ) ) {
607 /**
608 * Get course author name in loop
609 *
610 * @since 1.0.0
611 *
612 * @return void
613 */
614 function tutor_course_loop_author() {
615 ob_start();
616 tutor_load_template( 'loop.course-author' );
617 $output = apply_filters( 'tutor_course_loop_author', ob_get_clean() );
618
619 echo $output; //phpcs:ignore -- data already escaped inside template file
620 }
621 }
622
623 if ( ! function_exists( 'tutor_course_loop_price' ) ) {
624 /**
625 * Course loop price.
626 *
627 * @since 1.0.0
628 *
629 * @return void
630 */
631 function tutor_course_loop_price() {
632
633 ob_start();
634
635 $course_id = get_the_ID();
636 $can_continue = tutor_utils()->is_enrolled( $course_id ) || get_post_meta( $course_id, '_tutor_is_public_course', true ) == 'yes';
637
638 // Check for further access type like course content access settings.
639 if ( ! $can_continue ) {
640 $can_continue = tutor_utils()->has_user_course_content_access( get_current_user_id(), $course_id );
641 }
642
643 if ( $can_continue ) {
644 tutor_load_template( 'loop.course-continue' );
645
646 } elseif ( tutor_utils()->is_course_added_to_cart( $course_id ) ) {
647 tutor_load_template( 'loop.course-in-cart' );
648
649 } else {
650 $tutor_course_sell_by = apply_filters( 'tutor_course_sell_by', null );
651
652 if ( $tutor_course_sell_by && ( tutor_utils()->is_course_purchasable( $course_id ) || ! is_user_logged_in() ) ) {
653 tutor_load_template( 'loop.course-price-' . $tutor_course_sell_by );
654 } else {
655 tutor_load_template( 'loop.course-price' );
656 }
657 }
658 echo apply_filters( 'tutor_course_loop_price', ob_get_clean(), $course_id ); //phpcs:ignore -- already escaped inside template file
659 }
660 }
661
662 if ( ! function_exists( 'tutor_course_loop_rating' ) ) {
663 /**
664 * Get Course rating
665 *
666 * @since 1.0.0
667 * @since v1.4.5 updated.
668 *
669 * @return void
670 */
671 function tutor_course_loop_rating() {
672
673 $disable = ! get_tutor_option( 'enable_course_review' );
674 if ( $disable ) {
675 return;
676 }
677
678 ob_start();
679 tutor_load_template( 'loop.rating' );
680 $output = apply_filters( 'tutor_course_loop_rating', ob_get_clean() );
681
682 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
683 }
684 }
685
686 /**
687 * @param bool $echo
688 *
689 * @return mixed|void
690 *
691 * Get add to cart form
692 */
693
694 if ( ! function_exists( 'tutor_course_loop_add_to_cart' ) ) {
695 function tutor_course_loop_add_to_cart( $echo = true ) {
696 ob_start();
697 $tutor_course_sell_by = apply_filters( 'tutor_course_sell_by', null );
698
699 if ( $tutor_course_sell_by ) {
700 tutor_load_template( 'loop.add-to-cart-' . $tutor_course_sell_by );
701 }
702
703 $output = apply_filters( 'tutor_course_loop_add_to_cart_link', ob_get_clean() );
704
705 if ( $echo ) {
706 echo wp_kses_post( $output );
707 }
708 return $output;
709 }
710 }
711
712 if ( ! function_exists( 'tutor_course_price' ) ) {
713 function tutor_course_price() {
714 ob_start();
715 tutor_load_template( 'single.course.wc-price-html' );
716 $output = apply_filters( 'tutor_course_price', ob_get_clean() );
717
718 echo $output; //phpcs:ignore -- data already escaped inside template file
719 }
720 }
721
722 /**
723 * @param int $post_id
724 *
725 * echo the excerpt of TUTOR post type
726 *
727 * @since: v.1.0.0
728 */
729 if ( ! function_exists( 'tutor_the_excerpt' ) ) {
730 function tutor_the_excerpt( $post_id = 0 ) {
731 if ( ! $post_id ) {
732 $post_id = get_the_ID();
733 }
734 echo esc_textarea( tutor_get_the_excerpt( $post_id ) );
735 }
736 }
737 /**
738 * @param int $post_id
739 *
740 * @return mixed
741 *
742 * Return excerpt of TUTOR post type
743 *
744 * @since: v.1.0.0
745 */
746 if ( ! function_exists( 'tutor_get_the_excerpt' ) ) {
747 function tutor_get_the_excerpt( $post_id = 0 ) {
748 if ( ! $post_id ) {
749 $post_id = get_the_ID();
750 }
751
752 $get_post = get_post( $post_id );
753 return apply_filters( 'tutor_get_the_excerpt', $get_post->post_excerpt );
754 }
755 }
756
757 /**
758 * @return mixed
759 *
760 * return course author
761 *
762 * @since: v.1.0.0
763 */
764
765 if ( ! function_exists( 'get_tutor_course_author' ) ) {
766 function get_tutor_course_author() {
767 global $post;
768 return apply_filters( 'get_tutor_course_author', get_the_author_meta( 'display_name', $post->post_author ) );
769 }
770 }
771
772 function get_tutor_course_author_id() {
773 global $post;
774 return (int) $post->post_author;
775 }
776
777 /**
778 * @param int $course_id
779 *
780 * @return mixed
781 * Course benefits return array
782 *
783 * @since: v.1.0.0
784 */
785
786 if ( ! function_exists( 'tutor_course_benefits' ) ) {
787 function tutor_course_benefits( $course_id = 0 ) {
788 if ( ! $course_id ) {
789 $course_id = get_the_ID();
790 }
791 $benefits = get_post_meta( $course_id, '_tutor_course_benefits', true );
792
793 $benefits_array = array();
794 if ( $benefits ) {
795 $benefits_array = explode( "\n", $benefits );
796 }
797
798 $array = array_filter( array_map( 'trim', $benefits_array ) );
799
800 return apply_filters( 'tutor_course/single/benefits', $array, $course_id );
801 }
802 }
803
804 /**
805 * @param bool $echo
806 *
807 * @return mixed
808 *
809 * Course single page benefits
810 *
811 * @since: v.1.0.0
812 */
813
814 if ( ! function_exists( 'tutor_course_benefits_html' ) ) {
815 function tutor_course_benefits_html( $echo = true ) {
816 ob_start();
817 tutor_load_template( 'single.course.course-benefits' );
818 $output = apply_filters( 'tutor_course/single/benefits_html', ob_get_clean() );
819
820 if ( $echo ) {
821 echo wp_kses_post( $output );
822 }
823 return $output;
824 }
825 }
826
827 /**
828 * @param bool $echo
829 *
830 * @return mixed|void
831 *
832 * Return Topics HTML
833 *
834 * @since: v.1.0.0
835 */
836 if ( ! function_exists( 'tutor_course_topics' ) ) {
837 function tutor_course_topics( $echo = true ) {
838 ob_start();
839 tutor_load_template( 'single.course.course-topics' );
840 $output = apply_filters( 'tutor_course/single/topics', ob_get_clean() );
841 wp_reset_postdata();
842
843 if ( $echo ) {
844 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
845 }
846
847 return $output;
848 }
849 }
850
851 /**
852 * @param int $course_id
853 *
854 * @return mixed|void
855 *
856 * return course requirements in array
857 *
858 * @since: v.1.0.0
859 */
860 if ( ! function_exists( 'tutor_course_requirements' ) ) {
861 function tutor_course_requirements( $course_id = 0 ) {
862 if ( ! $course_id ) {
863 $course_id = get_the_ID();
864 }
865 $requirements = get_post_meta( $course_id, '_tutor_course_requirements', true );
866
867 $requirements_array = array();
868 if ( $requirements ) {
869 $requirements_array = explode( "\n", $requirements );
870 }
871
872 $array = array_filter( array_map( 'trim', $requirements_array ) );
873 return apply_filters( 'tutor_course/single/requirements', $array, $course_id );
874 }
875 }
876
877 /**
878 * @param bool $echo
879 *
880 * @return mixed|void
881 *
882 * Return course requirements in course single page
883 *
884 * @since: v.1.0.0
885 */
886 if ( ! function_exists( 'tutor_course_requirements_html' ) ) {
887 function tutor_course_requirements_html( $echo = true ) {
888 ob_start();
889 tutor_course_material_includes_html();
890 tutor_load_template( 'single.course.course-requirements' );
891 $output = apply_filters( 'tutor_course/single/requirements_html', ob_get_clean() );
892
893 if ( $echo ) {
894 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
895 }
896 return $output;
897 }
898 }
899
900
901 /**
902 * @param int $course_id
903 *
904 * @return mixed|void
905 *
906 * Return target audience in course single page
907 *
908 * @since: v.1.0.0
909 */
910 if ( ! function_exists( 'tutor_course_target_audience' ) ) {
911 function tutor_course_target_audience( $course_id = 0 ) {
912 if ( ! $course_id ) {
913 $course_id = get_the_ID();
914 }
915 $target_audience = get_post_meta( $course_id, '_tutor_course_target_audience', true );
916
917 $target_audience_array = array();
918 if ( $target_audience ) {
919 $target_audience_array = explode( "\n", $target_audience );
920 }
921
922 $array = array_filter( array_map( 'trim', $target_audience_array ) );
923 return apply_filters( 'tutor_course/single/target_audience', $array, $course_id );
924 }
925 }
926
927 /**
928 * @param bool $echo
929 *
930 * @return mixed|void
931 *
932 * Return target audience in course single page
933 *
934 * @since: v.1.0.0
935 */
936 if ( ! function_exists( 'tutor_course_target_audience_html' ) ) {
937 function tutor_course_target_audience_html( $echo = true ) {
938 ob_start();
939 tutor_load_template( 'single.course.course-target-audience' );
940 $output = apply_filters( 'tutor_course/single/audience_html', ob_get_clean() );
941
942 if ( $echo ) {
943 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
944 }
945 return $output;
946 }
947 }
948
949
950 if ( ! function_exists( 'tutor_course_material_includes' ) ) {
951 function tutor_course_material_includes( $course_id = 0 ) {
952 if ( ! $course_id ) {
953 $course_id = get_the_ID();
954 }
955 $target_audience = get_post_meta( $course_id, '_tutor_course_material_includes', true );
956
957 $target_audience_array = array();
958 if ( $target_audience ) {
959 $target_audience_array = explode( "\n", $target_audience );
960 }
961
962 $array = array_filter( array_map( 'trim', $target_audience_array ) );
963 return apply_filters( 'tutor_course/single/material_includes', $array, $course_id );
964 }
965 }
966
967 if ( ! function_exists( 'tutor_course_material_includes_html' ) ) {
968 function tutor_course_material_includes_html( $echo = true ) {
969 ob_start();
970 tutor_load_template( 'single.course.material-includes' );
971 $output = apply_filters( 'tutor_course/single/material_includes', ob_get_clean() );
972
973 if ( $echo ) {
974 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
975 }
976 return $output;
977 }
978 }
979
980 // tutor_course_material_includes_html
981
982
983 if ( ! function_exists( 'tutor_course_instructors_html' ) ) {
984 function tutor_course_instructors_html( $echo = true ) {
985 $display_course_instructors = tutor_utils()->get_option( 'display_course_instructors' );
986 if ( ! $display_course_instructors ) {
987 return null;
988 }
989
990 ob_start();
991 tutor_load_template( 'single.course.instructors' );
992 $output = apply_filters( 'tutor_course/single/instructors_html', ob_get_clean() );
993
994 if ( $echo ) {
995 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
996 }
997 return $output;
998 }
999 }
1000
1001 if ( ! function_exists( 'tutor_course_target_reviews_html' ) ) {
1002 function tutor_course_target_reviews_html( $echo = true ) {
1003 ob_start();
1004 tutor_load_template( 'single.course.reviews' );
1005
1006 $output = apply_filters( 'tutor_course/single/reviews_html', ob_get_clean() );
1007
1008 if ( $echo ) {
1009 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1010 }
1011 return $output;
1012 }
1013 }
1014
1015 /**
1016 * @param bool $echo
1017 *
1018 * @return mixed
1019 *
1020 * Course single page main content / description
1021 *
1022 * @since: v.1.0.0
1023 */
1024 if ( ! function_exists( 'tutor_course_content' ) ) {
1025 function tutor_course_content( $echo = true ) {
1026 ob_start();
1027 tutor_load_template( 'single.course.course-content' );
1028 $output = apply_filters( 'tutor_course/single/content', ob_get_clean() );
1029
1030 if ( $echo ) {
1031 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1032 }
1033
1034 return $output;
1035 }
1036 }
1037
1038 /**
1039 * Course single page lead info
1040 *
1041 * @since: v.1.0.0
1042 */
1043 if ( ! function_exists( 'tutor_course_lead_info' ) ) {
1044 function tutor_course_lead_info( $echo = true ) {
1045 ob_start();
1046
1047 // exit('failed');
1048
1049 $course_id = get_the_ID();
1050 $course_post_type = tutor()->course_post_type;
1051 $queryCourse = new WP_Query(
1052 apply_filters(
1053 'tutor_course_lead_info_args',
1054 array(
1055 'p' => $course_id,
1056 'post_type' => $course_post_type,
1057 )
1058 )
1059 );
1060
1061 if ( $queryCourse->have_posts() ) {
1062 while ( $queryCourse->have_posts() ) {
1063 $queryCourse->the_post();
1064 tutor_load_template( 'single.course.lead-info' );
1065 }
1066 wp_reset_postdata();
1067 }
1068
1069 $output = apply_filters( 'tutor_course/single/lead_info', ob_get_clean() );
1070
1071 if ( $echo ) {
1072 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1073 }
1074 return $output;
1075 }
1076 }
1077
1078 /**
1079 * @param bool $echo
1080 *
1081 * @return mixed|void
1082 */
1083
1084 if ( ! function_exists( 'tutor_course_enrolled_lead_info' ) ) {
1085 function tutor_course_enrolled_lead_info( $echo = true ) {
1086 ob_start();
1087
1088 $course_id = get_the_ID();
1089 $course_post_type = tutor()->course_post_type;
1090 $queryCourse = new WP_Query(
1091 array(
1092 'p' => $course_id,
1093 'post_type' => $course_post_type,
1094 )
1095 );
1096
1097 if ( $queryCourse->have_posts() ) {
1098 while ( $queryCourse->have_posts() ) {
1099 $queryCourse->the_post();
1100 tutor_load_template( 'single.course.lead-info' );
1101 }
1102 wp_reset_postdata();
1103 }
1104
1105 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
1106
1107 if ( $echo ) {
1108 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1109 }
1110
1111 return $output;
1112 }
1113 }
1114
1115 if ( ! function_exists( 'tutor_lesson_lead_info' ) ) {
1116 function tutor_lesson_lead_info( $lesson_id = 0, $echo = true ) {
1117 if ( ! $lesson_id ) {
1118 $lesson_id = get_the_ID();
1119 }
1120
1121 ob_start();
1122 $course_id = tutor_utils()->get_course_id_by( 'lesson', $lesson_id );
1123 $course_post_type = tutor()->course_post_type;
1124 $queryCourse = new WP_Query(
1125 array(
1126 'p' => $course_id,
1127 'post_type' => $course_post_type,
1128 )
1129 );
1130
1131 if ( $queryCourse->have_posts() ) {
1132 while ( $queryCourse->have_posts() ) {
1133 $queryCourse->the_post();
1134 tutor_load_template( 'single.course.lead-info' );
1135 }
1136 wp_reset_postdata();
1137 }
1138 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
1139
1140 if ( $echo ) {
1141 echo $output; //phpcs:ignore -- already escaped inside template file
1142 }
1143
1144 return $output;
1145
1146 }
1147 }
1148
1149 if ( ! function_exists( 'tutor_course_video' ) ) {
1150 function tutor_course_video( $echo = true ) {
1151 ob_start();
1152 tutor_load_template( 'single.video.video' );
1153 $output = apply_filters( 'tutor_course/single/video', ob_get_clean() );
1154
1155 if ( $echo ) {
1156 echo $output; //phpcs:ignore -- already escaped inside template file
1157 }
1158 return $output;
1159 }
1160 }
1161
1162 if ( ! function_exists( 'tutor_lesson_video' ) ) {
1163 function tutor_lesson_video( $echo = true ) {
1164 ob_start();
1165 tutor_load_template( 'single.video.video' );
1166 $output = apply_filters( 'tutor_lesson/single/video', ob_get_clean() );
1167
1168 if ( $echo ) {
1169 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1170 }
1171 return $output;
1172 }
1173 }
1174
1175 /**
1176 *
1177 * Get all lessons attachments
1178 *
1179 * @param bool $echo
1180 *
1181 * @return mixed
1182 *
1183 * @since v.1.0.0
1184 */
1185 if ( ! function_exists( 'get_tutor_posts_attachments' ) ) {
1186 function get_tutor_posts_attachments( $echo = true ) {
1187 ob_start();
1188 tutor_load_template( 'global.attachments' );
1189 $output = apply_filters( 'tutor_lesson/single/attachments', ob_get_clean() );
1190
1191 if ( $echo ) {
1192 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1193 }
1194 return $output;
1195 }
1196 }
1197
1198 /**
1199 * @param bool $echo
1200 *
1201 * @return mixed
1202 *
1203 * Render Lesson Main Content
1204 * @since v.1.0.0
1205 */
1206 if ( ! function_exists( 'tutor_lesson_content' ) ) {
1207 function tutor_lesson_content( $echo = true ) {
1208 ob_start();
1209 tutor_load_template( 'single.lesson.content' );
1210 $output = apply_filters( 'tutor_lesson/single/content', ob_get_clean() );
1211
1212 if ( $echo ) {
1213 echo $output; //phpcs:ignore -- already escaped inside template file
1214 }
1215
1216 return $output;
1217 }
1218 }
1219
1220 if ( ! function_exists( 'tutor_lesson_mark_complete_html' ) ) {
1221 function tutor_lesson_mark_complete_html( $echo = true ) {
1222 ob_start();
1223 tutor_load_template( 'single.lesson.complete_form' );
1224 $output = apply_filters( 'tutor_lesson/single/complete_form', ob_get_clean() );
1225
1226 if ( $echo ) {
1227 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1228 }
1229
1230 return $output;
1231 }
1232 }
1233
1234 function tutor_course_question_and_answer( $echo = true ) {
1235 ob_start();
1236 tutor_load_template( 'single.course.enrolled.question_and_answer' );
1237 $output = apply_filters( 'tutor_course/single/question_and_answer', ob_get_clean() );
1238
1239 if ( $echo ) {
1240 echo $output; //phpcs:ignore -- already escaped inside template file
1241 }
1242
1243 return $output;
1244 }
1245
1246 /**
1247 * @param bool $echo
1248 *
1249 * @return mixed
1250 *
1251 * @show progress bar about course complete
1252 *
1253 * @since v.2.0.0
1254 *
1255 * Course Curriculum added
1256 *
1257 * @since v2.0.5
1258 */
1259
1260 function tutor_course_info_tab() {
1261 tutor_course_content();
1262 tutor_course_benefits_html();
1263 tutor_course_topics();
1264 }
1265
1266
1267 function tutor_course_announcements( $echo = true ) {
1268 ob_start();
1269 tutor_load_template( 'single.course.enrolled.announcements' );
1270 $output = apply_filters( 'tutor_course/single/announcements', ob_get_clean() );
1271
1272 if ( $echo ) {
1273 echo $output; //phpcs:ignore -- already escaped inside template file
1274 }
1275
1276 return $output;
1277 }
1278
1279 function tutor_single_quiz_top( $echo = true ) {
1280 ob_start();
1281 tutor_load_template( 'single.quiz.top' );
1282 $output = apply_filters( 'tutor_single_quiz/top', ob_get_clean() );
1283
1284 if ( $echo ) {
1285 echo $output; //phpcs:ignore -- already escaped inside template file
1286 }
1287 return $output;
1288 }
1289
1290 function tutor_single_quiz_body( $echo = true ) {
1291 ob_start();
1292 tutor_load_template( 'single.quiz.body' );
1293 $output = apply_filters( 'tutor_single_quiz/body', ob_get_clean() );
1294
1295 if ( $echo ) {
1296 echo $output; //phpcs:ignore -- data already escaped inside template file
1297 }
1298 return $output;
1299 }
1300
1301 /**
1302 * @param bool $echo
1303 *
1304 * @return mixed|void
1305 *
1306 * Get the quiz description
1307 */
1308 function tutor_single_quiz_content( $echo = true ) {
1309 ob_start();
1310 tutor_load_template( 'single.quiz.content' );
1311 $output = apply_filters( 'tutor_single_quiz/content', ob_get_clean() );
1312
1313 if ( $echo ) {
1314 echo $output; //phpcs:ignore -- already escaped inside template file
1315 }
1316 return $output;
1317 }
1318
1319
1320 function tutor_single_quiz_no_course_belongs( $echo = true ) {
1321 ob_start();
1322 tutor_load_template( 'single.quiz.no_course_belongs' );
1323 $output = apply_filters( 'tutor_single_quiz/no_course_belongs', ob_get_clean() );
1324
1325 if ( $echo ) {
1326 echo $output; //phpcs:ignore -- already escaped inside template file
1327 }
1328 return $output;
1329 }
1330
1331 function single_quiz_contents( $echo = true ) {
1332
1333 ob_start();
1334 tutor_load_template( 'single.quiz.single_quiz_contents' );
1335 $output = apply_filters( 'tutor_single_quiz/single_quiz_contents', ob_get_clean() );
1336
1337 if ( $echo ) {
1338 echo $output; //phpcs:ignore -- already escaped inside template file
1339 }
1340 return $output;
1341 }
1342
1343 function get_tutor_course_level( $course_id = 0 ) {
1344 if ( ! $course_id ) {
1345 $course_id = get_the_ID();
1346 }
1347 if ( ! $course_id ) {
1348 return '';
1349 }
1350
1351 $course_level = get_post_meta( $course_id, '_tutor_course_level', true );
1352
1353 if ( $course_level ) {
1354 return tutor_utils()->course_levels( $course_level );
1355 }
1356 return false;
1357 }
1358
1359 if ( ! function_exists( 'get_tutor_course_duration_context' ) ) {
1360 function get_tutor_course_duration_context( $course_id = 0, $short_form = false ) {
1361 if ( ! $course_id ) {
1362 $course_id = get_the_ID();
1363 }
1364 if ( ! $course_id ) {
1365 return '';
1366 }
1367 $duration = get_post_meta( $course_id, '_course_duration', true );
1368 $durationHours = tutor_utils()->avalue_dot( 'hours', $duration );
1369 $durationMinutes = tutor_utils()->avalue_dot( 'minutes', $duration );
1370 $durationSeconds = tutor_utils()->avalue_dot( 'seconds', $duration );
1371
1372 $hour_format = $short_form ? __( 'h', 'tutor' ) : ' ' . ( $durationHours > 1 ? __( 'hours', 'tutor' ) : __( 'hour', 'tutor' ) );
1373 $minute_format = $short_form ? __( 'm', 'tutor' ) : ' ' . ( $durationMinutes > 1 ? __( 'minutes', 'tutor' ) : __( 'minute', 'tutor' ) );
1374 $second_format = $short_form ? __( 's', 'tutor' ) : ' ' . ( $durationSeconds > 1 ? __( 'seconds', 'tutor' ) : __( 'second', 'tutor' ) );
1375
1376 if ( $duration ) {
1377 $output = '';
1378 if ( $durationHours > 0 ) {
1379 $output .= '<span class="tutor-meta-level">' . ' ' . $durationHours . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $hour_format . '</span>';
1380 }
1381
1382 if ( $durationMinutes > 0 ) {
1383 $output .= '<span class="tutor-meta-level">' . ' ' . $durationMinutes . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $minute_format . '</span>';
1384 }
1385
1386 if ( ! $durationHours && ! $durationMinutes && $durationSeconds > 0 ) {
1387 $output .= '<span class="tutor-meta-level">' . ' ' . $durationSeconds . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $second_format . '</span>';
1388 }
1389
1390 return $output;
1391 }
1392
1393 return false;
1394 }
1395 }
1396 if ( ! function_exists( 'get_tutor_course_categories' ) ) {
1397 function get_tutor_course_categories( $course_id = 0 ) {
1398 if ( ! $course_id ) {
1399 $course_id = get_the_ID();
1400 }
1401 $terms = get_the_terms( $course_id, CourseModel::COURSE_CATEGORY );
1402
1403 return $terms;
1404 }
1405 }
1406
1407 /**
1408 * @param int $course_id
1409 *
1410 * @return array|false|WP_Error
1411 *
1412 * Get course tags
1413 */
1414
1415 if ( ! function_exists( 'get_tutor_course_tags' ) ) {
1416 function get_tutor_course_tags( $course_id = 0 ) {
1417 if ( ! $course_id ) {
1418 $course_id = get_the_ID();
1419 }
1420 $terms = get_the_terms( $course_id, CourseModel::COURSE_TAG );
1421
1422 return $terms;
1423 }
1424 }
1425
1426 /**
1427 * @param bool $echo
1428 *
1429 * @return mixed|void
1430 *
1431 * Template for course tags html
1432 */
1433
1434 if ( ! function_exists( 'tutor_course_tags_html' ) ) {
1435 function tutor_course_tags_html( $echo = true ) {
1436 ob_start();
1437 tutor_load_template( 'single.course.tags' );
1438 $output = apply_filters( 'tutor_course/single/tags_html', ob_get_clean() );
1439
1440 if ( $echo ) {
1441 echo tutor_kses_html( $output );
1442 }
1443
1444 return $output;
1445 }
1446 }
1447
1448 /**
1449 * @param bool $echo
1450 *
1451 * @return mixed
1452 *
1453 * Get Q&A in lesson sidebar
1454 */
1455
1456 if ( ! function_exists( 'tutor_lesson_sidebar_question_and_answer' ) ) {
1457 function tutor_lesson_sidebar_question_and_answer( $echo = true ) {
1458 ob_start();
1459 tutor_load_template( 'single.lesson.sidebar_question_and_answer' );
1460 $output = apply_filters( 'tutor_lesson/single/sidebar_question_and_answer', ob_get_clean() );
1461
1462 if ( $echo ) {
1463 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1464 }
1465
1466 return $output;
1467 }
1468 }
1469
1470 /**
1471 * @param bool $echo
1472 *
1473 * @return mixed
1474 *
1475 * Get Assignment content
1476 *
1477 * @since v.1.3.3
1478 */
1479
1480 if ( ! function_exists( 'tutor_assignment_content' ) ) {
1481 function tutor_assignment_content( $echo = true ) {
1482 ob_start();
1483 tutor_load_template( 'single.assignment.content' );
1484 $output = apply_filters( 'tutor_assignment/single/content', ob_get_clean() );
1485
1486 if ( $echo ) {
1487 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1488 }
1489
1490 return $output;
1491 }
1492 }
1493
1494 /**
1495 * @param string $msg
1496 * @param string $title
1497 * @param string $type
1498 *
1499 * @return string
1500 *
1501 * @since v.1.4.0
1502 */
1503
1504 if ( ! function_exists( 'get_tnotice' ) ) {
1505 function get_tnotice( $msg = '', $title = 'Success', $type = 'success' ) {
1506
1507 $output = '<div class="tnotice tnotice--' . $type . '">
1508 <div class="tnotice__icon">&iexcl;</div>
1509 <div class="tnotice__content">';
1510
1511 if ( $title ) {
1512 $output .= '<p class="tnotice__type">' . $title . '</p>';
1513 }
1514 $output .= '<p class="tnotice__message">' . $msg . '</p>
1515 </div>
1516 </div>';
1517
1518 return $output;
1519 }
1520 }
1521
1522 /**
1523 * @param int $course_content_id
1524 * @param bool $echo
1525 *
1526 * @return mixed|void
1527 *
1528 * Next Previous Pagination
1529 *
1530 * @since v.1.4.7
1531 */
1532
1533 function tutor_next_previous_pagination( $course_content_id = 0, $echo = true ) {
1534 $content_id = tutor_utils()->get_post_id( $course_content_id );
1535 $contents = tutor_utils()->get_course_prev_next_contents_by_id( $content_id );
1536 $previous_id = $contents->previous_id;
1537 $next_id = $contents->next_id;
1538
1539 ob_start();
1540 do_action( 'tutor_lesson_next_previous_pagination_before' );
1541 tutor_load_template( 'single.next-previous-pagination', compact( 'previous_id', 'next_id' ) );
1542 do_action( 'tutor_lesson_next_previous_pagination_after' );
1543 $output = apply_filters( 'tutor/single/next_previous_pagination', ob_get_clean() );
1544
1545 if ( $echo ) {
1546 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1547 }
1548
1549 return $output;
1550 }
1551
1552 /**
1553 * Load custom template from any given file
1554 *
1555 * Pass parameter as wish
1556 *
1557 * @since 1.9.8
1558 */
1559 if ( ! function_exists( 'tutor_load_template_from_custom_path' ) ) {
1560 function tutor_load_template_from_custom_path( $template = null, $data = array(), $once = true ) {
1561 do_action( 'tutor_load_template_from_custom_path_before', $template, $data );
1562 if ( file_exists( $template ) ) {
1563 if ( $once ) {
1564 include_once $template;
1565 } else {
1566 include $template;
1567 }
1568 }
1569 do_action( 'tutor_load_template_from_custom_path_after', $template, $data );
1570 }
1571 }
1572
1573 /**
1574 * Load enrolled course progress template
1575 *
1576 * This template will be used on only dashboard enrolled course page
1577 *
1578 * @since v2.0.0
1579 */
1580 if ( ! function_exists( 'tutor_enrolled_course_progress' ) ) {
1581 function tutor_enrolled_course_progress() {
1582 global $wp_query;
1583 $query_vars = $wp_query->query_vars;
1584 if ( isset( $query_vars['tutor_dashboard_page'] ) && 'enrolled-courses' === $query_vars['tutor_dashboard_page'] ) {
1585 tutor_load_template_from_custom_path( tutor()->path . 'templates/loop/enrolled-course-progress.php', '', false );
1586 }
1587 }
1588 }
1589
1590 if ( ! function_exists( 'tutor_permission_denied_template' ) ) {
1591 /**
1592 * Load permission denied template
1593 *
1594 * It will load permission denied template & return so not code
1595 * after this will execute
1596 *
1597 * @since 2.2.0
1598 *
1599 * @param integer $post_id post id if 0 then current post id will be used.
1600 *
1601 * @return void
1602 */
1603 function tutor_permission_denied_template( int $post_id = 0 ) {
1604 if ( ! $post_id ) {
1605 $post_id = get_the_ID();
1606 }
1607
1608 $args = array(
1609 'headline' => __( 'Permission Denied', 'tutor' ),
1610 'message' => __( 'You don\'t have the right to edit this course', 'tutor' ),
1611 'description' => __( 'Please make sure you are logged in to correct account', 'tutor' ),
1612 'button' => array(
1613 'url' => get_permalink( $post_id ),
1614 'text' => __( 'View Course', 'tutor' ),
1615 ),
1616 );
1617
1618 tutor_load_template( 'permission-denied', $args );
1619 return;
1620 }
1621 }
1622