PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 2.1.3
Tutor LMS – eLearning and online course solution v2.1.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 tinymce_translate.php 4 years ago tutor-general-functions.php 3 years ago tutor-template-functions.php 3 years ago tutor-template-hook.php 4 years ago
tutor-template-functions.php
1428 lines
1 <?php
2 /**
3 * Tutor template functions
4 *
5 * @package TutorFunctions
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 exit;
10 }
11
12 /**
13 * @param null $template
14 * @param bool $tutor_pro
15 *
16 * @return bool|string
17 *
18 * Load template with override file system
19 *
20 * @since v.1.0.0
21 * @updated v.1.4.2
22 * @updated v.1.4.3
23 */
24
25 if ( ! function_exists( 'tutor_get_template' ) ) {
26 function tutor_get_template( $template = null, $tutor_pro = false ) {
27 if ( ! $template ) {
28 return false;
29 }
30 $template = str_replace( '.', DIRECTORY_SEPARATOR, $template );
31
32 /**
33 * Get template first from child-theme if exists
34 * If child theme not exists, then get template from parent theme
35 */
36 $template_location = trailingslashit( get_stylesheet_directory() ) . "tutor/{$template}.php";
37 if ( ! file_exists( $template_location ) ) {
38 $template_location = trailingslashit( get_template_directory() ) . "tutor/{$template}.php";
39 }
40 $file_in_theme = $template_location;
41 if ( ! file_exists( $template_location ) ) {
42 $template_location = trailingslashit( tutor()->path ) . "templates/{$template}.php";
43
44 if ( $tutor_pro && function_exists( 'tutor_pro' ) ) {
45 $pro_template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
46 if ( file_exists( $pro_template_location ) ) {
47 $template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
48 }
49 }
50
51 if ( ! file_exists( $template_location ) ) {
52 echo '<div class="tutor-notice-warning"> ' . __( sprintf( '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: %s ', '<code>' . $file_in_theme . '</code>' ), 'tutor' ) . ' </div>';
53 }
54 }
55
56 return apply_filters( 'tutor_get_template_path', $template_location, $template );
57 }
58 }
59
60 /**
61 * @param null $template
62 * @param bool $tutor_pro
63 *
64 * @return bool|mixed|void
65 *
66 * Get only template path without any warning...
67 *
68 * @since v.1.4.2
69 */
70 if ( ! function_exists( 'tutor_get_template_path' ) ) {
71 function tutor_get_template_path( $template = null, $tutor_pro = false ) {
72 if ( ! $template ) {
73 return false;
74 }
75 $template = str_replace( '.', DIRECTORY_SEPARATOR, $template );
76
77 /**
78 * Get template first from child-theme if exists
79 * If child theme not exists, then get template from parent theme
80 */
81 $template_location = trailingslashit( get_stylesheet_directory() ) . "tutor/{$template}.php";
82 if ( ! file_exists( $template_location ) ) {
83 $template_location = trailingslashit( get_template_directory() ) . "tutor/{$template}.php";
84 }
85 if ( ! file_exists( $template_location ) ) {
86 $template_location = trailingslashit( tutor()->path ) . "templates/{$template}.php";
87 }
88 if ( ! file_exists( $template_location ) && $tutor_pro && function_exists( 'tutor_pro' ) ) {
89 $template_location = trailingslashit( tutor_pro()->path ) . "templates/{$template}.php";
90 }
91
92 return apply_filters( 'tutor_get_template_path', $template_location, $template );
93 }
94 }
95
96 /**
97 * @param null $template
98 *
99 * @param array $variables
100 *
101 * Load template for TUTOR
102 *
103 * @since v.1.0.0
104 *
105 * @updated v.1.1.2
106 */
107
108 if ( ! function_exists( 'tutor_load_template' ) ) {
109 function tutor_load_template( $template = null, $variables = array(), $tutor_pro = false ) {
110 $variables = (array) $variables;
111 $variables = apply_filters( 'get_tutor_load_template_variables', $variables );
112 extract( $variables );
113
114 $isLoad = apply_filters( 'should_tutor_load_template', true, $template, $variables );
115 if ( ! $isLoad ) {
116 return;
117 }
118
119 do_action( 'tutor_load_template_before', $template, $variables );
120 include tutor_get_template( $template, $tutor_pro );
121 do_action( 'tutor_load_template_after', $template, $variables );
122 }
123 }
124
125 /**
126 * @param null $template
127 * @param array $variables
128 * @param bool $tutor_pro
129 *
130 * @since v.1.4.3
131 */
132
133 if ( ! function_exists( 'tutor_load_template_part' ) ) {
134 function tutor_load_template_part( $template = null, $variables = array(), $tutor_pro = false ) {
135 $variables = (array) $variables;
136 $variables = apply_filters( 'get_tutor_load_template_variables', $variables );
137 extract( $variables );
138
139 /**
140 * Get template first from child-theme if exists
141 * If child theme not exists, then get template from parent theme
142 */
143 $template_location = trailingslashit( get_stylesheet_directory() ) . 'tutor/template.php';
144 if ( ! file_exists( $template_location ) ) {
145 $template_location = trailingslashit( get_template_directory() ) . 'tutor/template.php';
146 }
147
148 if ( ! file_exists( $template_location ) ) {
149 $template_location = trailingslashit( tutor()->path ) . 'templates/template.php';
150 if ( ! file_exists( $template_location ) && $tutor_pro && function_exists( 'tutor_pro' ) ) {
151 $template_location = trailingslashit( tutor_pro()->path ) . 'templates/template.php';
152 }
153 }
154
155 include apply_filters( 'tutor_get_template_part_path', $template_location, $template );
156 }
157 }
158
159 /**
160 * @param $template_name
161 * @param array $variables
162 *
163 * @return string
164 *
165 * @since v.1.4.3
166 */
167
168 if ( ! function_exists( 'tutor_get_template_html' ) ) {
169 function tutor_get_template_html( $template_name, $variables = array(), $tutor_pro = false ) {
170 ob_start();
171 tutor_load_template( $template_name, $variables, $tutor_pro );
172
173 return ob_get_clean();
174 }
175 }
176
177 if ( ! function_exists( 'tutor_course_loop_start' ) ) {
178 function tutor_course_loop_start( $echo = true ) {
179 ob_start();
180 tutor_load_template( 'loop.loop-start' );
181 $output = apply_filters( 'tutor_course_loop_start', ob_get_clean() );
182
183 if ( $echo ) {
184 echo tutor_kses_html( $output );
185 }
186 return $output;
187 }
188 }
189
190 if ( ! function_exists( 'tutor_course_loop_end' ) ) {
191 function tutor_course_loop_end( $echo = true ) {
192 ob_start();
193 tutor_load_template( 'loop.loop-end' );
194
195 $output = apply_filters( 'tutor_course_loop_end', ob_get_clean() );
196 if ( $echo ) {
197 echo tutor_kses_html( $output );
198 }
199
200 return $output;
201 }
202 }
203
204 function tutor_course_loop_before_content() {
205 ob_start();
206 tutor_load_template( 'loop.loop-before-content' );
207
208 $output = apply_filters( 'tutor_course_loop_before_content', ob_get_clean() );
209 echo tutor_kses_html( $output );
210 }
211
212 function tutor_course_loop_after_content() {
213 ob_start();
214 tutor_load_template( 'loop.loop-after-content' );
215
216 $output = apply_filters( 'tutor_course_loop_after_content', ob_get_clean() );
217 echo tutor_kses_html( $output );
218 }
219
220 if ( ! function_exists( 'tutor_course_loop_title' ) ) {
221 function tutor_course_loop_title() {
222 ob_start();
223 tutor_load_template( 'loop.title' );
224 $output = apply_filters( 'tutor_course_loop_title', ob_get_clean() );
225
226 echo tutor_kses_html( $output );
227 }
228 }
229
230
231 if ( ! function_exists( 'tutor_course_loop_header' ) ) {
232 function tutor_course_loop_header() {
233 ob_start();
234 tutor_load_template( 'loop.header' );
235 $output = apply_filters( 'tutor_course_loop_header', ob_get_clean() );
236
237 echo tutor_kses_html( $output );
238 }
239 }
240
241 if ( ! function_exists( 'tutor_course_loop_footer' ) ) {
242 function tutor_course_loop_footer() {
243 ob_start();
244 tutor_load_template( 'loop.footer' );
245 $output = apply_filters( 'tutor_course_loop_footer', ob_get_clean() );
246
247 echo tutor_kses_html( $output );
248 }
249 }
250
251 // tutor_course_loop_footer
252
253
254 if ( ! function_exists( 'tutor_course_loop_start_content_wrap' ) ) {
255 function tutor_course_loop_start_content_wrap() {
256 ob_start();
257 tutor_load_template( 'loop.start_content_wrap' );
258 $output = apply_filters( 'tutor_course_loop_start_content_wrap', ob_get_clean() );
259
260 echo tutor_kses_html( $output );
261 }
262 }
263
264 if ( ! function_exists( 'tutor_course_loop_end_content_wrap' ) ) {
265 function tutor_course_loop_end_content_wrap() {
266 ob_start();
267 tutor_load_template( 'loop.end_content_wrap' );
268 $output = apply_filters( 'tutor_course_loop_end_content_wrap', ob_get_clean() );
269
270 echo tutor_kses_html( $output );
271 }
272 }
273
274 if ( ! function_exists( 'tutor_course_loop_thumbnail' ) ) {
275 function tutor_course_loop_thumbnail( $echo = true ) {
276 ob_start();
277 tutor_load_template( 'loop.thumbnail' );
278 $output = apply_filters( 'tutor_course_loop_thumbnail', ob_get_clean() );
279
280 if ( $echo ) {
281 echo tutor_kses_html( $output );
282 } else {
283 return $output;
284 }
285 }
286 }
287
288 if ( ! function_exists( 'tutor_course_loop_wrap_classes' ) ) {
289 function tutor_course_loop_wrap_classes( $echo = true ) {
290 $courseID = get_the_ID();
291 $classes = apply_filters(
292 'tutor_course_loop_wrap_classes',
293 array(
294 'tutor-course',
295 'tutor-course-loop',
296 'tutor-course-loop-' . $courseID,
297 )
298 );
299
300 $class = implode( ' ', $classes );
301 if ( $echo ) {
302 echo esc_attr( $class );
303 }
304
305 return esc_attr( $class );
306 }
307 }
308
309 if ( ! function_exists( 'tutor_course_loop_col_classes' ) ) {
310 function tutor_course_loop_col_classes( $echo = true ) {
311 $course_filter = (bool) tutor_utils()->get_option( 'course_archive_filter', false );
312 $course_archive_arg = isset( $GLOBALS['tutor_course_archive_arg'] ) ? $GLOBALS['tutor_course_archive_arg']['column_per_row'] : null;
313 $course_cols = $course_archive_arg === null ? tutor_utils()->get_option( 'courses_col_per_row', 3 ) : $course_archive_arg;
314 $classes = apply_filters(
315 'tutor_course_loop_col_classes',
316 array(
317 'tutor-col-' . $course_cols,
318 )
319 );
320
321 $class = implode( ' ', $classes );
322 if ( $echo ) {
323 echo esc_attr( $class );
324 }
325
326 return esc_attr( $class );
327 }
328 }
329
330
331 if ( ! function_exists( 'tutor_container_classes' ) ) {
332 function tutor_container_classes( $echo = true ) {
333
334 $classes = apply_filters(
335 'tutor_container_classes',
336 array(
337 'tutor-wrap tutor-courses-wrap',
338 'tutor-container',
339 )
340 );
341
342 $classes = apply_filters(
343 'tutor_container_classes',
344 array(
345 'tutor-wrap tutor-courses-wrap',
346 'tutor-container',
347 )
348 );
349
350 $class = implode( ' ', $classes );
351
352 if ( $echo ) {
353 echo esc_attr( $class );
354 }
355
356 return esc_attr( $class );
357 }
358 }
359 if ( ! function_exists( 'tutor_post_class' ) ) {
360 function tutor_post_class( $default = '' ) {
361 $classes = apply_filters(
362 'tutor_post_class',
363 array(
364 'tutor-wrap',
365 $default,
366 )
367 );
368
369 post_class( $classes );
370 }
371 }
372
373 /**
374 *
375 * Get classes for widget loop single course wrap
376 *
377 * @param bool $echo
378 *
379 * @return string
380 *
381 * @since v.1.3.1
382 */
383 if ( ! function_exists( 'tutor_widget_course_loop_classes' ) ) {
384 function tutor_widget_course_loop_classes( $echo = true ) {
385
386 $classes = apply_filters(
387 'tutor_widget_course_loop_classes',
388 array(
389 'tutor-widget-course-loop',
390 'tutor-widget-course',
391 'tutor-widget-course-' . get_the_ID(),
392 )
393 );
394
395 $class = implode( ' ', $classes );
396 if ( $echo ) {
397 echo esc_attr( $class );
398 }
399
400 return esc_attr( $class );
401 }
402 }
403
404 /**
405 * Get the post thumbnail
406 */
407 if ( ! function_exists( 'get_tutor_course_thumbnail' ) ) {
408 function get_tutor_course_thumbnail( $size = 'post-thumbnail', $url = false ) {
409 $post_id = get_the_ID();
410 $size = apply_filters( 'tutor_course_thumbnail_size', $size, $post_id );
411 $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id );
412 $placeHolderUrl = tutor()->url . 'assets/images/placeholder.svg';
413 $thumb_url = $post_thumbnail_id ? wp_get_attachment_image_url( $post_thumbnail_id, $size ) : $placeHolderUrl;
414
415 if ( $url ) {
416 return $thumb_url;
417 }
418
419 echo '<div class="tutor-course-thumbnail">
420 <img src="' . $thumb_url . '" />
421 </div>';
422 }
423 }
424 /**
425 * Get the course/post thumbnail src
426 */
427 if ( ! function_exists( 'get_tutor_course_thumbnail_src' ) ) {
428 function get_tutor_course_thumbnail_src( $size = 'post-thumbnail' ) {
429 $post_id = get_the_ID();
430 $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id );
431
432 if ( $post_thumbnail_id ) {
433 $size = apply_filters( 'tutor_course_thumbnail_size', $size, $post_id );
434 $src = wp_get_attachment_image_url( $post_thumbnail_id, $size, false );
435 } else {
436 $src = tutor()->url . 'assets/images/placeholder.svg';
437 }
438
439 return $src;
440 }
441 }
442
443 if ( ! function_exists( 'tutor_course_loop_meta' ) ) {
444 function tutor_course_loop_meta() {
445 ob_start();
446 tutor_load_template( 'loop.meta' );
447 $output = apply_filters( 'tutor_course_loop_meta', ob_get_clean() );
448
449 echo tutor_kses_html( $output );
450 }
451 }
452
453 /**
454 * Get course author name in loop
455 *
456 * @since: v.1.0.0
457 */
458
459 if ( ! function_exists( 'tutor_course_loop_author' ) ) {
460 function tutor_course_loop_author() {
461 ob_start();
462 tutor_load_template( 'loop.course-author' );
463 $output = apply_filters( 'tutor_course_loop_author', ob_get_clean() );
464
465 echo $output;
466 }
467 }
468
469 /**
470 * Get formatted price with cart form
471 */
472
473 if ( ! function_exists( 'tutor_course_loop_price' ) ) {
474 function tutor_course_loop_price() {
475
476 ob_start();
477
478 $course_id = get_the_ID();
479 $can_continue = tutor_utils()->is_enrolled( $course_id ) || get_post_meta( $course_id, '_tutor_is_public_course', true ) == 'yes';
480
481 // Check for further access type like course content access settings
482 if ( ! $can_continue ) {
483 $can_continue = tutor_utils()->has_user_course_content_access( get_current_user_id(), $course_id );
484 }
485
486 if ( $can_continue ) {
487 tutor_load_template( 'loop.course-continue' );
488
489 } elseif ( tutor_utils()->is_course_added_to_cart( $course_id ) ) {
490 tutor_load_template( 'loop.course-in-cart' );
491
492 } else {
493 $tutor_course_sell_by = apply_filters( 'tutor_course_sell_by', null );
494
495 if ( $tutor_course_sell_by && ( tutor_utils()->is_course_purchasable( $course_id ) || ! is_user_logged_in() ) ) {
496 tutor_load_template( 'loop.course-price-' . $tutor_course_sell_by );
497 } else {
498 tutor_load_template( 'loop.course-price' );
499 }
500 }
501 echo apply_filters( 'tutor_course_loop_price', ob_get_clean() );
502 }
503 }
504
505 /**
506 * Get Course rating
507 *
508 * @since v.1.0.0
509 * @updated v.1.4.5
510 */
511
512 if ( ! function_exists( 'tutor_course_loop_rating' ) ) {
513 function tutor_course_loop_rating() {
514
515 $disable = ! get_tutor_option( 'enable_course_review' );
516 if ( $disable ) {
517 return;
518 }
519
520 ob_start();
521 tutor_load_template( 'loop.rating' );
522 $output = apply_filters( 'tutor_course_loop_rating', ob_get_clean() );
523
524 echo tutor_kses_html( $output );
525 }
526 }
527
528 /**
529 * @param bool $echo
530 *
531 * @return mixed|void
532 *
533 * Get add to cart form
534 */
535
536 if ( ! function_exists( 'tutor_course_loop_add_to_cart' ) ) {
537 function tutor_course_loop_add_to_cart( $echo = true ) {
538 ob_start();
539 $tutor_course_sell_by = apply_filters( 'tutor_course_sell_by', null );
540
541 if ( $tutor_course_sell_by ) {
542 tutor_load_template( 'loop.add-to-cart-' . $tutor_course_sell_by );
543 }
544
545 $output = apply_filters( 'tutor_course_loop_add_to_cart_link', ob_get_clean() );
546
547 if ( $echo ) {
548 echo wp_kses_post( $output );
549 }
550 return $output;
551 }
552 }
553
554 if ( ! function_exists( 'tutor_course_price' ) ) {
555 function tutor_course_price() {
556 ob_start();
557 tutor_load_template( 'single.course.wc-price-html' );
558 $output = apply_filters( 'tutor_course_price', ob_get_clean() );
559
560 echo $output;
561 }
562 }
563
564 /**
565 * @param int $post_id
566 *
567 * echo the excerpt of TUTOR post type
568 *
569 * @since: v.1.0.0
570 */
571 if ( ! function_exists( 'tutor_the_excerpt' ) ) {
572 function tutor_the_excerpt( $post_id = 0 ) {
573 if ( ! $post_id ) {
574 $post_id = get_the_ID();
575 }
576 echo tutor_get_the_excerpt( $post_id );
577 }
578 }
579 /**
580 * @param int $post_id
581 *
582 * @return mixed
583 *
584 * Return excerpt of TUTOR post type
585 *
586 * @since: v.1.0.0
587 */
588 if ( ! function_exists( 'tutor_get_the_excerpt' ) ) {
589 function tutor_get_the_excerpt( $post_id = 0 ) {
590 if ( ! $post_id ) {
591 $post_id = get_the_ID();
592 }
593
594 $get_post = get_post( $post_id );
595 return apply_filters( 'tutor_get_the_excerpt', $get_post->post_excerpt );
596 }
597 }
598
599 /**
600 * @return mixed
601 *
602 * return course author
603 *
604 * @since: v.1.0.0
605 */
606
607 if ( ! function_exists( 'get_tutor_course_author' ) ) {
608 function get_tutor_course_author() {
609 global $post;
610 return apply_filters( 'get_tutor_course_author', get_the_author_meta( 'display_name', $post->post_author ) );
611 }
612 }
613
614 function get_tutor_course_author_id() {
615 global $post;
616 return (int) $post->post_author;
617 }
618
619 /**
620 * @param int $course_id
621 *
622 * @return mixed
623 * Course benefits return array
624 *
625 * @since: v.1.0.0
626 */
627
628 if ( ! function_exists( 'tutor_course_benefits' ) ) {
629 function tutor_course_benefits( $course_id = 0 ) {
630 if ( ! $course_id ) {
631 $course_id = get_the_ID();
632 }
633 $benefits = get_post_meta( $course_id, '_tutor_course_benefits', true );
634
635 $benefits_array = array();
636 if ( $benefits ) {
637 $benefits_array = explode( "\n", $benefits );
638 }
639
640 $array = array_filter( array_map( 'trim', $benefits_array ) );
641
642 return apply_filters( 'tutor_course/single/benefits', $array, $course_id );
643 }
644 }
645
646 /**
647 * @param bool $echo
648 *
649 * @return mixed
650 *
651 * Course single page benefits
652 *
653 * @since: v.1.0.0
654 */
655
656 if ( ! function_exists( 'tutor_course_benefits_html' ) ) {
657 function tutor_course_benefits_html( $echo = true ) {
658 ob_start();
659 tutor_load_template( 'single.course.course-benefits' );
660 $output = apply_filters( 'tutor_course/single/benefits_html', ob_get_clean() );
661
662 if ( $echo ) {
663 echo wp_kses_post( $output );
664 }
665 return $output;
666 }
667 }
668
669 /**
670 * @param bool $echo
671 *
672 * @return mixed|void
673 *
674 * Return Topics HTML
675 *
676 * @since: v.1.0.0
677 */
678 if ( ! function_exists( 'tutor_course_topics' ) ) {
679 function tutor_course_topics( $echo = true ) {
680 ob_start();
681 tutor_load_template( 'single.course.course-topics' );
682 $output = apply_filters( 'tutor_course/single/topics', ob_get_clean() );
683 wp_reset_postdata();
684
685 if ( $echo ) {
686 echo tutor_kses_html( $output );
687 }
688
689 return $output;
690 }
691 }
692
693 /**
694 * @param int $course_id
695 *
696 * @return mixed|void
697 *
698 * return course requirements in array
699 *
700 * @since: v.1.0.0
701 */
702 if ( ! function_exists( 'tutor_course_requirements' ) ) {
703 function tutor_course_requirements( $course_id = 0 ) {
704 if ( ! $course_id ) {
705 $course_id = get_the_ID();
706 }
707 $requirements = get_post_meta( $course_id, '_tutor_course_requirements', true );
708
709 $requirements_array = array();
710 if ( $requirements ) {
711 $requirements_array = explode( "\n", $requirements );
712 }
713
714 $array = array_filter( array_map( 'trim', $requirements_array ) );
715 return apply_filters( 'tutor_course/single/requirements', $array, $course_id );
716 }
717 }
718
719 /**
720 * @param bool $echo
721 *
722 * @return mixed|void
723 *
724 * Return course requirements in course single page
725 *
726 * @since: v.1.0.0
727 */
728 if ( ! function_exists( 'tutor_course_requirements_html' ) ) {
729 function tutor_course_requirements_html( $echo = true ) {
730 ob_start();
731 tutor_course_material_includes_html();
732 tutor_load_template( 'single.course.course-requirements' );
733 $output = apply_filters( 'tutor_course/single/requirements_html', ob_get_clean() );
734
735 if ( $echo ) {
736 echo tutor_kses_html( $output );
737 }
738 return $output;
739 }
740 }
741
742
743 /**
744 * @param int $course_id
745 *
746 * @return mixed|void
747 *
748 * Return target audience in course single page
749 *
750 * @since: v.1.0.0
751 */
752 if ( ! function_exists( 'tutor_course_target_audience' ) ) {
753 function tutor_course_target_audience( $course_id = 0 ) {
754 if ( ! $course_id ) {
755 $course_id = get_the_ID();
756 }
757 $target_audience = get_post_meta( $course_id, '_tutor_course_target_audience', true );
758
759 $target_audience_array = array();
760 if ( $target_audience ) {
761 $target_audience_array = explode( "\n", $target_audience );
762 }
763
764 $array = array_filter( array_map( 'trim', $target_audience_array ) );
765 return apply_filters( 'tutor_course/single/target_audience', $array, $course_id );
766 }
767 }
768
769 /**
770 * @param bool $echo
771 *
772 * @return mixed|void
773 *
774 * Return target audience in course single page
775 *
776 * @since: v.1.0.0
777 */
778 if ( ! function_exists( 'tutor_course_target_audience_html' ) ) {
779 function tutor_course_target_audience_html( $echo = true ) {
780 ob_start();
781 tutor_load_template( 'single.course.course-target-audience' );
782 $output = apply_filters( 'tutor_course/single/audience_html', ob_get_clean() );
783
784 if ( $echo ) {
785 echo tutor_kses_html( $output );
786 }
787 return $output;
788 }
789 }
790
791
792 if ( ! function_exists( 'tutor_course_material_includes' ) ) {
793 function tutor_course_material_includes( $course_id = 0 ) {
794 if ( ! $course_id ) {
795 $course_id = get_the_ID();
796 }
797 $target_audience = get_post_meta( $course_id, '_tutor_course_material_includes', true );
798
799 $target_audience_array = array();
800 if ( $target_audience ) {
801 $target_audience_array = explode( "\n", $target_audience );
802 }
803
804 $array = array_filter( array_map( 'trim', $target_audience_array ) );
805 return apply_filters( 'tutor_course/single/material_includes', $array, $course_id );
806 }
807 }
808
809 if ( ! function_exists( 'tutor_course_material_includes_html' ) ) {
810 function tutor_course_material_includes_html( $echo = true ) {
811 ob_start();
812 tutor_load_template( 'single.course.material-includes' );
813 $output = apply_filters( 'tutor_course/single/material_includes', ob_get_clean() );
814
815 if ( $echo ) {
816 echo tutor_kses_html( $output );
817 }
818 return $output;
819 }
820 }
821
822 // tutor_course_material_includes_html
823
824
825 if ( ! function_exists( 'tutor_course_instructors_html' ) ) {
826 function tutor_course_instructors_html( $echo = true ) {
827 $display_course_instructors = tutor_utils()->get_option( 'display_course_instructors' );
828 if ( ! $display_course_instructors ) {
829 return null;
830 }
831
832 ob_start();
833 tutor_load_template( 'single.course.instructors' );
834 $output = apply_filters( 'tutor_course/single/instructors_html', ob_get_clean() );
835
836 if ( $echo ) {
837 echo tutor_kses_html( $output );
838 }
839 return $output;
840 }
841 }
842
843 if ( ! function_exists( 'tutor_course_target_reviews_html' ) ) {
844 function tutor_course_target_reviews_html( $echo = true ) {
845 ob_start();
846 tutor_load_template( 'single.course.reviews' );
847
848 $output = apply_filters( 'tutor_course/single/reviews_html', ob_get_clean() );
849
850 if ( $echo ) {
851 echo tutor_kses_html( $output );
852 }
853 return $output;
854 }
855 }
856
857 /**
858 * @param bool $echo
859 *
860 * @return mixed
861 *
862 * Course single page main content / description
863 *
864 * @since: v.1.0.0
865 */
866 if ( ! function_exists( 'tutor_course_content' ) ) {
867 function tutor_course_content( $echo = true ) {
868 ob_start();
869 tutor_load_template( 'single.course.course-content' );
870 $output = apply_filters( 'tutor_course/single/content', ob_get_clean() );
871
872 if ( $echo ) {
873 echo tutor_kses_html( $output );
874 }
875
876 return $output;
877 }
878 }
879
880 /**
881 * Course single page lead info
882 *
883 * @since: v.1.0.0
884 */
885 if ( ! function_exists( 'tutor_course_lead_info' ) ) {
886 function tutor_course_lead_info( $echo = true ) {
887 ob_start();
888
889 // exit('failed');
890
891 $course_id = get_the_ID();
892 $course_post_type = tutor()->course_post_type;
893 $queryCourse = new WP_Query(
894 array(
895 'p' => $course_id,
896 'post_type' => $course_post_type,
897 )
898 );
899
900 if ( $queryCourse->have_posts() ) {
901 while ( $queryCourse->have_posts() ) {
902 $queryCourse->the_post();
903 tutor_load_template( 'single.course.lead-info' );
904 }
905 wp_reset_postdata();
906 }
907
908 $output = apply_filters( 'tutor_course/single/lead_info', ob_get_clean() );
909
910 if ( $echo ) {
911 echo tutor_kses_html( $output );
912 }
913 return $output;
914 }
915 }
916
917 /**
918 * @param bool $echo
919 *
920 * @return mixed|void
921 */
922
923 if ( ! function_exists( 'tutor_course_enrolled_lead_info' ) ) {
924 function tutor_course_enrolled_lead_info( $echo = true ) {
925 ob_start();
926
927 $course_id = get_the_ID();
928 $course_post_type = tutor()->course_post_type;
929 $queryCourse = new WP_Query(
930 array(
931 'p' => $course_id,
932 'post_type' => $course_post_type,
933 )
934 );
935
936 if ( $queryCourse->have_posts() ) {
937 while ( $queryCourse->have_posts() ) {
938 $queryCourse->the_post();
939 tutor_load_template( 'single.course.lead-info' );
940 }
941 wp_reset_postdata();
942 }
943
944 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
945
946 if ( $echo ) {
947 echo tutor_kses_html( $output );
948 }
949
950 return $output;
951 }
952 }
953
954 if ( ! function_exists( 'tutor_lesson_lead_info' ) ) {
955 function tutor_lesson_lead_info( $lesson_id = 0, $echo = true ) {
956 if ( ! $lesson_id ) {
957 $lesson_id = get_the_ID();
958 }
959
960 ob_start();
961 $course_id = tutor_utils()->get_course_id_by( 'lesson', $lesson_id );
962 $course_post_type = tutor()->course_post_type;
963 $queryCourse = new WP_Query(
964 array(
965 'p' => $course_id,
966 'post_type' => $course_post_type,
967 )
968 );
969
970 if ( $queryCourse->have_posts() ) {
971 while ( $queryCourse->have_posts() ) {
972 $queryCourse->the_post();
973 tutor_load_template( 'single.course.lead-info' );
974 }
975 wp_reset_postdata();
976 }
977 $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() );
978
979 if ( $echo ) {
980 echo $output;
981 }
982
983 return $output;
984
985 }
986 }
987
988 if ( ! function_exists( 'tutor_course_video' ) ) {
989 function tutor_course_video( $echo = true ) {
990 ob_start();
991 tutor_load_template( 'single.video.video' );
992 $output = apply_filters( 'tutor_course/single/video', ob_get_clean() );
993
994 if ( $echo ) {
995 echo $output;
996 }
997 return $output;
998 }
999 }
1000
1001 if ( ! function_exists( 'tutor_lesson_video' ) ) {
1002 function tutor_lesson_video( $echo = true ) {
1003 ob_start();
1004 tutor_load_template( 'single.video.video' );
1005 $output = apply_filters( 'tutor_lesson/single/video', ob_get_clean() );
1006
1007 if ( $echo ) {
1008 echo tutor_kses_html( $output );
1009 }
1010 return $output;
1011 }
1012 }
1013
1014 /**
1015 *
1016 * Get all lessons attachments
1017 *
1018 * @param bool $echo
1019 *
1020 * @return mixed
1021 *
1022 * @since v.1.0.0
1023 */
1024 if ( ! function_exists( 'get_tutor_posts_attachments' ) ) {
1025 function get_tutor_posts_attachments( $echo = true ) {
1026 ob_start();
1027 tutor_load_template( 'global.attachments' );
1028 $output = apply_filters( 'tutor_lesson/single/attachments', ob_get_clean() );
1029
1030 if ( $echo ) {
1031 echo tutor_kses_html( $output );
1032 }
1033 return $output;
1034 }
1035 }
1036
1037 /**
1038 * @param bool $echo
1039 *
1040 * @return mixed
1041 *
1042 * Render Lesson Main Content
1043 * @since v.1.0.0
1044 */
1045 if ( ! function_exists( 'tutor_lesson_content' ) ) {
1046 function tutor_lesson_content( $echo = true ) {
1047 ob_start();
1048 tutor_load_template( 'single.lesson.content' );
1049 $output = apply_filters( 'tutor_lesson/single/content', ob_get_clean() );
1050
1051 if ( $echo ) {
1052 echo $output;
1053 }
1054
1055 return $output;
1056 }
1057 }
1058
1059 if ( ! function_exists( 'tutor_lesson_mark_complete_html' ) ) {
1060 function tutor_lesson_mark_complete_html( $echo = true ) {
1061 ob_start();
1062 tutor_load_template( 'single.lesson.complete_form' );
1063 $output = apply_filters( 'tutor_lesson/single/complete_form', ob_get_clean() );
1064
1065 if ( $echo ) {
1066 echo tutor_kses_html( $output );
1067 }
1068
1069 return $output;
1070 }
1071 }
1072
1073 function tutor_course_question_and_answer( $echo = true ) {
1074 ob_start();
1075 tutor_load_template( 'single.course.enrolled.question_and_answer' );
1076 $output = apply_filters( 'tutor_course/single/question_and_answer', ob_get_clean() );
1077
1078 if ( $echo ) {
1079 echo $output;
1080 }
1081
1082 return $output;
1083 }
1084
1085 /**
1086 * @param bool $echo
1087 *
1088 * @return mixed
1089 *
1090 * @show progress bar about course complete
1091 *
1092 * @since v.2.0.0
1093 *
1094 * Course Curriculum added
1095 *
1096 * @since v2.0.5
1097 */
1098
1099 function tutor_course_info_tab() {
1100 tutor_course_content();
1101 tutor_course_benefits_html();
1102 tutor_course_topics();
1103 }
1104
1105
1106 function tutor_course_announcements( $echo = true ) {
1107 ob_start();
1108 tutor_load_template( 'single.course.enrolled.announcements' );
1109 $output = apply_filters( 'tutor_course/single/announcements', ob_get_clean() );
1110
1111 if ( $echo ) {
1112 echo $output;
1113 }
1114
1115 return $output;
1116 }
1117
1118 function tutor_single_quiz_top( $echo = true ) {
1119 ob_start();
1120 tutor_load_template( 'single.quiz.top' );
1121 $output = apply_filters( 'tutor_single_quiz/top', ob_get_clean() );
1122
1123 if ( $echo ) {
1124 echo $output;
1125 }
1126 return $output;
1127 }
1128
1129 function tutor_single_quiz_body( $echo = true ) {
1130 ob_start();
1131 tutor_load_template( 'single.quiz.body' );
1132 $output = apply_filters( 'tutor_single_quiz/body', ob_get_clean() );
1133
1134 if ( $echo ) {
1135 echo $output;
1136 }
1137 return $output;
1138 }
1139
1140 /**
1141 * @param bool $echo
1142 *
1143 * @return mixed|void
1144 *
1145 * Get the quiz description
1146 */
1147 function tutor_single_quiz_content( $echo = true ) {
1148 ob_start();
1149 tutor_load_template( 'single.quiz.content' );
1150 $output = apply_filters( 'tutor_single_quiz/content', ob_get_clean() );
1151
1152 if ( $echo ) {
1153 echo $output;
1154 }
1155 return $output;
1156 }
1157
1158
1159 function tutor_single_quiz_no_course_belongs( $echo = true ) {
1160 ob_start();
1161 tutor_load_template( 'single.quiz.no_course_belongs' );
1162 $output = apply_filters( 'tutor_single_quiz/no_course_belongs', ob_get_clean() );
1163
1164 if ( $echo ) {
1165 echo $output;
1166 }
1167 return $output;
1168 }
1169
1170 function single_quiz_contents( $echo = true ) {
1171
1172 ob_start();
1173 tutor_load_template( 'single.quiz.single_quiz_contents' );
1174 $output = apply_filters( 'tutor_single_quiz/single_quiz_contents', ob_get_clean() );
1175
1176 if ( $echo ) {
1177 echo $output;
1178 }
1179 return $output;
1180 }
1181
1182 function get_tutor_course_level( $course_id = 0 ) {
1183 if ( ! $course_id ) {
1184 $course_id = get_the_ID();
1185 }
1186 if ( ! $course_id ) {
1187 return '';
1188 }
1189
1190 $course_level = get_post_meta( $course_id, '_tutor_course_level', true );
1191
1192 if ( $course_level ) {
1193 return tutor_utils()->course_levels( $course_level );
1194 }
1195 return false;
1196 }
1197
1198 if ( ! function_exists( 'get_tutor_course_duration_context' ) ) {
1199 function get_tutor_course_duration_context( $course_id = 0, $short_form = false ) {
1200 if ( ! $course_id ) {
1201 $course_id = get_the_ID();
1202 }
1203 if ( ! $course_id ) {
1204 return '';
1205 }
1206 $duration = get_post_meta( $course_id, '_course_duration', true );
1207 $durationHours = tutor_utils()->avalue_dot( 'hours', $duration );
1208 $durationMinutes = tutor_utils()->avalue_dot( 'minutes', $duration );
1209 $durationSeconds = tutor_utils()->avalue_dot( 'seconds', $duration );
1210
1211 $hour_format = $short_form ? __( 'h', 'tutor' ) : ' ' . ( $durationHours > 1 ? __( 'hours', 'tutor' ) : __( 'hour', 'tutor' ) );
1212 $minute_format = $short_form ? __( 'm', 'tutor' ) : ' ' . ( $durationMinutes > 1 ? __( 'minutes', 'tutor' ) : __( 'minute', 'tutor' ) );
1213 $second_format = $short_form ? __( 's', 'tutor' ) : ' ' . ( $durationSeconds > 1 ? __( 'seconds', 'tutor' ) : __( 'second', 'tutor' ) );
1214
1215 if ( $duration ) {
1216 $output = '';
1217 if ( $durationHours > 0 ) {
1218 $output .= '<span class="tutor-meta-level">' . ' ' . $durationHours . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $hour_format . '</span>';
1219 }
1220
1221 if ( $durationMinutes > 0 ) {
1222 $output .= '<span class="tutor-meta-level">' . ' ' . $durationMinutes . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $minute_format . '</span>';
1223 }
1224
1225 if ( ! $durationHours && ! $durationMinutes && $durationSeconds > 0 ) {
1226 $output .= '<span class="tutor-meta-level">' . ' ' . $durationSeconds . '</span><span class="tutor-meta-value tutor-color-secondary tutor-mr-4">' . $second_format . '</span>';
1227 }
1228
1229 return $output;
1230 }
1231
1232 return false;
1233 }
1234 }
1235 if ( ! function_exists( 'get_tutor_course_categories' ) ) {
1236 function get_tutor_course_categories( $course_id = 0 ) {
1237 if ( ! $course_id ) {
1238 $course_id = get_the_ID();
1239 }
1240 $terms = get_the_terms( $course_id, 'course-category' );
1241
1242 return $terms;
1243 }
1244 }
1245
1246 /**
1247 * @param int $course_id
1248 *
1249 * @return array|false|WP_Error
1250 *
1251 * Get course tags
1252 */
1253
1254 if ( ! function_exists( 'get_tutor_course_tags' ) ) {
1255 function get_tutor_course_tags( $course_id = 0 ) {
1256 if ( ! $course_id ) {
1257 $course_id = get_the_ID();
1258 }
1259 $terms = get_the_terms( $course_id, 'course-tag' );
1260
1261 return $terms;
1262 }
1263 }
1264
1265 /**
1266 * @param bool $echo
1267 *
1268 * @return mixed|void
1269 *
1270 * Template for course tags html
1271 */
1272
1273 if ( ! function_exists( 'tutor_course_tags_html' ) ) {
1274 function tutor_course_tags_html( $echo = true ) {
1275 ob_start();
1276 tutor_load_template( 'single.course.tags' );
1277 $output = apply_filters( 'tutor_course/single/tags_html', ob_get_clean() );
1278
1279 if ( $echo ) {
1280 echo tutor_kses_html( $output );
1281 }
1282
1283 return $output;
1284 }
1285 }
1286
1287 /**
1288 * @param bool $echo
1289 *
1290 * @return mixed
1291 *
1292 * Get Q&A in lesson sidebar
1293 */
1294
1295 if ( ! function_exists( 'tutor_lesson_sidebar_question_and_answer' ) ) {
1296 function tutor_lesson_sidebar_question_and_answer( $echo = true ) {
1297 ob_start();
1298 tutor_load_template( 'single.lesson.sidebar_question_and_answer' );
1299 $output = apply_filters( 'tutor_lesson/single/sidebar_question_and_answer', ob_get_clean() );
1300
1301 if ( $echo ) {
1302 echo tutor_kses_html( $output );
1303 }
1304
1305 return $output;
1306 }
1307 }
1308
1309 /**
1310 * @param bool $echo
1311 *
1312 * @return mixed
1313 *
1314 * Get Assignment content
1315 *
1316 * @since v.1.3.3
1317 */
1318
1319 if ( ! function_exists( 'tutor_assignment_content' ) ) {
1320 function tutor_assignment_content( $echo = true ) {
1321 ob_start();
1322 tutor_load_template( 'single.assignment.content' );
1323 $output = apply_filters( 'tutor_assignment/single/content', ob_get_clean() );
1324
1325 if ( $echo ) {
1326 echo tutor_kses_html( $output );
1327 }
1328
1329 return $output;
1330 }
1331 }
1332
1333 /**
1334 * @param string $msg
1335 * @param string $title
1336 * @param string $type
1337 *
1338 * @return string
1339 *
1340 * @since v.1.4.0
1341 */
1342
1343 if ( ! function_exists( 'get_tnotice' ) ) {
1344 function get_tnotice( $msg = '', $title = 'Success', $type = 'success' ) {
1345
1346 $output = '<div class="tnotice tnotice--' . $type . '">
1347 <div class="tnotice__icon">&iexcl;</div>
1348 <div class="tnotice__content">';
1349
1350 if ( $title ) {
1351 $output .= '<p class="tnotice__type">' . $title . '</p>';
1352 }
1353 $output .= '<p class="tnotice__message">' . $msg . '</p>
1354 </div>
1355 </div>';
1356
1357 return $output;
1358 }
1359 }
1360
1361 /**
1362 * @param int $course_content_id
1363 * @param bool $echo
1364 *
1365 * @return mixed|void
1366 *
1367 * Next Previous Pagination
1368 *
1369 * @since v.1.4.7
1370 */
1371
1372 function tutor_next_previous_pagination( $course_content_id = 0, $echo = true ) {
1373 $content_id = tutor_utils()->get_post_id( $course_content_id );
1374 $contents = tutor_utils()->get_course_prev_next_contents_by_id( $content_id );
1375 $previous_id = $contents->previous_id;
1376 $next_id = $contents->next_id;
1377
1378 ob_start();
1379 do_action( 'tutor_lesson_next_previous_pagination_before' );
1380 tutor_load_template( 'single.next-previous-pagination', compact( 'previous_id', 'next_id' ) );
1381 do_action( 'tutor_lesson_next_previous_pagination_after' );
1382 $output = apply_filters( 'tutor/single/next_previous_pagination', ob_get_clean() );
1383
1384 if ( $echo ) {
1385 echo tutor_kses_html( $output );
1386 }
1387
1388 return $output;
1389 }
1390
1391 /**
1392 * Load custom template from any given file
1393 *
1394 * Pass parameter as wish
1395 *
1396 * @since 1.9.8
1397 */
1398 if ( ! function_exists( 'tutor_load_template_from_custom_path' ) ) {
1399 function tutor_load_template_from_custom_path( $template = null, $data = array(), $once = true ) {
1400 do_action( 'tutor_load_template_from_custom_path_before', $template, $data );
1401 if ( file_exists( $template ) ) {
1402 if ( $once ) {
1403 include_once $template;
1404 } else {
1405 include $template;
1406 }
1407 }
1408 do_action( 'tutor_load_template_from_custom_path_after', $template, $data );
1409 }
1410 }
1411
1412 /**
1413 * Load enrolled course progress template
1414 *
1415 * This template will be used on only dashboard enrolled course page
1416 *
1417 * @since v2.0.0
1418 */
1419 if ( ! function_exists( 'tutor_enrolled_course_progress' ) ) {
1420 function tutor_enrolled_course_progress() {
1421 global $wp_query;
1422 $query_vars = $wp_query->query_vars;
1423 if ( isset( $query_vars['tutor_dashboard_page'] ) && 'enrolled-courses' === $query_vars['tutor_dashboard_page'] ) {
1424 tutor_load_template_from_custom_path( tutor()->path . 'templates/loop/enrolled-course-progress.php', '', false );
1425 }
1426 }
1427 }
1428