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