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