theme-compatibility
7 years ago
tutor-general-functions.php
7 years ago
tutor-template-functions.php
7 years ago
tutor-template-hook.php
7 years ago
tutor-template-functions.php
1222 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) |
| 4 | exit; |
| 5 | |
| 6 | /** |
| 7 | * @param null $template |
| 8 | * |
| 9 | * @return bool|string |
| 10 | * |
| 11 | * Load template with override file system |
| 12 | * |
| 13 | * @since v.1.0.0 |
| 14 | */ |
| 15 | |
| 16 | if ( ! function_exists('tutor_get_template')) { |
| 17 | function tutor_get_template( $template = null ) { |
| 18 | if ( ! $template ) { |
| 19 | return false; |
| 20 | } |
| 21 | $template = str_replace( '.', DIRECTORY_SEPARATOR, $template ); |
| 22 | |
| 23 | $template_location = trailingslashit( get_template_directory() ) . "tutor/{$template}.php"; |
| 24 | $file_in_theme = $template_location; |
| 25 | if ( ! file_exists( $template_location ) ) { |
| 26 | $template_location = trailingslashit( tutor()->path ) . "templates/{$template}.php"; |
| 27 | |
| 28 | if ( ! file_exists($template_location)){ |
| 29 | echo '<div class="tutor-notice-warning"> '.__(sprintf('The file you are trying to load is not exists in your theme or tutor plugins location, if you are a developer and extending tutor plugin, please create a php file at location %s ', "<code>{$file_in_theme}</code>"), 'tutor').' </div>'; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return $template_location; |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @param null $template |
| 39 | * |
| 40 | * @param array $variables |
| 41 | * |
| 42 | * Load template for TUTOR |
| 43 | * |
| 44 | * @since v.1.0.0 |
| 45 | * |
| 46 | * @updated v.1.1.2 |
| 47 | */ |
| 48 | |
| 49 | if ( ! function_exists('tutor_load_template')) { |
| 50 | function tutor_load_template( $template = null, $variables = array() ) { |
| 51 | $variables = (array) $variables; |
| 52 | extract($variables); |
| 53 | |
| 54 | include tutor_get_template( $template ); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | if ( ! function_exists('tutor_course_loop_start')){ |
| 59 | function tutor_course_loop_start($echo = true ){ |
| 60 | ob_start(); |
| 61 | tutor_load_template('loop.loop-start'); |
| 62 | $output = apply_filters('tutor_course_loop_start', ob_get_clean()); |
| 63 | |
| 64 | if ( $echo ) { |
| 65 | echo $output; |
| 66 | } |
| 67 | return $output; |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | if ( ! function_exists('tutor_course_loop_end')) { |
| 72 | function tutor_course_loop_end( $echo = true ) { |
| 73 | ob_start(); |
| 74 | tutor_load_template( 'loop.loop-end' ); |
| 75 | |
| 76 | $output = apply_filters( 'tutor_course_loop_end', ob_get_clean() ); |
| 77 | if ( $echo ) { |
| 78 | echo $output; |
| 79 | } |
| 80 | |
| 81 | return $output; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | if ( ! function_exists('tutor_course_archive_pagination')) { |
| 86 | function tutor_course_archive_pagination( $echo = true ) { |
| 87 | ob_start(); |
| 88 | tutor_load_template( 'loop.tutor-pagination' ); |
| 89 | |
| 90 | $output = apply_filters( 'tutor_course_archive_pagination', ob_get_clean() ); |
| 91 | if ( $echo ) { |
| 92 | echo $output; |
| 93 | } |
| 94 | |
| 95 | return $output; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | function tutor_course_loop_before_content(){ |
| 100 | ob_start(); |
| 101 | tutor_load_template( 'loop.loop-before-content' ); |
| 102 | |
| 103 | $output = apply_filters( 'tutor_course_loop_before_content', ob_get_clean() ); |
| 104 | echo $output; |
| 105 | } |
| 106 | |
| 107 | function tutor_course_loop_after_content(){ |
| 108 | ob_start(); |
| 109 | tutor_load_template( 'loop.loop-after-content' ); |
| 110 | |
| 111 | $output = apply_filters( 'tutor_course_loop_after_content', ob_get_clean() ); |
| 112 | echo $output; |
| 113 | } |
| 114 | |
| 115 | if ( ! function_exists('tutor_course_loop_title')) { |
| 116 | function tutor_course_loop_title() { |
| 117 | ob_start(); |
| 118 | tutor_load_template( 'loop.title' ); |
| 119 | $output = apply_filters( 'tutor_course_loop_title', ob_get_clean() ); |
| 120 | |
| 121 | echo $output; |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | |
| 126 | if ( ! function_exists('tutor_course_loop_header')) { |
| 127 | function tutor_course_loop_header() { |
| 128 | ob_start(); |
| 129 | tutor_load_template( 'loop.header' ); |
| 130 | $output = apply_filters( 'tutor_course_loop_header', ob_get_clean() ); |
| 131 | |
| 132 | echo $output; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | if ( ! function_exists('tutor_course_loop_footer')) { |
| 137 | function tutor_course_loop_footer() { |
| 138 | ob_start(); |
| 139 | tutor_load_template( 'loop.footer' ); |
| 140 | $output = apply_filters( 'tutor_course_loop_footer', ob_get_clean() ); |
| 141 | |
| 142 | echo $output; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | //tutor_course_loop_footer |
| 147 | |
| 148 | |
| 149 | if ( ! function_exists('tutor_course_loop_start_content_wrap')) { |
| 150 | function tutor_course_loop_start_content_wrap() { |
| 151 | ob_start(); |
| 152 | tutor_load_template( 'loop.start_content_wrap' ); |
| 153 | $output = apply_filters( 'tutor_course_loop_start_content_wrap', ob_get_clean() ); |
| 154 | |
| 155 | echo $output; |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | if ( ! function_exists('tutor_course_loop_end_content_wrap')) { |
| 160 | function tutor_course_loop_end_content_wrap() { |
| 161 | ob_start(); |
| 162 | tutor_load_template( 'loop.end_content_wrap' ); |
| 163 | $output = apply_filters( 'tutor_course_loop_end_content_wrap', ob_get_clean() ); |
| 164 | |
| 165 | echo $output; |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | if ( ! function_exists('tutor_course_loop_thumbnail')) { |
| 170 | function tutor_course_loop_thumbnail() { |
| 171 | ob_start(); |
| 172 | tutor_load_template( 'loop.thumbnail' ); |
| 173 | $output = apply_filters( 'tutor_course_loop_thumbnail', ob_get_clean() ); |
| 174 | |
| 175 | echo $output; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | if( ! function_exists('tutor_course_loop_wrap_classes')) { |
| 180 | function tutor_course_loop_wrap_classes( $echo = true ) { |
| 181 | $courseID = get_the_ID(); |
| 182 | $classes = apply_filters( 'tutor_course_loop_wrap_classes', array( |
| 183 | 'tutor-course', |
| 184 | 'tutor-course-loop', |
| 185 | 'tutor-course-loop-' . $courseID, |
| 186 | ) ); |
| 187 | |
| 188 | $class = implode( ' ', $classes ); |
| 189 | if ( $echo ) { |
| 190 | echo $class; |
| 191 | } |
| 192 | |
| 193 | return $class; |
| 194 | } |
| 195 | } |
| 196 | |
| 197 | if( ! function_exists('tutor_course_loop_col_classes')) { |
| 198 | function tutor_course_loop_col_classes( $echo = true ) { |
| 199 | $courseCols = tutor_utils()->get_option( 'courses_col_per_row', 4 ); |
| 200 | $classes = apply_filters( 'tutor_course_loop_col_classes', array( |
| 201 | 'tutor-course-col-' . $courseCols, |
| 202 | ) ); |
| 203 | |
| 204 | $class = implode( ' ', $classes ); |
| 205 | if ( $echo ) { |
| 206 | echo $class; |
| 207 | } |
| 208 | |
| 209 | return $class; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | |
| 214 | if ( ! function_exists('tutor_container_classes')) { |
| 215 | function tutor_container_classes( $echo = true ) { |
| 216 | |
| 217 | $classes = apply_filters( 'tutor_container_classes', array( |
| 218 | 'tutor-wrap tutor-courses-wrap', |
| 219 | 'tutor-container' |
| 220 | ) ); |
| 221 | |
| 222 | $class = implode( ' ', $classes ); |
| 223 | |
| 224 | if ( $echo ) { |
| 225 | echo $class; |
| 226 | } |
| 227 | |
| 228 | return $class; |
| 229 | } |
| 230 | } |
| 231 | if ( ! function_exists('tutor_post_class')) { |
| 232 | function tutor_post_class($default = '') { |
| 233 | $classes = apply_filters( 'tutor_post_class', array( |
| 234 | 'tutor-wrap', |
| 235 | $default |
| 236 | ) ); |
| 237 | |
| 238 | post_class( $classes ); |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if ( ! function_exists('tutor_course_archive_filter_bar')) { |
| 243 | function tutor_course_archive_filter_bar() { |
| 244 | ob_start(); |
| 245 | tutor_load_template( 'global.course-archive-filter-bar' ); |
| 246 | $output = apply_filters( 'tutor_course_archive_filter_bar', ob_get_clean() ); |
| 247 | |
| 248 | echo $output; |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Get the post thumbnail |
| 254 | */ |
| 255 | if ( ! function_exists('get_tutor_course_thumbnail')) { |
| 256 | function get_tutor_course_thumbnail($url = false) { |
| 257 | $post_id = get_the_ID(); |
| 258 | $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id ); |
| 259 | |
| 260 | if ( $post_thumbnail_id ) { |
| 261 | |
| 262 | $size = 'post-thumbnail'; |
| 263 | $size = apply_filters( 'post_thumbnail_size', $size, $post_id ); |
| 264 | if ($url){ |
| 265 | return wp_get_attachment_image_url($post_thumbnail_id, $size); |
| 266 | } |
| 267 | |
| 268 | $html = wp_get_attachment_image( $post_thumbnail_id, $size, false ); |
| 269 | } else { |
| 270 | $placeHolderUrl = tutor()->url . 'assets/images/placeholder.jpg'; |
| 271 | if ($url){ |
| 272 | return $placeHolderUrl; |
| 273 | } |
| 274 | $html = sprintf('<img alt="%s" src="' . $placeHolderUrl . '" />', __('Placeholder', 'tutor')); |
| 275 | } |
| 276 | |
| 277 | echo $html; |
| 278 | } |
| 279 | } |
| 280 | /** |
| 281 | * Get the course/post thumbnail src |
| 282 | */ |
| 283 | if ( ! function_exists('get_tutor_course_thumbnail_src')) { |
| 284 | function get_tutor_course_thumbnail_src() { |
| 285 | $post_id = get_the_ID(); |
| 286 | $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id ); |
| 287 | |
| 288 | if ( $post_thumbnail_id ) { |
| 289 | $size = 'post-thumbnail'; |
| 290 | $size = apply_filters( 'post_thumbnail_size', $size, $post_id ); |
| 291 | $src = wp_get_attachment_image_url( $post_thumbnail_id, $size, false ); |
| 292 | } else { |
| 293 | $src = tutor()->url . 'assets/images/placeholder.jpg'; |
| 294 | } |
| 295 | |
| 296 | return $src; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | if ( ! function_exists('tutor_course_loop_meta')) { |
| 301 | function tutor_course_loop_meta() { |
| 302 | ob_start(); |
| 303 | tutor_load_template( 'loop.meta' ); |
| 304 | $output = apply_filters( 'tutor_course_loop_meta', ob_get_clean() ); |
| 305 | |
| 306 | echo $output; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /** |
| 311 | * Get course author name in loop |
| 312 | * |
| 313 | * @since: v.1.0.0 |
| 314 | */ |
| 315 | |
| 316 | if ( ! function_exists('tutor_course_loop_author')) { |
| 317 | function tutor_course_loop_author() { |
| 318 | ob_start(); |
| 319 | tutor_load_template( 'loop.course-author' ); |
| 320 | $output = apply_filters( 'tutor_course_loop_author', ob_get_clean() ); |
| 321 | |
| 322 | echo $output; |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | if ( ! function_exists('tutor_course_loop_price')) { |
| 327 | function tutor_course_loop_price() { |
| 328 | ob_start(); |
| 329 | |
| 330 | $tutor_course_sell_by = apply_filters('tutor_course_sell_by', null); |
| 331 | if ($tutor_course_sell_by){ |
| 332 | tutor_load_template( 'loop.course-price-'.$tutor_course_sell_by ); |
| 333 | }else{ |
| 334 | tutor_load_template( 'loop.course-price' ); |
| 335 | } |
| 336 | $output = apply_filters( 'tutor_course_loop_price', ob_get_clean() ); |
| 337 | |
| 338 | echo $output; |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | if ( ! function_exists('tutor_course_loop_rating')) { |
| 343 | function tutor_course_loop_rating() { |
| 344 | ob_start(); |
| 345 | tutor_load_template( 'loop.rating' ); |
| 346 | $output = apply_filters( 'tutor_course_loop_rating', ob_get_clean() ); |
| 347 | |
| 348 | echo $output; |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | if ( ! function_exists('tutor_course_loop_add_to_cart')) { |
| 353 | function tutor_course_loop_add_to_cart($echo = true) { |
| 354 | ob_start(); |
| 355 | $tutor_course_sell_by = apply_filters('tutor_course_sell_by', null); |
| 356 | |
| 357 | if ($tutor_course_sell_by){ |
| 358 | tutor_load_template( 'loop.add-to-cart-'.$tutor_course_sell_by ); |
| 359 | } |
| 360 | |
| 361 | $output = apply_filters( 'tutor_course_loop_add_to_cart_link', ob_get_clean() ); |
| 362 | |
| 363 | if ($echo){ |
| 364 | echo $output; |
| 365 | } |
| 366 | return $output; |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | |
| 371 | |
| 372 | if ( ! function_exists('tutor_course_price')) { |
| 373 | function tutor_course_price() { |
| 374 | ob_start(); |
| 375 | tutor_load_template( 'single.course.wc-price-html' ); |
| 376 | $output = apply_filters( 'tutor_course_price', ob_get_clean() ); |
| 377 | |
| 378 | echo $output; |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | |
| 383 | /** |
| 384 | * @param int $post_id |
| 385 | * |
| 386 | * echo the excerpt of TUTOR post type |
| 387 | * |
| 388 | * @since: v.1.0.0 |
| 389 | */ |
| 390 | if ( ! function_exists('tutor_the_excerpt')) { |
| 391 | function tutor_the_excerpt( $post_id = 0 ) { |
| 392 | if ( ! $post_id ) { |
| 393 | $post_id = get_the_ID(); |
| 394 | } |
| 395 | echo tutor_get_the_excerpt( $post_id ); |
| 396 | } |
| 397 | } |
| 398 | /** |
| 399 | * @param int $post_id |
| 400 | * |
| 401 | * @return mixed |
| 402 | * |
| 403 | * Return excerpt of TUTOR post type |
| 404 | * |
| 405 | * @since: v.1.0.0 |
| 406 | */ |
| 407 | if ( ! function_exists('tutor_get_the_excerpt')) { |
| 408 | function tutor_get_the_excerpt( $post_id = 0 ) { |
| 409 | if ( ! $post_id ) { |
| 410 | $post_id = get_the_ID(); |
| 411 | } |
| 412 | |
| 413 | $get_post = get_post($post_id); |
| 414 | return apply_filters( 'tutor_get_the_excerpt', $get_post->post_excerpt ); |
| 415 | } |
| 416 | } |
| 417 | |
| 418 | /** |
| 419 | * @return mixed |
| 420 | * |
| 421 | * return course author |
| 422 | * |
| 423 | * @since: v.1.0.0 |
| 424 | */ |
| 425 | |
| 426 | if ( ! function_exists('get_tutor_course_author')) { |
| 427 | function get_tutor_course_author() { |
| 428 | global $post; |
| 429 | return apply_filters( 'get_tutor_course_author', get_the_author_meta( 'display_name', $post->post_author ) ); |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | function get_tutor_course_author_id(){ |
| 434 | global $post; |
| 435 | return $post->post_author; |
| 436 | } |
| 437 | |
| 438 | /** |
| 439 | * @param int $course_id |
| 440 | * |
| 441 | * @return mixed |
| 442 | * Course benefits return array |
| 443 | * |
| 444 | * @since: v.1.0.0 |
| 445 | */ |
| 446 | |
| 447 | if ( ! function_exists('tutor_course_benefits')) { |
| 448 | function tutor_course_benefits( $course_id = 0 ) { |
| 449 | if ( ! $course_id ) { |
| 450 | $course_id = get_the_ID(); |
| 451 | } |
| 452 | $benefits = get_post_meta( $course_id, '_tutor_course_benefits', true ); |
| 453 | |
| 454 | $benefits_array = array(); |
| 455 | if ($benefits){ |
| 456 | $benefits_array = explode("\n", $benefits); |
| 457 | } |
| 458 | |
| 459 | $array = array_filter(array_map('trim', $benefits_array)); |
| 460 | |
| 461 | return apply_filters( 'tutor_course/single/benefits', $array, $course_id ); |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | /** |
| 466 | * @param bool $echo |
| 467 | * |
| 468 | * @return mixed |
| 469 | * |
| 470 | * Course single page benefits |
| 471 | * |
| 472 | * @since: v.1.0.0 |
| 473 | */ |
| 474 | |
| 475 | if ( ! function_exists('tutor_course_benefits_html')) { |
| 476 | function tutor_course_benefits_html($echo = true) { |
| 477 | ob_start(); |
| 478 | tutor_load_template( 'single.course.course-benefits' ); |
| 479 | $output = apply_filters( 'tutor_course/single/benefits_html', ob_get_clean() ); |
| 480 | |
| 481 | if ($echo){ |
| 482 | echo $output; |
| 483 | } |
| 484 | return $output; |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | /** |
| 489 | * @param bool $echo |
| 490 | * |
| 491 | * @return mixed|void |
| 492 | * |
| 493 | * Return Topics HTML |
| 494 | * |
| 495 | * @since: v.1.0.0 |
| 496 | */ |
| 497 | if ( ! function_exists('tutor_course_topics')) { |
| 498 | function tutor_course_topics( $echo = true ) { |
| 499 | ob_start(); |
| 500 | tutor_load_template( 'single.course.course-topics' ); |
| 501 | $output = apply_filters( 'tutor_course/single/topics', ob_get_clean() ); |
| 502 | wp_reset_postdata(); |
| 503 | |
| 504 | if ( $echo ) { |
| 505 | echo $output; |
| 506 | } |
| 507 | |
| 508 | return $output; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | /** |
| 513 | * @param int $course_id |
| 514 | * |
| 515 | * @return mixed|void |
| 516 | * |
| 517 | * return course requirements in array |
| 518 | * |
| 519 | * @since: v.1.0.0 |
| 520 | */ |
| 521 | if ( ! function_exists('tutor_course_requirements')) { |
| 522 | function tutor_course_requirements( $course_id = 0 ) { |
| 523 | if ( ! $course_id ) { |
| 524 | $course_id = get_the_ID(); |
| 525 | } |
| 526 | $requirements = get_post_meta( $course_id, '_tutor_course_requirements', true ); |
| 527 | |
| 528 | $requirements_array = array(); |
| 529 | if ($requirements){ |
| 530 | $requirements_array = explode("\n", $requirements); |
| 531 | } |
| 532 | |
| 533 | $array = array_filter(array_map('trim', $requirements_array)); |
| 534 | return apply_filters( 'tutor_course/single/requirements', $array, $course_id ); |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * @param bool $echo |
| 540 | * |
| 541 | * @return mixed|void |
| 542 | * |
| 543 | * Return course requirements in course single page |
| 544 | * |
| 545 | * @since: v.1.0.0 |
| 546 | */ |
| 547 | if ( ! function_exists('tutor_course_requirements_html')) { |
| 548 | function tutor_course_requirements_html($echo = true) { |
| 549 | ob_start(); |
| 550 | tutor_load_template( 'single.course.course-requirements' ); |
| 551 | $output = apply_filters( 'tutor_course/single/requirements_html', ob_get_clean() ); |
| 552 | |
| 553 | if ($echo){ |
| 554 | echo $output; |
| 555 | } |
| 556 | return $output; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | |
| 561 | /** |
| 562 | * @param int $course_id |
| 563 | * |
| 564 | * @return mixed|void |
| 565 | * |
| 566 | * Return target audience in course single page |
| 567 | * |
| 568 | * @since: v.1.0.0 |
| 569 | */ |
| 570 | if ( ! function_exists('tutor_course_target_audience')) { |
| 571 | function tutor_course_target_audience( $course_id = 0 ) { |
| 572 | if ( ! $course_id ) { |
| 573 | $course_id = get_the_ID(); |
| 574 | } |
| 575 | $target_audience = get_post_meta( $course_id, '_tutor_course_target_audience', true ); |
| 576 | |
| 577 | $target_audience_array = array(); |
| 578 | if ($target_audience){ |
| 579 | $target_audience_array = explode("\n", $target_audience); |
| 580 | } |
| 581 | |
| 582 | $array = array_filter(array_map('trim', $target_audience_array)); |
| 583 | return apply_filters( 'tutor_course/single/target_audience', $array, $course_id ); |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * @param bool $echo |
| 589 | * |
| 590 | * @return mixed|void |
| 591 | * |
| 592 | * Return target audience in course single page |
| 593 | * |
| 594 | * @since: v.1.0.0 |
| 595 | */ |
| 596 | if ( ! function_exists('tutor_course_target_audience_html')) { |
| 597 | function tutor_course_target_audience_html($echo = true) { |
| 598 | ob_start(); |
| 599 | tutor_load_template( 'single.course.course-target-audience' ); |
| 600 | $output = apply_filters( 'tutor_course/single/audience_html', ob_get_clean() ); |
| 601 | |
| 602 | if ($echo){ |
| 603 | echo $output; |
| 604 | } |
| 605 | return $output; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | |
| 610 | if ( ! function_exists('tutor_course_material_includes')) { |
| 611 | function tutor_course_material_includes( $course_id = 0 ) { |
| 612 | if ( ! $course_id ) { |
| 613 | $course_id = get_the_ID(); |
| 614 | } |
| 615 | $target_audience = get_post_meta( $course_id, '_tutor_course_material_includes', true ); |
| 616 | |
| 617 | $target_audience_array = array(); |
| 618 | if ($target_audience){ |
| 619 | $target_audience_array = explode("\n", $target_audience); |
| 620 | } |
| 621 | |
| 622 | $array = array_filter(array_map('trim', $target_audience_array)); |
| 623 | return apply_filters( 'tutor_course/single/material_includes', $array, $course_id ); |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | if ( ! function_exists('tutor_course_material_includes_html')) { |
| 628 | function tutor_course_material_includes_html($echo = true) { |
| 629 | ob_start(); |
| 630 | tutor_load_template( 'single.course.material-includes' ); |
| 631 | $output = apply_filters( 'tutor_course/single/material_includes', ob_get_clean() ); |
| 632 | |
| 633 | if ($echo){ |
| 634 | echo $output; |
| 635 | } |
| 636 | return $output; |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | //tutor_course_material_includes_html |
| 641 | |
| 642 | |
| 643 | if ( ! function_exists('tutor_course_instructors_html')) { |
| 644 | function tutor_course_instructors_html($echo = true) { |
| 645 | $display_course_instructors = tutor_utils()->get_option('display_course_instructors'); |
| 646 | if ( ! $display_course_instructors){ |
| 647 | return null; |
| 648 | } |
| 649 | |
| 650 | ob_start(); |
| 651 | tutor_load_template( 'single.course.instructors' ); |
| 652 | $output = apply_filters( 'tutor_course/single/instructors_html', ob_get_clean() ); |
| 653 | |
| 654 | if ($echo){ |
| 655 | echo $output; |
| 656 | } |
| 657 | return $output; |
| 658 | } |
| 659 | } |
| 660 | |
| 661 | if ( ! function_exists('tutor_course_target_reviews_html')) { |
| 662 | function tutor_course_target_reviews_html($echo = true) { |
| 663 | ob_start(); |
| 664 | tutor_load_template( 'single.course.reviews' ); |
| 665 | $output = apply_filters( 'tutor_course/single/reviews_html', ob_get_clean() ); |
| 666 | |
| 667 | if ($echo){ |
| 668 | echo $output; |
| 669 | } |
| 670 | return $output; |
| 671 | } |
| 672 | } |
| 673 | |
| 674 | if ( ! function_exists('tutor_course_target_review_form_html')) { |
| 675 | function tutor_course_target_review_form_html($echo = true) { |
| 676 | ob_start(); |
| 677 | tutor_load_template( 'single.course.review-form' ); |
| 678 | $output = apply_filters( 'tutor_course/single/reviews_form', ob_get_clean() ); |
| 679 | |
| 680 | if ($echo){ |
| 681 | echo $output; |
| 682 | } |
| 683 | |
| 684 | return $output; |
| 685 | |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | /** |
| 690 | * @param bool $echo |
| 691 | * |
| 692 | * @return mixed |
| 693 | * |
| 694 | * Course single page main content / description |
| 695 | * |
| 696 | * @since: v.1.0.0 |
| 697 | */ |
| 698 | if ( ! function_exists('tutor_course_content')) { |
| 699 | function tutor_course_content( $echo = true ) { |
| 700 | ob_start(); |
| 701 | tutor_load_template( 'single.course.course-content' ); |
| 702 | $output = apply_filters( 'tutor_course/single/content', ob_get_clean() ); |
| 703 | |
| 704 | if ( $echo ) { |
| 705 | echo $output; |
| 706 | } |
| 707 | |
| 708 | return $output; |
| 709 | } |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * Course single page lead info |
| 714 | * |
| 715 | * @since: v.1.0.0 |
| 716 | */ |
| 717 | if ( ! function_exists('tutor_course_lead_info')) { |
| 718 | function tutor_course_lead_info( $echo = true ) { |
| 719 | ob_start(); |
| 720 | |
| 721 | $course_id = get_the_ID(); |
| 722 | $course_post_type = tutor()->course_post_type; |
| 723 | $queryCourse = new WP_Query(array('p' => $course_id, 'post_type' => $course_post_type)); |
| 724 | |
| 725 | if ($queryCourse->have_posts()){ |
| 726 | while ($queryCourse->have_posts()){ |
| 727 | $queryCourse->the_post(); |
| 728 | tutor_load_template( 'single.course.lead-info' ); |
| 729 | } |
| 730 | wp_reset_postdata(); |
| 731 | } |
| 732 | |
| 733 | $output = apply_filters( 'tutor_course/single/lead_info', ob_get_clean() ); |
| 734 | |
| 735 | if ( $echo ) { |
| 736 | echo $output; |
| 737 | } |
| 738 | return $output; |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | /** |
| 743 | * @param bool $echo |
| 744 | * |
| 745 | * @return mixed|void |
| 746 | */ |
| 747 | |
| 748 | if ( ! function_exists('tutor_course_enrolled_lead_info')) { |
| 749 | function tutor_course_enrolled_lead_info( $echo = true ) { |
| 750 | ob_start(); |
| 751 | |
| 752 | $course_id = get_the_ID(); |
| 753 | $course_post_type = tutor()->course_post_type; |
| 754 | $queryCourse = new WP_Query( array( 'p' => $course_id, 'post_type' => $course_post_type ) ); |
| 755 | |
| 756 | if ( $queryCourse->have_posts() ) { |
| 757 | while ( $queryCourse->have_posts() ) { |
| 758 | $queryCourse->the_post(); |
| 759 | tutor_load_template( 'single.course.enrolled.lead-info' ); |
| 760 | } |
| 761 | wp_reset_postdata(); |
| 762 | } |
| 763 | |
| 764 | $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() ); |
| 765 | |
| 766 | if ( $echo ) { |
| 767 | echo $output; |
| 768 | } |
| 769 | |
| 770 | return $output; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | if ( ! function_exists('tutor_lesson_lead_info')) { |
| 775 | function tutor_lesson_lead_info( $lesson_id = 0, $echo = true ) { |
| 776 | if ( ! $lesson_id ) { |
| 777 | $lesson_id = get_the_ID(); |
| 778 | } |
| 779 | |
| 780 | ob_start(); |
| 781 | $course_id = tutor_utils()->get_course_id_by_lesson( $lesson_id ); |
| 782 | $course_post_type = tutor()->course_post_type; |
| 783 | $queryCourse = new WP_Query( array( 'p' => $course_id, 'post_type' => $course_post_type ) ); |
| 784 | |
| 785 | if ( $queryCourse->have_posts() ) { |
| 786 | while ( $queryCourse->have_posts() ) { |
| 787 | $queryCourse->the_post(); |
| 788 | tutor_load_template( 'single.course.enrolled.lead-info' ); |
| 789 | } |
| 790 | wp_reset_postdata(); |
| 791 | } |
| 792 | $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() ); |
| 793 | |
| 794 | if ( $echo ) { |
| 795 | echo $output; |
| 796 | } |
| 797 | |
| 798 | return $output; |
| 799 | |
| 800 | } |
| 801 | } |
| 802 | /** |
| 803 | * @param bool $echo |
| 804 | * |
| 805 | * @return mixed |
| 806 | * |
| 807 | * Return enroll box in single course |
| 808 | * |
| 809 | * @since: v.1.0.0 |
| 810 | */ |
| 811 | |
| 812 | if ( ! function_exists('tutor_course_enroll_box')) { |
| 813 | function tutor_course_enroll_box( $echo = true ) { |
| 814 | $isLoggedIn = is_user_logged_in(); |
| 815 | $enrolled = tutor_utils()->is_enrolled(); |
| 816 | |
| 817 | ob_start(); |
| 818 | |
| 819 | if ( $enrolled ) { |
| 820 | tutor_load_template( 'single.course.course-enrolled-box' ); |
| 821 | $output = apply_filters( 'tutor_course/single/enrolled', ob_get_clean() ); |
| 822 | } else { |
| 823 | tutor_load_template( 'single.course.course-enroll-box' ); |
| 824 | $output = apply_filters( 'tutor_course/single/enroll', ob_get_clean() ); |
| 825 | } |
| 826 | |
| 827 | if ( $echo ) { |
| 828 | echo $output; |
| 829 | } |
| 830 | |
| 831 | return $output; |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | function tutor_single_course_add_to_cart($echo = true){ |
| 836 | ob_start(); |
| 837 | |
| 838 | $isLoggedIn = is_user_logged_in(); |
| 839 | $output = ''; |
| 840 | |
| 841 | tutor_load_template( 'single.course.add-to-cart' ); |
| 842 | $output .= apply_filters( 'tutor_course/single/add-to-cart', ob_get_clean() ); |
| 843 | |
| 844 | if ( ! $isLoggedIn){ |
| 845 | ob_start(); |
| 846 | tutor_load_template( 'single.course.login' ); |
| 847 | $login_form = apply_filters( 'tutor_course/global/login', ob_get_clean() ); |
| 848 | |
| 849 | $output .= "<div class='tutor-cart-box-login-form' style='display: none;'><div class='tutor-cart-box-login-form-inner'><button class='tutor-popup-form-close tutor-icon-line-cross'></button>{$login_form}</div></div>"; |
| 850 | } |
| 851 | |
| 852 | if ( $echo ) { |
| 853 | echo $output; |
| 854 | } |
| 855 | |
| 856 | return $output; |
| 857 | } |
| 858 | |
| 859 | if ( ! function_exists('tutor_course_enrolled_nav')) { |
| 860 | function tutor_course_enrolled_nav($echo = true) { |
| 861 | $course_post_type = tutor()->course_post_type; |
| 862 | $lesson_post_type = tutor()->lesson_post_type; |
| 863 | |
| 864 | ob_start(); |
| 865 | global $post; |
| 866 | |
| 867 | if ( ! empty($post->post_type) && $post->post_type === $course_post_type){ |
| 868 | tutor_load_template( 'single.course.enrolled.nav' ); |
| 869 | }elseif(! empty($post->post_type) && $post->post_type === $lesson_post_type){ |
| 870 | $lesson_id = get_the_ID(); |
| 871 | $course_id = tutor_utils()->get_course_id_by_lesson($lesson_id); |
| 872 | |
| 873 | $course_post_type = tutor()->course_post_type; |
| 874 | $queryCourse = new WP_Query(array('p' => $course_id, 'post_type' => $course_post_type)); |
| 875 | |
| 876 | if ($queryCourse->have_posts()){ |
| 877 | while ($queryCourse->have_posts()){ |
| 878 | $queryCourse->the_post(); |
| 879 | tutor_load_template( 'single.course.enrolled.nav' ); |
| 880 | } |
| 881 | wp_reset_postdata(); |
| 882 | } |
| 883 | } |
| 884 | $output = apply_filters( 'tutor_course/single/enrolled/nav', ob_get_clean() ); |
| 885 | |
| 886 | if ( $echo ) { |
| 887 | echo $output; |
| 888 | } |
| 889 | return $output; |
| 890 | } |
| 891 | } |
| 892 | |
| 893 | if ( ! function_exists('tutor_course_video')){ |
| 894 | function tutor_course_video($echo = true){ |
| 895 | ob_start(); |
| 896 | tutor_load_template( 'single.video.video' ); |
| 897 | $output = apply_filters( 'tutor_course/single/video', ob_get_clean() ); |
| 898 | |
| 899 | if ( $echo ) { |
| 900 | echo $output; |
| 901 | } |
| 902 | return $output; |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | if ( ! function_exists('tutor_lesson_video')){ |
| 907 | function tutor_lesson_video($echo = true){ |
| 908 | ob_start(); |
| 909 | tutor_load_template( 'single.video.video' ); |
| 910 | $output = apply_filters( 'tutor_lesson/single/video', ob_get_clean() ); |
| 911 | |
| 912 | if ( $echo ) { |
| 913 | echo $output; |
| 914 | } |
| 915 | return $output; |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | /** |
| 920 | * |
| 921 | * Get all lessons attachments |
| 922 | * |
| 923 | * @param bool $echo |
| 924 | * |
| 925 | * @return mixed |
| 926 | * |
| 927 | * @since v.1.0.0 |
| 928 | */ |
| 929 | if ( ! function_exists('get_tutor_posts_attachments')){ |
| 930 | function get_tutor_posts_attachments($echo = true){ |
| 931 | ob_start(); |
| 932 | tutor_load_template( 'global.attachments' ); |
| 933 | $output = apply_filters( 'tutor_lesson/single/attachments', ob_get_clean() ); |
| 934 | |
| 935 | if ( $echo ) { |
| 936 | echo $output; |
| 937 | } |
| 938 | return $output; |
| 939 | } |
| 940 | } |
| 941 | |
| 942 | /** |
| 943 | * @param bool $echo |
| 944 | * |
| 945 | * @return mixed |
| 946 | * |
| 947 | * Get the lessons with topics |
| 948 | * |
| 949 | * @since v.1.0.0 |
| 950 | */ |
| 951 | if ( ! function_exists('tutor_lessons_sidebar')) { |
| 952 | function tutor_lessons_sidebar( $echo = true ) { |
| 953 | ob_start(); |
| 954 | tutor_load_template( 'single.lesson.lesson_sidebar' ); |
| 955 | $output = apply_filters( 'tutor_lesson/single/lesson_sidebar', ob_get_clean() ); |
| 956 | |
| 957 | if ( $echo ) { |
| 958 | echo $output; |
| 959 | } |
| 960 | |
| 961 | return $output; |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | /** |
| 966 | * @param bool $echo |
| 967 | * |
| 968 | * @return mixed |
| 969 | * |
| 970 | * Render Lesson Main Content |
| 971 | * @since v.1.0.0 |
| 972 | */ |
| 973 | if ( ! function_exists('tutor_lesson_content')) { |
| 974 | function tutor_lesson_content( $echo = true ) { |
| 975 | ob_start(); |
| 976 | tutor_load_template( 'single.lesson.content' ); |
| 977 | $output = apply_filters( 'tutor_lesson/single/content', ob_get_clean() ); |
| 978 | |
| 979 | if ( $echo ) { |
| 980 | echo $output; |
| 981 | } |
| 982 | |
| 983 | return $output; |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | if ( ! function_exists('tutor_lesson_mark_complete_html')) { |
| 988 | function tutor_lesson_mark_complete_html( $echo = true ) { |
| 989 | ob_start(); |
| 990 | tutor_load_template( 'single.lesson.complete_form' ); |
| 991 | $output = apply_filters( 'tutor_lesson/single/complete_form', ob_get_clean() ); |
| 992 | |
| 993 | if ( $echo ) { |
| 994 | echo $output; |
| 995 | } |
| 996 | |
| 997 | return $output; |
| 998 | } |
| 999 | } |
| 1000 | |
| 1001 | if ( ! function_exists('tutor_course_mark_complete_html')) { |
| 1002 | function tutor_course_mark_complete_html( $echo = true ) { |
| 1003 | ob_start(); |
| 1004 | tutor_load_template( 'single.course.complete_form' ); |
| 1005 | $output = apply_filters( 'tutor_course/single/complete_form', ob_get_clean() ); |
| 1006 | |
| 1007 | if ( $echo ) { |
| 1008 | echo $output; |
| 1009 | } |
| 1010 | |
| 1011 | return $output; |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | |
| 1016 | /** |
| 1017 | * @param bool $echo |
| 1018 | * |
| 1019 | * @return mixed |
| 1020 | * |
| 1021 | * @show progress bar about course complete |
| 1022 | * |
| 1023 | * @since v.1.0.0 |
| 1024 | */ |
| 1025 | |
| 1026 | if ( ! function_exists('tutor_course_completing_progress_bar')) { |
| 1027 | function tutor_course_completing_progress_bar( $echo = true ) { |
| 1028 | ob_start(); |
| 1029 | tutor_load_template( 'single.course.enrolled.completing-progress' ); |
| 1030 | $output = apply_filters( 'tutor_course/single/completing-progress-bar', ob_get_clean() ); |
| 1031 | |
| 1032 | if ( $echo ) { |
| 1033 | echo $output; |
| 1034 | } |
| 1035 | |
| 1036 | return $output; |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | function tutor_course_question_and_answer($echo = true){ |
| 1041 | ob_start(); |
| 1042 | tutor_load_template( 'single.course.enrolled.question_and_answer' ); |
| 1043 | $output = apply_filters( 'tutor_course/single/question_and_answer', ob_get_clean() ); |
| 1044 | |
| 1045 | if ( $echo ) { |
| 1046 | echo $output; |
| 1047 | } |
| 1048 | |
| 1049 | return $output; |
| 1050 | } |
| 1051 | |
| 1052 | |
| 1053 | function tutor_course_announcements($echo = true){ |
| 1054 | ob_start(); |
| 1055 | tutor_load_template( 'single.course.enrolled.announcements' ); |
| 1056 | $output = apply_filters( 'tutor_course/single/announcements', ob_get_clean() ); |
| 1057 | |
| 1058 | if ( $echo ) { |
| 1059 | echo $output; |
| 1060 | } |
| 1061 | |
| 1062 | return $output; |
| 1063 | } |
| 1064 | |
| 1065 | function tutor_single_quiz_top($echo = true){ |
| 1066 | ob_start(); |
| 1067 | tutor_load_template( 'single.quiz.top' ); |
| 1068 | $output = apply_filters( 'tutor_single_quiz/top', ob_get_clean() ); |
| 1069 | |
| 1070 | if ( $echo ) { |
| 1071 | echo $output; |
| 1072 | } |
| 1073 | return $output; |
| 1074 | } |
| 1075 | |
| 1076 | function tutor_single_quiz_body($echo = true){ |
| 1077 | ob_start(); |
| 1078 | tutor_load_template( 'single.quiz.body' ); |
| 1079 | $output = apply_filters( 'tutor_single_quiz/body', ob_get_clean() ); |
| 1080 | |
| 1081 | if ( $echo ) { |
| 1082 | echo $output; |
| 1083 | } |
| 1084 | return $output; |
| 1085 | } |
| 1086 | |
| 1087 | function tutor_single_quiz_no_course_belongs($echo = true){ |
| 1088 | ob_start(); |
| 1089 | tutor_load_template( 'single.quiz.no_course_belongs' ); |
| 1090 | $output = apply_filters( 'tutor_single_quiz/no_course_belongs', ob_get_clean() ); |
| 1091 | |
| 1092 | if ( $echo ) { |
| 1093 | echo $output; |
| 1094 | } |
| 1095 | return $output; |
| 1096 | } |
| 1097 | |
| 1098 | function single_quiz_contents($echo = true){ |
| 1099 | |
| 1100 | ob_start(); |
| 1101 | tutor_load_template( 'single.quiz.single_quiz_contents' ); |
| 1102 | $output = apply_filters( 'tutor_single_quiz/single_quiz_contents', ob_get_clean() ); |
| 1103 | |
| 1104 | if ( $echo ) { |
| 1105 | echo $output; |
| 1106 | } |
| 1107 | return $output; |
| 1108 | } |
| 1109 | |
| 1110 | function get_tutor_course_level($course_id = 0){ |
| 1111 | if ( ! $course_id){ |
| 1112 | $course_id = get_the_ID(); |
| 1113 | } |
| 1114 | if ( ! $course_id){ |
| 1115 | return ''; |
| 1116 | } |
| 1117 | |
| 1118 | $course_level = get_post_meta($course_id, '_tutor_course_level', true); |
| 1119 | |
| 1120 | if ($course_level){ |
| 1121 | return tutor_utils()->course_levels($course_level); |
| 1122 | } |
| 1123 | return false; |
| 1124 | } |
| 1125 | |
| 1126 | if ( ! function_exists('get_tutor_course_duration_context')) { |
| 1127 | function get_tutor_course_duration_context( $course_id = 0 ) { |
| 1128 | if ( ! $course_id ) { |
| 1129 | $course_id = get_the_ID(); |
| 1130 | } |
| 1131 | if ( ! $course_id ) { |
| 1132 | return ''; |
| 1133 | } |
| 1134 | $duration = get_post_meta( $course_id, '_course_duration', true ); |
| 1135 | $durationHours = tutor_utils()->avalue_dot( 'hours', $duration ); |
| 1136 | $durationMinutes = tutor_utils()->avalue_dot( 'minutes', $duration ); |
| 1137 | $durationSeconds = tutor_utils()->avalue_dot( 'seconds', $duration ); |
| 1138 | |
| 1139 | if ( $duration ) { |
| 1140 | $output = ''; |
| 1141 | if ( $durationHours > 0 ) { |
| 1142 | $output .= $durationHours . "h "; |
| 1143 | } |
| 1144 | |
| 1145 | if ( $durationMinutes > 0 ) { |
| 1146 | $output .= $durationMinutes . "m "; |
| 1147 | } |
| 1148 | |
| 1149 | if ( $durationSeconds > 0 ) { |
| 1150 | $output .= $durationSeconds ."s "; |
| 1151 | } |
| 1152 | |
| 1153 | return $output; |
| 1154 | } |
| 1155 | |
| 1156 | return false; |
| 1157 | } |
| 1158 | } |
| 1159 | if ( ! function_exists('get_tutor_course_categories')){ |
| 1160 | function get_tutor_course_categories($course_id = 0){ |
| 1161 | if ( ! $course_id ) { |
| 1162 | $course_id = get_the_ID(); |
| 1163 | } |
| 1164 | $terms = get_the_terms( $course_id, 'course-category' ); |
| 1165 | |
| 1166 | return $terms; |
| 1167 | } |
| 1168 | } |
| 1169 | if ( ! function_exists('get_tutor_course_tags')){ |
| 1170 | function get_tutor_course_tags($course_id = 0){ |
| 1171 | if ( ! $course_id ) { |
| 1172 | $course_id = get_the_ID(); |
| 1173 | } |
| 1174 | $terms = get_the_terms( $course_id, 'course-tag' ); |
| 1175 | |
| 1176 | return $terms; |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | if ( ! function_exists('tutor_course_tags_html')) { |
| 1181 | function tutor_course_tags_html( $echo = true ) { |
| 1182 | ob_start(); |
| 1183 | tutor_load_template( 'single.course.tags' ); |
| 1184 | $output = apply_filters( 'tutor_course/single/tags_html', ob_get_clean() ); |
| 1185 | |
| 1186 | if ( $echo ) { |
| 1187 | echo $output; |
| 1188 | } |
| 1189 | |
| 1190 | return $output; |
| 1191 | } |
| 1192 | } |
| 1193 | |
| 1194 | if ( ! function_exists('tutor_lesson_sidebar_question_and_answer')) { |
| 1195 | function tutor_lesson_sidebar_question_and_answer( $echo = true ) { |
| 1196 | ob_start(); |
| 1197 | tutor_load_template( 'single.lesson.sidebar_question_and_answer' ); |
| 1198 | $output = apply_filters( 'tutor_lesson/single/sidebar_question_and_answer', ob_get_clean() ); |
| 1199 | |
| 1200 | if ( $echo ) { |
| 1201 | echo $output; |
| 1202 | } |
| 1203 | |
| 1204 | return $output; |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | if ( ! function_exists('tutor_social_share')) { |
| 1209 | function tutor_social_share( $echo = true ) { |
| 1210 | ob_start(); |
| 1211 | tutor_load_template( 'single.course.social_share' ); |
| 1212 | $output = apply_filters( 'tutor_course/single/social_share', ob_get_clean() ); |
| 1213 | |
| 1214 | if ( $echo ) { |
| 1215 | echo $output; |
| 1216 | } |
| 1217 | |
| 1218 | return $output; |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 |