PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 3.9.0
Tutor LMS – eLearning and online course solution v3.9.0
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 8 months ago theme-compatibility 4 years ago country.php 1 year ago ecommerce-functions.php 10 months ago tinymce_translate.php 1 year ago translate-text.php 1 year ago tutor-general-functions.php 8 months ago tutor-template-functions.php 9 months ago tutor-template-hook.php 4 years ago
tutor-template-functions.php
1625 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 * @since 3.4.1 Attachment src fallback added to show placeholder image
567 *
568 * @param string $size size of thumb.
569 * @param int $id post id.
570 *
571 * @return string src of the post thumbnail | default placeholder
572 */
573 function get_tutor_course_thumbnail_src( $size = 'post-thumbnail', $id = 0 ) {
574 $post_id = $id ? $id : get_the_ID();
575 $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id );
576 $placeholder_url = tutor()->url . 'assets/images/placeholder.svg';
577
578 if ( $post_thumbnail_id ) {
579 $size = apply_filters( 'tutor_course_thumbnail_size', $size, $post_id );
580 $src = wp_get_attachment_image_url( $post_thumbnail_id, $size, false );
581 if ( ! $src ) {
582 $src = $placeholder_url;
583 }
584 } else {
585 $src = apply_filters( 'tutor_course_thumbnail_placeholder', $placeholder_url, $post_id );
586 }
587
588 $src = apply_filters( 'tutor_course_thumb_url', $src, $post_id, $size, $post_thumbnail_id );
589
590 return $src;
591 }
592 }
593
594 if ( ! function_exists( 'tutor_course_loop_meta' ) ) {
595 /**
596 * Course loop meta.
597 *
598 * @since 1.0.0
599 *
600 * @return void
601 */
602 function tutor_course_loop_meta() {
603 ob_start();
604 tutor_load_template( 'loop.meta' );
605 $output = apply_filters( 'tutor_course_loop_meta', ob_get_clean() );
606
607 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
608 }
609 }
610
611 if ( ! function_exists( 'tutor_course_loop_author' ) ) {
612 /**
613 * Get course author name in loop
614 *
615 * @since 1.0.0
616 *
617 * @return void
618 */
619 function tutor_course_loop_author() {
620 ob_start();
621 tutor_load_template( 'loop.course-author' );
622 $output = apply_filters( 'tutor_course_loop_author', ob_get_clean() );
623
624 echo $output; //phpcs:ignore -- data already escaped inside template file
625 }
626 }
627
628 if ( ! function_exists( 'tutor_course_loop_price' ) ) {
629 /**
630 * Course loop price.
631 *
632 * @since 1.0.0
633 *
634 * @return void
635 */
636 function tutor_course_loop_price() {
637
638 ob_start();
639
640 $course_id = get_the_ID();
641 $can_continue = tutor_utils()->is_enrolled( $course_id ) || get_post_meta( $course_id, '_tutor_is_public_course', true ) == 'yes';
642
643 // Check for further access type like course content access settings.
644 if ( ! $can_continue ) {
645 $can_continue = tutor_utils()->has_user_course_content_access( get_current_user_id(), $course_id );
646 }
647
648 if ( $can_continue ) {
649 tutor_load_template( 'loop.course-continue' );
650
651 } elseif ( tutor_utils()->is_course_added_to_cart( $course_id ) ) {
652 tutor_load_template( 'loop.course-in-cart' );
653
654 } else {
655 $tutor_course_sell_by = apply_filters( 'tutor_course_sell_by', null );
656
657 if ( $tutor_course_sell_by && ( tutor_utils()->is_course_purchasable( $course_id ) || ! is_user_logged_in() ) ) {
658 tutor_load_template( 'loop.course-price-' . $tutor_course_sell_by );
659 } else {
660 tutor_load_template( 'loop.course-price' );
661 }
662 }
663 echo apply_filters( 'tutor_course_loop_price', ob_get_clean(), $course_id ); //phpcs:ignore -- already escaped inside template file
664 }
665 }
666
667 if ( ! function_exists( 'tutor_course_loop_rating' ) ) {
668 /**
669 * Get Course rating
670 *
671 * @since 1.0.0
672 * @since v1.4.5 updated.
673 *
674 * @return void
675 */
676 function tutor_course_loop_rating() {
677
678 $disable = ! get_tutor_option( 'enable_course_review' );
679 if ( $disable ) {
680 return;
681 }
682
683 ob_start();
684 tutor_load_template( 'loop.rating' );
685 $output = apply_filters( 'tutor_course_loop_rating', ob_get_clean() );
686
687 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
688 }
689 }
690
691 /**
692 * @param bool $echo
693 *
694 * @return mixed|void
695 *
696 * Get add to cart form
697 */
698
699 if ( ! function_exists( 'tutor_course_loop_add_to_cart' ) ) {
700 function tutor_course_loop_add_to_cart( $echo = true ) {
701 ob_start();
702 $tutor_course_sell_by = apply_filters( 'tutor_course_sell_by', null );
703
704 if ( $tutor_course_sell_by ) {
705 tutor_load_template( 'loop.add-to-cart-' . $tutor_course_sell_by );
706 }
707
708 $output = apply_filters( 'tutor_course_loop_add_to_cart_link', ob_get_clean() );
709
710 if ( $echo ) {
711 echo wp_kses_post( $output );
712 }
713 return $output;
714 }
715 }
716
717 if ( ! function_exists( 'tutor_course_price' ) ) {
718 function tutor_course_price() {
719 ob_start();
720 tutor_load_template( 'single.course.wc-price-html' );
721 $output = apply_filters( 'tutor_course_price', ob_get_clean() );
722
723 echo $output; //phpcs:ignore -- data already escaped inside template file
724 }
725 }
726
727 /**
728 * @param int $post_id
729 *
730 * echo the excerpt of TUTOR post type
731 *
732 * @since: v.1.0.0
733 */
734 if ( ! function_exists( 'tutor_the_excerpt' ) ) {
735 function tutor_the_excerpt( $post_id = 0 ) {
736 if ( ! $post_id ) {
737 $post_id = get_the_ID();
738 }
739 echo esc_textarea( tutor_get_the_excerpt( $post_id ) );
740 }
741 }
742 /**
743 * @param int $post_id
744 *
745 * @return mixed
746 *
747 * Return excerpt of TUTOR post type
748 *
749 * @since: v.1.0.0
750 */
751 if ( ! function_exists( 'tutor_get_the_excerpt' ) ) {
752 function tutor_get_the_excerpt( $post_id = 0 ) {
753 if ( ! $post_id ) {
754 $post_id = get_the_ID();
755 }
756
757 $get_post = get_post( $post_id );
758 return apply_filters( 'tutor_get_the_excerpt', $get_post->post_excerpt );
759 }
760 }
761
762 /**
763 * @return mixed
764 *
765 * return course author
766 *
767 * @since: v.1.0.0
768 */
769
770 if ( ! function_exists( 'get_tutor_course_author' ) ) {
771 function get_tutor_course_author() {
772 global $post;
773 return apply_filters( 'get_tutor_course_author', get_the_author_meta( 'display_name', $post->post_author ) );
774 }
775 }
776
777 function get_tutor_course_author_id() {
778 global $post;
779 return (int) $post->post_author;
780 }
781
782 /**
783 * @param int $course_id
784 *
785 * @return mixed
786 * Course benefits return array
787 *
788 * @since: v.1.0.0
789 */
790
791 if ( ! function_exists( 'tutor_course_benefits' ) ) {
792 function tutor_course_benefits( $course_id = 0 ) {
793 if ( ! $course_id ) {
794 $course_id = get_the_ID();
795 }
796 $benefits = get_post_meta( $course_id, '_tutor_course_benefits', true );
797
798 $benefits_array = array();
799 if ( $benefits ) {
800 $benefits_array = explode( "\n", $benefits );
801 }
802
803 $array = array_filter( array_map( 'trim', $benefits_array ) );
804
805 return apply_filters( 'tutor_course/single/benefits', $array, $course_id );
806 }
807 }
808
809 /**
810 * @param bool $echo
811 *
812 * @return mixed
813 *
814 * Course single page benefits
815 *
816 * @since: v.1.0.0
817 */
818
819 if ( ! function_exists( 'tutor_course_benefits_html' ) ) {
820 function tutor_course_benefits_html( $echo = true ) {
821 ob_start();
822 tutor_load_template( 'single.course.course-benefits' );
823 $output = apply_filters( 'tutor_course/single/benefits_html', ob_get_clean() );
824
825 if ( $echo ) {
826 echo wp_kses_post( $output );
827 }
828 return $output;
829 }
830 }
831
832 /**
833 * @param bool $echo
834 *
835 * @return mixed|void
836 *
837 * Return Topics HTML
838 *
839 * @since: v.1.0.0
840 */
841 if ( ! function_exists( 'tutor_course_topics' ) ) {
842 function tutor_course_topics( $echo = true ) {
843 ob_start();
844 tutor_load_template( 'single.course.course-topics' );
845 $output = apply_filters( 'tutor_course/single/topics', ob_get_clean() );
846 wp_reset_postdata();
847
848 if ( $echo ) {
849 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
850 }
851
852 return $output;
853 }
854 }
855
856 /**
857 * @param int $course_id
858 *
859 * @return mixed|void
860 *
861 * return course requirements in array
862 *
863 * @since: v.1.0.0
864 */
865 if ( ! function_exists( 'tutor_course_requirements' ) ) {
866 function tutor_course_requirements( $course_id = 0 ) {
867 if ( ! $course_id ) {
868 $course_id = get_the_ID();
869 }
870 $requirements = get_post_meta( $course_id, '_tutor_course_requirements', true );
871
872 $requirements_array = array();
873 if ( $requirements ) {
874 $requirements_array = explode( "\n", $requirements );
875 }
876
877 $array = array_filter( array_map( 'trim', $requirements_array ) );
878 return apply_filters( 'tutor_course/single/requirements', $array, $course_id );
879 }
880 }
881
882 /**
883 * @param bool $echo
884 *
885 * @return mixed|void
886 *
887 * Return course requirements in course single page
888 *
889 * @since: v.1.0.0
890 */
891 if ( ! function_exists( 'tutor_course_requirements_html' ) ) {
892 function tutor_course_requirements_html( $echo = true ) {
893 ob_start();
894 tutor_course_material_includes_html();
895 tutor_load_template( 'single.course.course-requirements' );
896 $output = apply_filters( 'tutor_course/single/requirements_html', ob_get_clean() );
897
898 if ( $echo ) {
899 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
900 }
901 return $output;
902 }
903 }
904
905
906 /**
907 * @param int $course_id
908 *
909 * @return mixed|void
910 *
911 * Return target audience in course single page
912 *
913 * @since: v.1.0.0
914 */
915 if ( ! function_exists( 'tutor_course_target_audience' ) ) {
916 function tutor_course_target_audience( $course_id = 0 ) {
917 if ( ! $course_id ) {
918 $course_id = get_the_ID();
919 }
920 $target_audience = get_post_meta( $course_id, '_tutor_course_target_audience', true );
921
922 $target_audience_array = array();
923 if ( $target_audience ) {
924 $target_audience_array = explode( "\n", $target_audience );
925 }
926
927 $array = array_filter( array_map( 'trim', $target_audience_array ) );
928 return apply_filters( 'tutor_course/single/target_audience', $array, $course_id );
929 }
930 }
931
932 /**
933 * @param bool $echo
934 *
935 * @return mixed|void
936 *
937 * Return target audience in course single page
938 *
939 * @since: v.1.0.0
940 */
941 if ( ! function_exists( 'tutor_course_target_audience_html' ) ) {
942 function tutor_course_target_audience_html( $echo = true ) {
943 ob_start();
944 tutor_load_template( 'single.course.course-target-audience' );
945 $output = apply_filters( 'tutor_course/single/audience_html', ob_get_clean() );
946
947 if ( $echo ) {
948 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
949 }
950 return $output;
951 }
952 }
953
954
955 if ( ! function_exists( 'tutor_course_material_includes' ) ) {
956 function tutor_course_material_includes( $course_id = 0 ) {
957 if ( ! $course_id ) {
958 $course_id = get_the_ID();
959 }
960 $target_audience = get_post_meta( $course_id, '_tutor_course_material_includes', true );
961
962 $target_audience_array = array();
963 if ( $target_audience ) {
964 $target_audience_array = explode( "\n", $target_audience );
965 }
966
967 $array = array_filter( array_map( 'trim', $target_audience_array ) );
968 return apply_filters( 'tutor_course/single/material_includes', $array, $course_id );
969 }
970 }
971
972 if ( ! function_exists( 'tutor_course_material_includes_html' ) ) {
973 function tutor_course_material_includes_html( $echo = true ) {
974 ob_start();
975 tutor_load_template( 'single.course.material-includes' );
976 $output = apply_filters( 'tutor_course/single/material_includes', ob_get_clean() );
977
978 if ( $echo ) {
979 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
980 }
981 return $output;
982 }
983 }
984
985 // tutor_course_material_includes_html
986
987
988 if ( ! function_exists( 'tutor_course_instructors_html' ) ) {
989 function tutor_course_instructors_html( $echo = true ) {
990 $display_course_instructors = tutor_utils()->get_option( 'display_course_instructors' );
991 if ( ! $display_course_instructors ) {
992 return null;
993 }
994
995 ob_start();
996 tutor_load_template( 'single.course.instructors' );
997 $output = apply_filters( 'tutor_course/single/instructors_html', ob_get_clean() );
998
999 if ( $echo ) {
1000 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1001 }
1002 return $output;
1003 }
1004 }
1005
1006 if ( ! function_exists( 'tutor_course_target_reviews_html' ) ) {
1007 function tutor_course_target_reviews_html( $echo = true ) {
1008 ob_start();
1009 tutor_load_template( 'single.course.reviews' );
1010
1011 $output = apply_filters( 'tutor_course/single/reviews_html', 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 * @param bool $echo
1022 *
1023 * @return mixed
1024 *
1025 * Course single page main content / description
1026 *
1027 * @since: v.1.0.0
1028 */
1029 if ( ! function_exists( 'tutor_course_content' ) ) {
1030 function tutor_course_content( $echo = true ) {
1031 ob_start();
1032 tutor_load_template( 'single.course.course-content' );
1033 $output = apply_filters( 'tutor_course/single/content', ob_get_clean() );
1034
1035 if ( $echo ) {
1036 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1037 }
1038
1039 return $output;
1040 }
1041 }
1042
1043 /**
1044 * Course single page lead info
1045 *
1046 * @since: v.1.0.0
1047 */
1048 if ( ! function_exists( 'tutor_course_lead_info' ) ) {
1049 function tutor_course_lead_info( $echo = true ) {
1050 ob_start();
1051
1052 // exit('failed');
1053
1054 $course_id = get_the_ID();
1055 $course_post_type = tutor()->course_post_type;
1056 $queryCourse = new WP_Query(
1057 apply_filters(
1058 'tutor_course_lead_info_args',
1059 array(
1060 'p' => $course_id,
1061 'post_type' => $course_post_type,
1062 )
1063 )
1064 );
1065
1066 if ( $queryCourse->have_posts() ) {
1067 while ( $queryCourse->have_posts() ) {
1068 $queryCourse->the_post();
1069 tutor_load_template( 'single.course.lead-info' );
1070 }
1071 wp_reset_postdata();
1072 }
1073
1074 $output = apply_filters( 'tutor_course/single/lead_info', ob_get_clean() );
1075
1076 if ( $echo ) {
1077 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1078 }
1079 return $output;
1080 }
1081 }
1082
1083 /**
1084 * @param bool $echo
1085 *
1086 * @return mixed|void
1087 */
1088
1089 if ( ! function_exists( 'tutor_course_enrolled_lead_info' ) ) {
1090 function tutor_course_enrolled_lead_info( $echo = true ) {
1091 ob_start();
1092
1093 $course_id = get_the_ID();
1094 $course_post_type = tutor()->course_post_type;
1095 $queryCourse = new WP_Query(
1096 array(
1097 'p' => $course_id,
1098 'post_type' => $course_post_type,
1099 )
1100 );
1101
1102 if ( $queryCourse->have_posts() ) {
1103 while ( $queryCourse->have_posts() ) {
1104 $queryCourse->the_post();
1105 tutor_load_template( 'single.course.lead-info' );
1106 }
1107 wp_reset_postdata();
1108 }
1109
1110 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
1111
1112 if ( $echo ) {
1113 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1114 }
1115
1116 return $output;
1117 }
1118 }
1119
1120 if ( ! function_exists( 'tutor_lesson_lead_info' ) ) {
1121 function tutor_lesson_lead_info( $lesson_id = 0, $echo = true ) {
1122 if ( ! $lesson_id ) {
1123 $lesson_id = get_the_ID();
1124 }
1125
1126 ob_start();
1127 $course_id = tutor_utils()->get_course_id_by( 'lesson', $lesson_id );
1128 $course_post_type = tutor()->course_post_type;
1129 $queryCourse = new WP_Query(
1130 array(
1131 'p' => $course_id,
1132 'post_type' => $course_post_type,
1133 )
1134 );
1135
1136 if ( $queryCourse->have_posts() ) {
1137 while ( $queryCourse->have_posts() ) {
1138 $queryCourse->the_post();
1139 tutor_load_template( 'single.course.lead-info' );
1140 }
1141 wp_reset_postdata();
1142 }
1143 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
1144
1145 if ( $echo ) {
1146 echo $output; //phpcs:ignore -- already escaped inside template file
1147 }
1148
1149 return $output;
1150
1151 }
1152 }
1153
1154 if ( ! function_exists( 'tutor_course_video' ) ) {
1155 function tutor_course_video( $echo = true ) {
1156 ob_start();
1157 tutor_load_template( 'single.video.video' );
1158 $output = apply_filters( 'tutor_course/single/video', ob_get_clean() );
1159
1160 if ( $echo ) {
1161 echo $output; //phpcs:ignore -- already escaped inside template file
1162 }
1163 return $output;
1164 }
1165 }
1166
1167 if ( ! function_exists( 'tutor_lesson_video' ) ) {
1168 function tutor_lesson_video( $echo = true ) {
1169 ob_start();
1170 tutor_load_template( 'single.video.video' );
1171 $output = apply_filters( 'tutor_lesson/single/video', ob_get_clean() );
1172
1173 if ( $echo ) {
1174 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1175 }
1176 return $output;
1177 }
1178 }
1179
1180 /**
1181 *
1182 * Get all lessons attachments
1183 *
1184 * @param bool $echo
1185 *
1186 * @return mixed
1187 *
1188 * @since v.1.0.0
1189 */
1190 if ( ! function_exists( 'get_tutor_posts_attachments' ) ) {
1191 function get_tutor_posts_attachments( $echo = true ) {
1192 ob_start();
1193 tutor_load_template( 'global.attachments' );
1194 $output = apply_filters( 'tutor_lesson/single/attachments', ob_get_clean() );
1195
1196 if ( $echo ) {
1197 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1198 }
1199 return $output;
1200 }
1201 }
1202
1203 /**
1204 * @param bool $echo
1205 *
1206 * @return mixed
1207 *
1208 * Render Lesson Main Content
1209 * @since v.1.0.0
1210 */
1211 if ( ! function_exists( 'tutor_lesson_content' ) ) {
1212 function tutor_lesson_content( $echo = true ) {
1213 ob_start();
1214 tutor_load_template( 'single.lesson.content' );
1215 $output = apply_filters( 'tutor_lesson/single/content', ob_get_clean() );
1216
1217 if ( $echo ) {
1218 echo $output; //phpcs:ignore -- already escaped inside template file
1219 }
1220
1221 return $output;
1222 }
1223 }
1224
1225 if ( ! function_exists( 'tutor_lesson_mark_complete_html' ) ) {
1226 function tutor_lesson_mark_complete_html( $echo = true ) {
1227 ob_start();
1228 tutor_load_template( 'single.lesson.complete_form' );
1229 $output = apply_filters( 'tutor_lesson/single/complete_form', ob_get_clean() );
1230
1231 if ( $echo ) {
1232 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1233 }
1234
1235 return $output;
1236 }
1237 }
1238
1239 function tutor_course_question_and_answer( $echo = true ) {
1240 ob_start();
1241 tutor_load_template( 'single.course.enrolled.question_and_answer' );
1242 $output = apply_filters( 'tutor_course/single/question_and_answer', ob_get_clean() );
1243
1244 if ( $echo ) {
1245 echo $output; //phpcs:ignore -- already escaped inside template file
1246 }
1247
1248 return $output;
1249 }
1250
1251 /**
1252 * @param bool $echo
1253 *
1254 * @return mixed
1255 *
1256 * @show progress bar about course complete
1257 *
1258 * @since v.2.0.0
1259 *
1260 * Course Curriculum added
1261 *
1262 * @since v2.0.5
1263 */
1264
1265 function tutor_course_info_tab() {
1266 tutor_course_content();
1267 tutor_course_benefits_html();
1268 tutor_course_topics();
1269 }
1270
1271
1272 function tutor_course_announcements( $echo = true ) {
1273 ob_start();
1274 tutor_load_template( 'single.course.enrolled.announcements' );
1275 $output = apply_filters( 'tutor_course/single/announcements', ob_get_clean() );
1276
1277 if ( $echo ) {
1278 echo $output; //phpcs:ignore -- already escaped inside template file
1279 }
1280
1281 return $output;
1282 }
1283
1284 function tutor_single_quiz_top( $echo = true ) {
1285 ob_start();
1286 tutor_load_template( 'single.quiz.top' );
1287 $output = apply_filters( 'tutor_single_quiz/top', ob_get_clean() );
1288
1289 if ( $echo ) {
1290 echo $output; //phpcs:ignore -- already escaped inside template file
1291 }
1292 return $output;
1293 }
1294
1295 function tutor_single_quiz_body( $echo = true ) {
1296 ob_start();
1297 tutor_load_template( 'single.quiz.body' );
1298 $output = apply_filters( 'tutor_single_quiz/body', ob_get_clean() );
1299
1300 if ( $echo ) {
1301 echo $output; //phpcs:ignore -- data already escaped inside template file
1302 }
1303 return $output;
1304 }
1305
1306 /**
1307 * @param bool $echo
1308 *
1309 * @return mixed|void
1310 *
1311 * Get the quiz description
1312 */
1313 function tutor_single_quiz_content( $echo = true ) {
1314 ob_start();
1315 tutor_load_template( 'single.quiz.content' );
1316 $output = apply_filters( 'tutor_single_quiz/content', ob_get_clean() );
1317
1318 if ( $echo ) {
1319 echo $output; //phpcs:ignore -- already escaped inside template file
1320 }
1321 return $output;
1322 }
1323
1324
1325 function tutor_single_quiz_no_course_belongs( $echo = true ) {
1326 ob_start();
1327 tutor_load_template( 'single.quiz.no_course_belongs' );
1328 $output = apply_filters( 'tutor_single_quiz/no_course_belongs', ob_get_clean() );
1329
1330 if ( $echo ) {
1331 echo $output; //phpcs:ignore -- already escaped inside template file
1332 }
1333 return $output;
1334 }
1335
1336 function single_quiz_contents( $echo = true ) {
1337
1338 ob_start();
1339 tutor_load_template( 'single.quiz.single_quiz_contents' );
1340 $output = apply_filters( 'tutor_single_quiz/single_quiz_contents', ob_get_clean() );
1341
1342 if ( $echo ) {
1343 echo $output; //phpcs:ignore -- already escaped inside template file
1344 }
1345 return $output;
1346 }
1347
1348 function get_tutor_course_level( $course_id = 0 ) {
1349 if ( ! $course_id ) {
1350 $course_id = get_the_ID();
1351 }
1352 if ( ! $course_id ) {
1353 return '';
1354 }
1355
1356 $course_level = get_post_meta( $course_id, '_tutor_course_level', true );
1357
1358 if ( $course_level ) {
1359 return tutor_utils()->course_levels( $course_level );
1360 }
1361 return false;
1362 }
1363
1364 if ( ! function_exists( 'get_tutor_course_duration_context' ) ) {
1365 function get_tutor_course_duration_context( $course_id = 0, $short_form = false ) {
1366 if ( ! $course_id ) {
1367 $course_id = get_the_ID();
1368 }
1369 if ( ! $course_id ) {
1370 return '';
1371 }
1372 $duration = get_post_meta( $course_id, '_course_duration', true );
1373 $durationHours = tutor_utils()->avalue_dot( 'hours', $duration );
1374 $durationMinutes = tutor_utils()->avalue_dot( 'minutes', $duration );
1375 $durationSeconds = tutor_utils()->avalue_dot( 'seconds', $duration );
1376
1377 $hour_format = $short_form ? __( 'h', 'tutor' ) : ' ' . ( $durationHours > 1 ? __( 'hours', 'tutor' ) : __( 'hour', 'tutor' ) );
1378 $minute_format = $short_form ? __( 'm', 'tutor' ) : ' ' . ( $durationMinutes > 1 ? __( 'minutes', 'tutor' ) : __( 'minute', 'tutor' ) );
1379 $second_format = $short_form ? __( 's', 'tutor' ) : ' ' . ( $durationSeconds > 1 ? __( 'seconds', 'tutor' ) : __( 'second', 'tutor' ) );
1380
1381 if ( $duration ) {
1382 $output = '';
1383 if ( $durationHours > 0 ) {
1384 $output .= '<span class="tutor-meta-level">' . ' ' . $durationHours . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $hour_format . '</span>';
1385 }
1386
1387 if ( $durationMinutes > 0 ) {
1388 $output .= '<span class="tutor-meta-level">' . ' ' . $durationMinutes . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $minute_format . '</span>';
1389 }
1390
1391 if ( ! $durationHours && ! $durationMinutes && $durationSeconds > 0 ) {
1392 $output .= '<span class="tutor-meta-level">' . ' ' . $durationSeconds . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $second_format . '</span>';
1393 }
1394
1395 return $output;
1396 }
1397
1398 return false;
1399 }
1400 }
1401 if ( ! function_exists( 'get_tutor_course_categories' ) ) {
1402 function get_tutor_course_categories( $course_id = 0 ) {
1403 if ( ! $course_id ) {
1404 $course_id = get_the_ID();
1405 }
1406 $terms = get_the_terms( $course_id, CourseModel::COURSE_CATEGORY );
1407
1408 return $terms;
1409 }
1410 }
1411
1412 /**
1413 * @param int $course_id
1414 *
1415 * @return array|false|WP_Error
1416 *
1417 * Get course tags
1418 */
1419
1420 if ( ! function_exists( 'get_tutor_course_tags' ) ) {
1421 function get_tutor_course_tags( $course_id = 0 ) {
1422 if ( ! $course_id ) {
1423 $course_id = get_the_ID();
1424 }
1425 $terms = get_the_terms( $course_id, CourseModel::COURSE_TAG );
1426
1427 return $terms;
1428 }
1429 }
1430
1431 /**
1432 * @param bool $echo
1433 *
1434 * @return mixed|void
1435 *
1436 * Template for course tags html
1437 */
1438
1439 if ( ! function_exists( 'tutor_course_tags_html' ) ) {
1440 function tutor_course_tags_html( $echo = true ) {
1441 ob_start();
1442 tutor_load_template( 'single.course.tags' );
1443 $output = apply_filters( 'tutor_course/single/tags_html', ob_get_clean() );
1444
1445 if ( $echo ) {
1446 echo tutor_kses_html( $output );
1447 }
1448
1449 return $output;
1450 }
1451 }
1452
1453 /**
1454 * @param bool $echo
1455 *
1456 * @return mixed
1457 *
1458 * Get Q&A in lesson sidebar
1459 */
1460
1461 if ( ! function_exists( 'tutor_lesson_sidebar_question_and_answer' ) ) {
1462 function tutor_lesson_sidebar_question_and_answer( $echo = true ) {
1463 ob_start();
1464 tutor_load_template( 'single.lesson.sidebar_question_and_answer' );
1465 $output = apply_filters( 'tutor_lesson/single/sidebar_question_and_answer', ob_get_clean() );
1466
1467 if ( $echo ) {
1468 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1469 }
1470
1471 return $output;
1472 }
1473 }
1474
1475 /**
1476 * @param bool $echo
1477 *
1478 * @return mixed
1479 *
1480 * Get Assignment content
1481 *
1482 * @since v.1.3.3
1483 */
1484
1485 if ( ! function_exists( 'tutor_assignment_content' ) ) {
1486 function tutor_assignment_content( $echo = true ) {
1487 $output = apply_filters( 'tutor_assignment/single/content', '' );
1488
1489 if ( $echo ) {
1490 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1491 }
1492
1493 return $output;
1494 }
1495 }
1496
1497 /**
1498 * @param string $msg
1499 * @param string $title
1500 * @param string $type
1501 *
1502 * @return string
1503 *
1504 * @since v.1.4.0
1505 */
1506
1507 if ( ! function_exists( 'get_tnotice' ) ) {
1508 function get_tnotice( $msg = '', $title = 'Success', $type = 'success' ) {
1509
1510 $output = '<div class="tnotice tnotice--' . $type . '">
1511 <div class="tnotice__icon">&iexcl;</div>
1512 <div class="tnotice__content">';
1513
1514 if ( $title ) {
1515 $output .= '<p class="tnotice__type">' . $title . '</p>';
1516 }
1517 $output .= '<p class="tnotice__message">' . $msg . '</p>
1518 </div>
1519 </div>';
1520
1521 return $output;
1522 }
1523 }
1524
1525 /**
1526 * @param int $course_content_id
1527 * @param bool $echo
1528 *
1529 * @return mixed|void
1530 *
1531 * Next Previous Pagination
1532 *
1533 * @since v.1.4.7
1534 */
1535
1536 function tutor_next_previous_pagination( $course_content_id = 0, $echo = true ) {
1537 $content_id = tutor_utils()->get_post_id( $course_content_id );
1538 $contents = tutor_utils()->get_course_prev_next_contents_by_id( $content_id );
1539 $previous_id = $contents->previous_id;
1540 $next_id = $contents->next_id;
1541
1542 ob_start();
1543 do_action( 'tutor_lesson_next_previous_pagination_before' );
1544 tutor_load_template( 'single.next-previous-pagination', compact( 'previous_id', 'next_id' ) );
1545 do_action( 'tutor_lesson_next_previous_pagination_after' );
1546 $output = apply_filters( 'tutor/single/next_previous_pagination', ob_get_clean() );
1547
1548 if ( $echo ) {
1549 echo tutor_kses_html( $output ); //phpcs:ignore -- already escaped inside template file
1550 }
1551
1552 return $output;
1553 }
1554
1555 /**
1556 * Load custom template from any given file
1557 *
1558 * Pass parameter as wish
1559 *
1560 * @since 1.9.8
1561 */
1562 if ( ! function_exists( 'tutor_load_template_from_custom_path' ) ) {
1563 function tutor_load_template_from_custom_path( $template = null, $data = array(), $once = true ) {
1564 do_action( 'tutor_load_template_from_custom_path_before', $template, $data );
1565 if ( file_exists( $template ) ) {
1566 if ( $once ) {
1567 include_once $template;
1568 } else {
1569 include $template;
1570 }
1571 }
1572 do_action( 'tutor_load_template_from_custom_path_after', $template, $data );
1573 }
1574 }
1575
1576 /**
1577 * Load enrolled course progress template
1578 *
1579 * This template will be used on only dashboard enrolled course page
1580 *
1581 * @since v2.0.0
1582 */
1583 if ( ! function_exists( 'tutor_enrolled_course_progress' ) ) {
1584 function tutor_enrolled_course_progress() {
1585 global $wp_query;
1586 $query_vars = $wp_query->query_vars;
1587 if ( isset( $query_vars['tutor_dashboard_page'] ) && 'enrolled-courses' === $query_vars['tutor_dashboard_page'] ) {
1588 tutor_load_template_from_custom_path( tutor()->path . 'templates/loop/enrolled-course-progress.php', '', false );
1589 }
1590 }
1591 }
1592
1593 if ( ! function_exists( 'tutor_permission_denied_template' ) ) {
1594 /**
1595 * Load permission denied template
1596 *
1597 * It will load permission denied template & return so not code
1598 * after this will execute
1599 *
1600 * @since 2.2.0
1601 *
1602 * @param integer $post_id post id if 0 then current post id will be used.
1603 *
1604 * @return void
1605 */
1606 function tutor_permission_denied_template( int $post_id = 0 ) {
1607 if ( ! $post_id ) {
1608 $post_id = get_the_ID();
1609 }
1610
1611 $args = array(
1612 'headline' => __( 'Permission Denied', 'tutor' ),
1613 'message' => __( 'You don\'t have the right to edit this course', 'tutor' ),
1614 'description' => __( 'Please make sure you are logged in to correct account', 'tutor' ),
1615 'button' => array(
1616 'url' => get_permalink( $post_id ),
1617 'text' => __( 'View Course', 'tutor' ),
1618 ),
1619 );
1620
1621 tutor_load_template( 'permission-denied', $args );
1622 return;
1623 }
1624 }
1625