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