theme-compatibility
6 years ago
tutor-general-functions.php
6 years ago
tutor-template-functions.php
6 years ago
tutor-template-hook.php
6 years ago
tutor-template-functions.php
1478 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 | $courseCols = tutor_utils()->get_option( 'courses_col_per_row', 4 ); |
| 317 | $classes = apply_filters( 'tutor_course_loop_col_classes', array( |
| 318 | 'tutor-course-col-' . $courseCols, |
| 319 | ) ); |
| 320 | |
| 321 | $class = implode( ' ', $classes ); |
| 322 | if ( $echo ) { |
| 323 | echo $class; |
| 324 | } |
| 325 | |
| 326 | return $class; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | |
| 331 | if ( ! function_exists('tutor_container_classes')) { |
| 332 | function tutor_container_classes( $echo = true ) { |
| 333 | |
| 334 | $classes = apply_filters( 'tutor_container_classes', array( |
| 335 | 'tutor-wrap tutor-courses-wrap', |
| 336 | 'tutor-container' |
| 337 | ) ); |
| 338 | |
| 339 | $class = implode( ' ', $classes ); |
| 340 | |
| 341 | if ( $echo ) { |
| 342 | echo $class; |
| 343 | } |
| 344 | |
| 345 | return $class; |
| 346 | } |
| 347 | } |
| 348 | if ( ! function_exists('tutor_post_class')) { |
| 349 | function tutor_post_class($default = '') { |
| 350 | $classes = apply_filters( 'tutor_post_class', array( |
| 351 | 'tutor-wrap', |
| 352 | $default |
| 353 | ) ); |
| 354 | |
| 355 | post_class( $classes ); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | if ( ! function_exists('tutor_course_archive_filter_bar')) { |
| 360 | function tutor_course_archive_filter_bar() { |
| 361 | ob_start(); |
| 362 | tutor_load_template( 'global.course-archive-filter-bar' ); |
| 363 | $output = apply_filters( 'tutor_course_archive_filter_bar', ob_get_clean() ); |
| 364 | |
| 365 | echo $output; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * |
| 371 | * Get classes for widget loop single course wrap |
| 372 | * |
| 373 | * @param bool $echo |
| 374 | * |
| 375 | * @return string |
| 376 | * |
| 377 | * @since v.1.3.1 |
| 378 | */ |
| 379 | if( ! function_exists('tutor_widget_course_loop_classes')) { |
| 380 | function tutor_widget_course_loop_classes( $echo = true ) { |
| 381 | |
| 382 | $classes = apply_filters( 'tutor_widget_course_loop_classes', array( |
| 383 | 'tutor-widget-course-loop', |
| 384 | 'tutor-widget-course', |
| 385 | 'tutor-widget-course-'.get_the_ID(), |
| 386 | ) ); |
| 387 | |
| 388 | $class = implode( ' ', $classes ); |
| 389 | if ( $echo ) { |
| 390 | echo $class; |
| 391 | } |
| 392 | |
| 393 | return $class; |
| 394 | } |
| 395 | } |
| 396 | |
| 397 | /** |
| 398 | * Get the post thumbnail |
| 399 | */ |
| 400 | if ( ! function_exists('get_tutor_course_thumbnail')) { |
| 401 | function get_tutor_course_thumbnail($size = 'post-thumbnail', $url = false) { |
| 402 | $post_id = get_the_ID(); |
| 403 | $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id ); |
| 404 | |
| 405 | if ( $post_thumbnail_id ) { |
| 406 | //$size = apply_filters( 'post_thumbnail_size', $size, $post_id ); |
| 407 | $size = apply_filters( 'tutor_course_thumbnail_size', $size, $post_id ); |
| 408 | if ($url){ |
| 409 | return wp_get_attachment_image_url($post_thumbnail_id, $size); |
| 410 | } |
| 411 | |
| 412 | $html = wp_get_attachment_image( $post_thumbnail_id, $size, false ); |
| 413 | } else { |
| 414 | $placeHolderUrl = tutor()->url . 'assets/images/placeholder.jpg'; |
| 415 | if ($url){ |
| 416 | return $placeHolderUrl; |
| 417 | } |
| 418 | $html = sprintf('<img alt="%s" src="' . $placeHolderUrl . '" />', __('Placeholder', 'tutor')); |
| 419 | } |
| 420 | |
| 421 | echo $html; |
| 422 | } |
| 423 | } |
| 424 | /** |
| 425 | * Get the course/post thumbnail src |
| 426 | */ |
| 427 | if ( ! function_exists('get_tutor_course_thumbnail_src')) { |
| 428 | function get_tutor_course_thumbnail_src($size = 'post-thumbnail') { |
| 429 | $post_id = get_the_ID(); |
| 430 | $post_thumbnail_id = (int) get_post_thumbnail_id( $post_id ); |
| 431 | |
| 432 | if ( $post_thumbnail_id ) { |
| 433 | $size = apply_filters( 'tutor_course_thumbnail_size', $size, $post_id ); |
| 434 | $src = wp_get_attachment_image_url( $post_thumbnail_id, $size, false ); |
| 435 | } else { |
| 436 | $src = tutor()->url . 'assets/images/placeholder.jpg'; |
| 437 | } |
| 438 | |
| 439 | return $src; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | if ( ! function_exists('tutor_course_loop_meta')) { |
| 444 | function tutor_course_loop_meta() { |
| 445 | ob_start(); |
| 446 | tutor_load_template( 'loop.meta' ); |
| 447 | $output = apply_filters( 'tutor_course_loop_meta', ob_get_clean() ); |
| 448 | |
| 449 | echo $output; |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Get course author name in loop |
| 455 | * |
| 456 | * @since: v.1.0.0 |
| 457 | */ |
| 458 | |
| 459 | if ( ! function_exists('tutor_course_loop_author')) { |
| 460 | function tutor_course_loop_author() { |
| 461 | ob_start(); |
| 462 | tutor_load_template( 'loop.course-author' ); |
| 463 | $output = apply_filters( 'tutor_course_loop_author', ob_get_clean() ); |
| 464 | |
| 465 | echo $output; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | /** |
| 470 | * Get formatted price with cart form |
| 471 | */ |
| 472 | |
| 473 | if ( ! function_exists('tutor_course_loop_price')) { |
| 474 | function tutor_course_loop_price() { |
| 475 | ob_start(); |
| 476 | |
| 477 | $tutor_course_sell_by = apply_filters('tutor_course_sell_by', null); |
| 478 | if ($tutor_course_sell_by){ |
| 479 | tutor_load_template( 'loop.course-price-'.$tutor_course_sell_by ); |
| 480 | }else{ |
| 481 | tutor_load_template( 'loop.course-price' ); |
| 482 | } |
| 483 | $output = apply_filters( 'tutor_course_loop_price', ob_get_clean() ); |
| 484 | |
| 485 | echo $output; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | /** |
| 490 | * Get Course rating |
| 491 | * |
| 492 | * @since v.1.0.0 |
| 493 | * @updated v.1.4.5 |
| 494 | */ |
| 495 | |
| 496 | if ( ! function_exists('tutor_course_loop_rating')) { |
| 497 | function tutor_course_loop_rating() { |
| 498 | |
| 499 | $disable = get_tutor_option('disable_course_review'); |
| 500 | if ($disable){ |
| 501 | return; |
| 502 | } |
| 503 | |
| 504 | ob_start(); |
| 505 | tutor_load_template( 'loop.rating' ); |
| 506 | $output = apply_filters( 'tutor_course_loop_rating', ob_get_clean() ); |
| 507 | |
| 508 | echo $output; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | /** |
| 513 | * @param bool $echo |
| 514 | * |
| 515 | * @return mixed|void |
| 516 | * |
| 517 | * Get add to cart form |
| 518 | */ |
| 519 | |
| 520 | if ( ! function_exists('tutor_course_loop_add_to_cart')) { |
| 521 | function tutor_course_loop_add_to_cart($echo = true) { |
| 522 | ob_start(); |
| 523 | $tutor_course_sell_by = apply_filters('tutor_course_sell_by', null); |
| 524 | |
| 525 | if ($tutor_course_sell_by){ |
| 526 | tutor_load_template( 'loop.add-to-cart-'.$tutor_course_sell_by ); |
| 527 | } |
| 528 | |
| 529 | $output = apply_filters( 'tutor_course_loop_add_to_cart_link', ob_get_clean() ); |
| 530 | |
| 531 | if ($echo){ |
| 532 | echo $output; |
| 533 | } |
| 534 | return $output; |
| 535 | } |
| 536 | } |
| 537 | |
| 538 | if ( ! function_exists('tutor_course_price')) { |
| 539 | function tutor_course_price() { |
| 540 | ob_start(); |
| 541 | tutor_load_template( 'single.course.wc-price-html' ); |
| 542 | $output = apply_filters( 'tutor_course_price', ob_get_clean() ); |
| 543 | |
| 544 | echo $output; |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | /** |
| 549 | * @param int $post_id |
| 550 | * |
| 551 | * echo the excerpt of TUTOR post type |
| 552 | * |
| 553 | * @since: v.1.0.0 |
| 554 | */ |
| 555 | if ( ! function_exists('tutor_the_excerpt')) { |
| 556 | function tutor_the_excerpt( $post_id = 0 ) { |
| 557 | if ( ! $post_id ) { |
| 558 | $post_id = get_the_ID(); |
| 559 | } |
| 560 | echo tutor_get_the_excerpt( $post_id ); |
| 561 | } |
| 562 | } |
| 563 | /** |
| 564 | * @param int $post_id |
| 565 | * |
| 566 | * @return mixed |
| 567 | * |
| 568 | * Return excerpt of TUTOR post type |
| 569 | * |
| 570 | * @since: v.1.0.0 |
| 571 | */ |
| 572 | if ( ! function_exists('tutor_get_the_excerpt')) { |
| 573 | function tutor_get_the_excerpt( $post_id = 0 ) { |
| 574 | if ( ! $post_id ) { |
| 575 | $post_id = get_the_ID(); |
| 576 | } |
| 577 | |
| 578 | $get_post = get_post($post_id); |
| 579 | return apply_filters( 'tutor_get_the_excerpt', $get_post->post_excerpt ); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | /** |
| 584 | * @return mixed |
| 585 | * |
| 586 | * return course author |
| 587 | * |
| 588 | * @since: v.1.0.0 |
| 589 | */ |
| 590 | |
| 591 | if ( ! function_exists('get_tutor_course_author')) { |
| 592 | function get_tutor_course_author() { |
| 593 | global $post; |
| 594 | return apply_filters( 'get_tutor_course_author', get_the_author_meta( 'display_name', $post->post_author ) ); |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | function get_tutor_course_author_id(){ |
| 599 | global $post; |
| 600 | return (int) $post->post_author; |
| 601 | } |
| 602 | |
| 603 | /** |
| 604 | * @param int $course_id |
| 605 | * |
| 606 | * @return mixed |
| 607 | * Course benefits return array |
| 608 | * |
| 609 | * @since: v.1.0.0 |
| 610 | */ |
| 611 | |
| 612 | if ( ! function_exists('tutor_course_benefits')) { |
| 613 | function tutor_course_benefits( $course_id = 0 ) { |
| 614 | if ( ! $course_id ) { |
| 615 | $course_id = get_the_ID(); |
| 616 | } |
| 617 | $benefits = get_post_meta( $course_id, '_tutor_course_benefits', true ); |
| 618 | |
| 619 | $benefits_array = array(); |
| 620 | if ($benefits){ |
| 621 | $benefits_array = explode("\n", $benefits); |
| 622 | } |
| 623 | |
| 624 | $array = array_filter(array_map('trim', $benefits_array)); |
| 625 | |
| 626 | return apply_filters( 'tutor_course/single/benefits', $array, $course_id ); |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * @param bool $echo |
| 632 | * |
| 633 | * @return mixed |
| 634 | * |
| 635 | * Course single page benefits |
| 636 | * |
| 637 | * @since: v.1.0.0 |
| 638 | */ |
| 639 | |
| 640 | if ( ! function_exists('tutor_course_benefits_html')) { |
| 641 | function tutor_course_benefits_html($echo = true) { |
| 642 | ob_start(); |
| 643 | tutor_load_template( 'single.course.course-benefits' ); |
| 644 | $output = apply_filters( 'tutor_course/single/benefits_html', ob_get_clean() ); |
| 645 | |
| 646 | if ($echo){ |
| 647 | echo $output; |
| 648 | } |
| 649 | return $output; |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * @param bool $echo |
| 655 | * |
| 656 | * @return mixed|void |
| 657 | * |
| 658 | * Return Topics HTML |
| 659 | * |
| 660 | * @since: v.1.0.0 |
| 661 | */ |
| 662 | if ( ! function_exists('tutor_course_topics')) { |
| 663 | function tutor_course_topics( $echo = true ) { |
| 664 | ob_start(); |
| 665 | tutor_load_template( 'single.course.course-topics' ); |
| 666 | $output = apply_filters( 'tutor_course/single/topics', ob_get_clean() ); |
| 667 | wp_reset_postdata(); |
| 668 | |
| 669 | if ( $echo ) { |
| 670 | echo $output; |
| 671 | } |
| 672 | |
| 673 | return $output; |
| 674 | } |
| 675 | } |
| 676 | |
| 677 | /** |
| 678 | * @param int $course_id |
| 679 | * |
| 680 | * @return mixed|void |
| 681 | * |
| 682 | * return course requirements in array |
| 683 | * |
| 684 | * @since: v.1.0.0 |
| 685 | */ |
| 686 | if ( ! function_exists('tutor_course_requirements')) { |
| 687 | function tutor_course_requirements( $course_id = 0 ) { |
| 688 | if ( ! $course_id ) { |
| 689 | $course_id = get_the_ID(); |
| 690 | } |
| 691 | $requirements = get_post_meta( $course_id, '_tutor_course_requirements', true ); |
| 692 | |
| 693 | $requirements_array = array(); |
| 694 | if ($requirements){ |
| 695 | $requirements_array = explode("\n", $requirements); |
| 696 | } |
| 697 | |
| 698 | $array = array_filter(array_map('trim', $requirements_array)); |
| 699 | return apply_filters( 'tutor_course/single/requirements', $array, $course_id ); |
| 700 | } |
| 701 | } |
| 702 | |
| 703 | /** |
| 704 | * @param bool $echo |
| 705 | * |
| 706 | * @return mixed|void |
| 707 | * |
| 708 | * Return course requirements in course single page |
| 709 | * |
| 710 | * @since: v.1.0.0 |
| 711 | */ |
| 712 | if ( ! function_exists('tutor_course_requirements_html')) { |
| 713 | function tutor_course_requirements_html($echo = true) { |
| 714 | ob_start(); |
| 715 | tutor_load_template( 'single.course.course-requirements' ); |
| 716 | $output = apply_filters( 'tutor_course/single/requirements_html', ob_get_clean() ); |
| 717 | |
| 718 | if ($echo){ |
| 719 | echo $output; |
| 720 | } |
| 721 | return $output; |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | |
| 726 | /** |
| 727 | * @param int $course_id |
| 728 | * |
| 729 | * @return mixed|void |
| 730 | * |
| 731 | * Return target audience in course single page |
| 732 | * |
| 733 | * @since: v.1.0.0 |
| 734 | */ |
| 735 | if ( ! function_exists('tutor_course_target_audience')) { |
| 736 | function tutor_course_target_audience( $course_id = 0 ) { |
| 737 | if ( ! $course_id ) { |
| 738 | $course_id = get_the_ID(); |
| 739 | } |
| 740 | $target_audience = get_post_meta( $course_id, '_tutor_course_target_audience', true ); |
| 741 | |
| 742 | $target_audience_array = array(); |
| 743 | if ($target_audience){ |
| 744 | $target_audience_array = explode("\n", $target_audience); |
| 745 | } |
| 746 | |
| 747 | $array = array_filter(array_map('trim', $target_audience_array)); |
| 748 | return apply_filters( 'tutor_course/single/target_audience', $array, $course_id ); |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | /** |
| 753 | * @param bool $echo |
| 754 | * |
| 755 | * @return mixed|void |
| 756 | * |
| 757 | * Return target audience in course single page |
| 758 | * |
| 759 | * @since: v.1.0.0 |
| 760 | */ |
| 761 | if ( ! function_exists('tutor_course_target_audience_html')) { |
| 762 | function tutor_course_target_audience_html($echo = true) { |
| 763 | ob_start(); |
| 764 | tutor_load_template( 'single.course.course-target-audience' ); |
| 765 | $output = apply_filters( 'tutor_course/single/audience_html', ob_get_clean() ); |
| 766 | |
| 767 | if ($echo){ |
| 768 | echo $output; |
| 769 | } |
| 770 | return $output; |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | |
| 775 | if ( ! function_exists('tutor_course_material_includes')) { |
| 776 | function tutor_course_material_includes( $course_id = 0 ) { |
| 777 | if ( ! $course_id ) { |
| 778 | $course_id = get_the_ID(); |
| 779 | } |
| 780 | $target_audience = get_post_meta( $course_id, '_tutor_course_material_includes', true ); |
| 781 | |
| 782 | $target_audience_array = array(); |
| 783 | if ($target_audience){ |
| 784 | $target_audience_array = explode("\n", $target_audience); |
| 785 | } |
| 786 | |
| 787 | $array = array_filter(array_map('trim', $target_audience_array)); |
| 788 | return apply_filters( 'tutor_course/single/material_includes', $array, $course_id ); |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | if ( ! function_exists('tutor_course_material_includes_html')) { |
| 793 | function tutor_course_material_includes_html($echo = true) { |
| 794 | ob_start(); |
| 795 | tutor_load_template( 'single.course.material-includes' ); |
| 796 | $output = apply_filters( 'tutor_course/single/material_includes', ob_get_clean() ); |
| 797 | |
| 798 | if ($echo){ |
| 799 | echo $output; |
| 800 | } |
| 801 | return $output; |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | //tutor_course_material_includes_html |
| 806 | |
| 807 | |
| 808 | if ( ! function_exists('tutor_course_instructors_html')) { |
| 809 | function tutor_course_instructors_html($echo = true) { |
| 810 | $display_course_instructors = tutor_utils()->get_option('display_course_instructors'); |
| 811 | if ( ! $display_course_instructors){ |
| 812 | return null; |
| 813 | } |
| 814 | |
| 815 | ob_start(); |
| 816 | tutor_load_template( 'single.course.instructors' ); |
| 817 | $output = apply_filters( 'tutor_course/single/instructors_html', ob_get_clean() ); |
| 818 | |
| 819 | if ($echo){ |
| 820 | echo $output; |
| 821 | } |
| 822 | return $output; |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | if ( ! function_exists('tutor_course_target_reviews_html')) { |
| 827 | function tutor_course_target_reviews_html($echo = true) { |
| 828 | ob_start(); |
| 829 | tutor_load_template( 'single.course.reviews' ); |
| 830 | $output = apply_filters( 'tutor_course/single/reviews_html', ob_get_clean() ); |
| 831 | |
| 832 | if ($echo){ |
| 833 | echo $output; |
| 834 | } |
| 835 | return $output; |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | if ( ! function_exists('tutor_course_target_review_form_html')) { |
| 840 | function tutor_course_target_review_form_html($echo = true) { |
| 841 | ob_start(); |
| 842 | tutor_load_template( 'single.course.review-form' ); |
| 843 | $output = apply_filters( 'tutor_course/single/reviews_form', ob_get_clean() ); |
| 844 | |
| 845 | if ($echo){ |
| 846 | echo $output; |
| 847 | } |
| 848 | |
| 849 | return $output; |
| 850 | |
| 851 | } |
| 852 | } |
| 853 | |
| 854 | /** |
| 855 | * @param bool $echo |
| 856 | * |
| 857 | * @return mixed |
| 858 | * |
| 859 | * Course single page main content / description |
| 860 | * |
| 861 | * @since: v.1.0.0 |
| 862 | */ |
| 863 | if ( ! function_exists('tutor_course_content')) { |
| 864 | function tutor_course_content( $echo = true ) { |
| 865 | ob_start(); |
| 866 | tutor_load_template( 'single.course.course-content' ); |
| 867 | $output = apply_filters( 'tutor_course/single/content', ob_get_clean() ); |
| 868 | |
| 869 | if ( $echo ) { |
| 870 | echo $output; |
| 871 | } |
| 872 | |
| 873 | return $output; |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | /** |
| 878 | * Course single page lead info |
| 879 | * |
| 880 | * @since: v.1.0.0 |
| 881 | */ |
| 882 | if ( ! function_exists('tutor_course_lead_info')) { |
| 883 | function tutor_course_lead_info( $echo = true ) { |
| 884 | ob_start(); |
| 885 | |
| 886 | $course_id = get_the_ID(); |
| 887 | $course_post_type = tutor()->course_post_type; |
| 888 | $queryCourse = new WP_Query(array('p' => $course_id, 'post_type' => $course_post_type)); |
| 889 | |
| 890 | if ($queryCourse->have_posts()){ |
| 891 | while ($queryCourse->have_posts()){ |
| 892 | $queryCourse->the_post(); |
| 893 | tutor_load_template( 'single.course.lead-info' ); |
| 894 | } |
| 895 | wp_reset_postdata(); |
| 896 | } |
| 897 | |
| 898 | $output = apply_filters( 'tutor_course/single/lead_info', ob_get_clean() ); |
| 899 | |
| 900 | if ( $echo ) { |
| 901 | echo $output; |
| 902 | } |
| 903 | return $output; |
| 904 | } |
| 905 | } |
| 906 | |
| 907 | /** |
| 908 | * @param bool $echo |
| 909 | * |
| 910 | * @return mixed|void |
| 911 | */ |
| 912 | |
| 913 | if ( ! function_exists('tutor_course_enrolled_lead_info')) { |
| 914 | function tutor_course_enrolled_lead_info( $echo = true ) { |
| 915 | ob_start(); |
| 916 | |
| 917 | $course_id = get_the_ID(); |
| 918 | $course_post_type = tutor()->course_post_type; |
| 919 | $queryCourse = new WP_Query( array( 'p' => $course_id, 'post_type' => $course_post_type ) ); |
| 920 | |
| 921 | if ( $queryCourse->have_posts() ) { |
| 922 | while ( $queryCourse->have_posts() ) { |
| 923 | $queryCourse->the_post(); |
| 924 | tutor_load_template( 'single.course.enrolled.lead-info' ); |
| 925 | } |
| 926 | wp_reset_postdata(); |
| 927 | } |
| 928 | |
| 929 | $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() ); |
| 930 | |
| 931 | if ( $echo ) { |
| 932 | echo $output; |
| 933 | } |
| 934 | |
| 935 | return $output; |
| 936 | } |
| 937 | } |
| 938 | |
| 939 | if ( ! function_exists('tutor_lesson_lead_info')) { |
| 940 | function tutor_lesson_lead_info( $lesson_id = 0, $echo = true ) { |
| 941 | if ( ! $lesson_id ) { |
| 942 | $lesson_id = get_the_ID(); |
| 943 | } |
| 944 | |
| 945 | ob_start(); |
| 946 | $course_id = tutor_utils()->get_course_id_by_lesson( $lesson_id ); |
| 947 | $course_post_type = tutor()->course_post_type; |
| 948 | $queryCourse = new WP_Query( array( 'p' => $course_id, 'post_type' => $course_post_type ) ); |
| 949 | |
| 950 | if ( $queryCourse->have_posts() ) { |
| 951 | while ( $queryCourse->have_posts() ) { |
| 952 | $queryCourse->the_post(); |
| 953 | tutor_load_template( 'single.course.enrolled.lead-info' ); |
| 954 | } |
| 955 | wp_reset_postdata(); |
| 956 | } |
| 957 | $output = apply_filters( 'tutor_course/single/enrolled/lead_info', ob_get_clean() ); |
| 958 | |
| 959 | if ( $echo ) { |
| 960 | echo $output; |
| 961 | } |
| 962 | |
| 963 | return $output; |
| 964 | |
| 965 | } |
| 966 | } |
| 967 | /** |
| 968 | * @param bool $echo |
| 969 | * |
| 970 | * @return mixed |
| 971 | * |
| 972 | * Return enroll box in single course |
| 973 | * |
| 974 | * @since: v.1.0.0 |
| 975 | */ |
| 976 | |
| 977 | if ( ! function_exists('tutor_course_enroll_box')) { |
| 978 | function tutor_course_enroll_box( $echo = true ) { |
| 979 | $isLoggedIn = is_user_logged_in(); |
| 980 | $enrolled = tutor_utils()->is_enrolled(); |
| 981 | |
| 982 | ob_start(); |
| 983 | |
| 984 | if ( $enrolled ) { |
| 985 | tutor_load_template( 'single.course.course-enrolled-box' ); |
| 986 | $output = apply_filters( 'tutor_course/single/enrolled', ob_get_clean() ); |
| 987 | } else { |
| 988 | tutor_load_template( 'single.course.course-enroll-box' ); |
| 989 | $output = apply_filters( 'tutor_course/single/enroll', ob_get_clean() ); |
| 990 | } |
| 991 | |
| 992 | if ( $echo ) { |
| 993 | echo $output; |
| 994 | } |
| 995 | |
| 996 | return $output; |
| 997 | } |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * @param bool $echo |
| 1002 | * |
| 1003 | * @return string |
| 1004 | * |
| 1005 | * Get Only add to cart form |
| 1006 | */ |
| 1007 | |
| 1008 | function tutor_single_course_add_to_cart($echo = true){ |
| 1009 | ob_start(); |
| 1010 | |
| 1011 | $isLoggedIn = is_user_logged_in(); |
| 1012 | $output = ''; |
| 1013 | |
| 1014 | tutor_load_template( 'single.course.add-to-cart' ); |
| 1015 | $output .= apply_filters( 'tutor_course/single/add-to-cart', ob_get_clean() ); |
| 1016 | |
| 1017 | if ( ! $isLoggedIn){ |
| 1018 | ob_start(); |
| 1019 | tutor_load_template( 'single.course.login' ); |
| 1020 | $login_form = apply_filters( 'tutor_course/global/login', ob_get_clean() ); |
| 1021 | |
| 1022 | $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>"; |
| 1023 | } |
| 1024 | |
| 1025 | if ( $echo ) { |
| 1026 | echo $output; |
| 1027 | } |
| 1028 | |
| 1029 | return $output; |
| 1030 | } |
| 1031 | |
| 1032 | if ( ! function_exists('tutor_course_enrolled_nav')) { |
| 1033 | function tutor_course_enrolled_nav($echo = true) { |
| 1034 | $course_post_type = tutor()->course_post_type; |
| 1035 | $lesson_post_type = tutor()->lesson_post_type; |
| 1036 | |
| 1037 | ob_start(); |
| 1038 | global $post; |
| 1039 | |
| 1040 | if ( ! empty($post->post_type) && $post->post_type === $course_post_type){ |
| 1041 | tutor_load_template( 'single.course.enrolled.nav' ); |
| 1042 | }elseif(! empty($post->post_type) && $post->post_type === $lesson_post_type){ |
| 1043 | $lesson_id = get_the_ID(); |
| 1044 | $course_id = tutor_utils()->get_course_id_by_lesson($lesson_id); |
| 1045 | |
| 1046 | $course_post_type = tutor()->course_post_type; |
| 1047 | $queryCourse = new WP_Query(array('p' => $course_id, 'post_type' => $course_post_type)); |
| 1048 | |
| 1049 | if ($queryCourse->have_posts()){ |
| 1050 | while ($queryCourse->have_posts()){ |
| 1051 | $queryCourse->the_post(); |
| 1052 | tutor_load_template( 'single.course.enrolled.nav' ); |
| 1053 | } |
| 1054 | wp_reset_postdata(); |
| 1055 | } |
| 1056 | } |
| 1057 | $output = apply_filters( 'tutor_course/single/enrolled/nav', ob_get_clean() ); |
| 1058 | |
| 1059 | if ( $echo ) { |
| 1060 | echo $output; |
| 1061 | } |
| 1062 | return $output; |
| 1063 | } |
| 1064 | } |
| 1065 | |
| 1066 | if ( ! function_exists('tutor_course_video')){ |
| 1067 | function tutor_course_video($echo = true){ |
| 1068 | ob_start(); |
| 1069 | tutor_load_template( 'single.video.video' ); |
| 1070 | $output = apply_filters( 'tutor_course/single/video', ob_get_clean() ); |
| 1071 | |
| 1072 | if ( $echo ) { |
| 1073 | echo $output; |
| 1074 | } |
| 1075 | return $output; |
| 1076 | } |
| 1077 | } |
| 1078 | |
| 1079 | if ( ! function_exists('tutor_lesson_video')){ |
| 1080 | function tutor_lesson_video($echo = true){ |
| 1081 | ob_start(); |
| 1082 | tutor_load_template( 'single.video.video' ); |
| 1083 | $output = apply_filters( 'tutor_lesson/single/video', ob_get_clean() ); |
| 1084 | |
| 1085 | if ( $echo ) { |
| 1086 | echo $output; |
| 1087 | } |
| 1088 | return $output; |
| 1089 | } |
| 1090 | } |
| 1091 | |
| 1092 | /** |
| 1093 | * |
| 1094 | * Get all lessons attachments |
| 1095 | * |
| 1096 | * @param bool $echo |
| 1097 | * |
| 1098 | * @return mixed |
| 1099 | * |
| 1100 | * @since v.1.0.0 |
| 1101 | */ |
| 1102 | if ( ! function_exists('get_tutor_posts_attachments')){ |
| 1103 | function get_tutor_posts_attachments($echo = true){ |
| 1104 | ob_start(); |
| 1105 | tutor_load_template( 'global.attachments' ); |
| 1106 | $output = apply_filters( 'tutor_lesson/single/attachments', ob_get_clean() ); |
| 1107 | |
| 1108 | if ( $echo ) { |
| 1109 | echo $output; |
| 1110 | } |
| 1111 | return $output; |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | /** |
| 1116 | * @param bool $echo |
| 1117 | * |
| 1118 | * @return mixed |
| 1119 | * |
| 1120 | * Get the lessons with topics |
| 1121 | * |
| 1122 | * @since v.1.0.0 |
| 1123 | */ |
| 1124 | if ( ! function_exists('tutor_lessons_sidebar')) { |
| 1125 | function tutor_lessons_sidebar( $echo = true ) { |
| 1126 | ob_start(); |
| 1127 | tutor_load_template( 'single.lesson.lesson_sidebar' ); |
| 1128 | $output = apply_filters( 'tutor_lesson/single/lesson_sidebar', ob_get_clean() ); |
| 1129 | |
| 1130 | if ( $echo ) { |
| 1131 | echo $output; |
| 1132 | } |
| 1133 | |
| 1134 | return $output; |
| 1135 | } |
| 1136 | } |
| 1137 | |
| 1138 | /** |
| 1139 | * @param bool $echo |
| 1140 | * |
| 1141 | * @return mixed |
| 1142 | * |
| 1143 | * Render Lesson Main Content |
| 1144 | * @since v.1.0.0 |
| 1145 | */ |
| 1146 | if ( ! function_exists('tutor_lesson_content')) { |
| 1147 | function tutor_lesson_content( $echo = true ) { |
| 1148 | ob_start(); |
| 1149 | tutor_load_template( 'single.lesson.content' ); |
| 1150 | $output = apply_filters( 'tutor_lesson/single/content', ob_get_clean() ); |
| 1151 | |
| 1152 | if ( $echo ) { |
| 1153 | echo $output; |
| 1154 | } |
| 1155 | |
| 1156 | return $output; |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | if ( ! function_exists('tutor_lesson_mark_complete_html')) { |
| 1161 | function tutor_lesson_mark_complete_html( $echo = true ) { |
| 1162 | ob_start(); |
| 1163 | tutor_load_template( 'single.lesson.complete_form' ); |
| 1164 | $output = apply_filters( 'tutor_lesson/single/complete_form', ob_get_clean() ); |
| 1165 | |
| 1166 | if ( $echo ) { |
| 1167 | echo $output; |
| 1168 | } |
| 1169 | |
| 1170 | return $output; |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | if ( ! function_exists('tutor_course_mark_complete_html')) { |
| 1175 | function tutor_course_mark_complete_html( $echo = true ) { |
| 1176 | ob_start(); |
| 1177 | tutor_load_template( 'single.course.complete_form' ); |
| 1178 | $output = apply_filters( 'tutor_course/single/complete_form', ob_get_clean() ); |
| 1179 | |
| 1180 | if ( $echo ) { |
| 1181 | echo $output; |
| 1182 | } |
| 1183 | |
| 1184 | return $output; |
| 1185 | } |
| 1186 | } |
| 1187 | |
| 1188 | |
| 1189 | /** |
| 1190 | * @param bool $echo |
| 1191 | * |
| 1192 | * @return mixed |
| 1193 | * |
| 1194 | * @show progress bar about course complete |
| 1195 | * |
| 1196 | * @since v.1.0.0 |
| 1197 | */ |
| 1198 | |
| 1199 | if ( ! function_exists('tutor_course_completing_progress_bar')) { |
| 1200 | function tutor_course_completing_progress_bar( $echo = true ) { |
| 1201 | ob_start(); |
| 1202 | tutor_load_template( 'single.course.enrolled.completing-progress' ); |
| 1203 | $output = apply_filters( 'tutor_course/single/completing-progress-bar', ob_get_clean() ); |
| 1204 | |
| 1205 | if ( $echo ) { |
| 1206 | echo $output; |
| 1207 | } |
| 1208 | |
| 1209 | return $output; |
| 1210 | } |
| 1211 | } |
| 1212 | |
| 1213 | function tutor_course_question_and_answer($echo = true){ |
| 1214 | ob_start(); |
| 1215 | tutor_load_template( 'single.course.enrolled.question_and_answer' ); |
| 1216 | $output = apply_filters( 'tutor_course/single/question_and_answer', ob_get_clean() ); |
| 1217 | |
| 1218 | if ( $echo ) { |
| 1219 | echo $output; |
| 1220 | } |
| 1221 | |
| 1222 | return $output; |
| 1223 | } |
| 1224 | |
| 1225 | |
| 1226 | function tutor_course_announcements($echo = true){ |
| 1227 | ob_start(); |
| 1228 | tutor_load_template( 'single.course.enrolled.announcements' ); |
| 1229 | $output = apply_filters( 'tutor_course/single/announcements', ob_get_clean() ); |
| 1230 | |
| 1231 | if ( $echo ) { |
| 1232 | echo $output; |
| 1233 | } |
| 1234 | |
| 1235 | return $output; |
| 1236 | } |
| 1237 | |
| 1238 | function tutor_single_quiz_top($echo = true){ |
| 1239 | ob_start(); |
| 1240 | tutor_load_template( 'single.quiz.top' ); |
| 1241 | $output = apply_filters( 'tutor_single_quiz/top', ob_get_clean() ); |
| 1242 | |
| 1243 | if ( $echo ) { |
| 1244 | echo $output; |
| 1245 | } |
| 1246 | return $output; |
| 1247 | } |
| 1248 | |
| 1249 | function tutor_single_quiz_body($echo = true){ |
| 1250 | ob_start(); |
| 1251 | tutor_load_template( 'single.quiz.body' ); |
| 1252 | $output = apply_filters( 'tutor_single_quiz/body', ob_get_clean() ); |
| 1253 | |
| 1254 | if ( $echo ) { |
| 1255 | echo $output; |
| 1256 | } |
| 1257 | return $output; |
| 1258 | } |
| 1259 | |
| 1260 | function tutor_single_quiz_no_course_belongs($echo = true){ |
| 1261 | ob_start(); |
| 1262 | tutor_load_template( 'single.quiz.no_course_belongs' ); |
| 1263 | $output = apply_filters( 'tutor_single_quiz/no_course_belongs', ob_get_clean() ); |
| 1264 | |
| 1265 | if ( $echo ) { |
| 1266 | echo $output; |
| 1267 | } |
| 1268 | return $output; |
| 1269 | } |
| 1270 | |
| 1271 | function single_quiz_contents($echo = true){ |
| 1272 | |
| 1273 | ob_start(); |
| 1274 | tutor_load_template( 'single.quiz.single_quiz_contents' ); |
| 1275 | $output = apply_filters( 'tutor_single_quiz/single_quiz_contents', ob_get_clean() ); |
| 1276 | |
| 1277 | if ( $echo ) { |
| 1278 | echo $output; |
| 1279 | } |
| 1280 | return $output; |
| 1281 | } |
| 1282 | |
| 1283 | function get_tutor_course_level($course_id = 0){ |
| 1284 | if ( ! $course_id){ |
| 1285 | $course_id = get_the_ID(); |
| 1286 | } |
| 1287 | if ( ! $course_id){ |
| 1288 | return ''; |
| 1289 | } |
| 1290 | |
| 1291 | $course_level = get_post_meta($course_id, '_tutor_course_level', true); |
| 1292 | |
| 1293 | if ($course_level){ |
| 1294 | return tutor_utils()->course_levels($course_level); |
| 1295 | } |
| 1296 | return false; |
| 1297 | } |
| 1298 | |
| 1299 | if ( ! function_exists('get_tutor_course_duration_context')) { |
| 1300 | function get_tutor_course_duration_context( $course_id = 0 ) { |
| 1301 | if ( ! $course_id ) { |
| 1302 | $course_id = get_the_ID(); |
| 1303 | } |
| 1304 | if ( ! $course_id ) { |
| 1305 | return ''; |
| 1306 | } |
| 1307 | $duration = get_post_meta( $course_id, '_course_duration', true ); |
| 1308 | $durationHours = tutor_utils()->avalue_dot( 'hours', $duration ); |
| 1309 | $durationMinutes = tutor_utils()->avalue_dot( 'minutes', $duration ); |
| 1310 | $durationSeconds = tutor_utils()->avalue_dot( 'seconds', $duration ); |
| 1311 | |
| 1312 | if ( $duration ) { |
| 1313 | $output = ''; |
| 1314 | if ( $durationHours > 0 ) { |
| 1315 | $output .= $durationHours . "h "; |
| 1316 | } |
| 1317 | |
| 1318 | if ( $durationMinutes > 0 ) { |
| 1319 | $output .= $durationMinutes . "m "; |
| 1320 | } |
| 1321 | |
| 1322 | if ( $durationSeconds > 0 ) { |
| 1323 | $output .= $durationSeconds ."s "; |
| 1324 | } |
| 1325 | |
| 1326 | return $output; |
| 1327 | } |
| 1328 | |
| 1329 | return false; |
| 1330 | } |
| 1331 | } |
| 1332 | if ( ! function_exists('get_tutor_course_categories')){ |
| 1333 | function get_tutor_course_categories($course_id = 0){ |
| 1334 | if ( ! $course_id ) { |
| 1335 | $course_id = get_the_ID(); |
| 1336 | } |
| 1337 | $terms = get_the_terms( $course_id, 'course-category' ); |
| 1338 | |
| 1339 | return $terms; |
| 1340 | } |
| 1341 | } |
| 1342 | |
| 1343 | /** |
| 1344 | * @param int $course_id |
| 1345 | * |
| 1346 | * @return array|false|WP_Error |
| 1347 | * |
| 1348 | * Get course tags |
| 1349 | */ |
| 1350 | |
| 1351 | if ( ! function_exists('get_tutor_course_tags')){ |
| 1352 | function get_tutor_course_tags($course_id = 0){ |
| 1353 | if ( ! $course_id ) { |
| 1354 | $course_id = get_the_ID(); |
| 1355 | } |
| 1356 | $terms = get_the_terms( $course_id, 'course-tag' ); |
| 1357 | |
| 1358 | return $terms; |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | /** |
| 1363 | * @param bool $echo |
| 1364 | * |
| 1365 | * @return mixed|void |
| 1366 | * |
| 1367 | * Template for course tags html |
| 1368 | */ |
| 1369 | |
| 1370 | if ( ! function_exists('tutor_course_tags_html')) { |
| 1371 | function tutor_course_tags_html( $echo = true ) { |
| 1372 | ob_start(); |
| 1373 | tutor_load_template( 'single.course.tags' ); |
| 1374 | $output = apply_filters( 'tutor_course/single/tags_html', ob_get_clean() ); |
| 1375 | |
| 1376 | if ( $echo ) { |
| 1377 | echo $output; |
| 1378 | } |
| 1379 | |
| 1380 | return $output; |
| 1381 | } |
| 1382 | } |
| 1383 | |
| 1384 | /** |
| 1385 | * @param bool $echo |
| 1386 | * |
| 1387 | * @return mixed |
| 1388 | * |
| 1389 | * Get Q&A in lesson sidebar |
| 1390 | */ |
| 1391 | |
| 1392 | if ( ! function_exists('tutor_lesson_sidebar_question_and_answer')) { |
| 1393 | function tutor_lesson_sidebar_question_and_answer( $echo = true ) { |
| 1394 | ob_start(); |
| 1395 | tutor_load_template( 'single.lesson.sidebar_question_and_answer' ); |
| 1396 | $output = apply_filters( 'tutor_lesson/single/sidebar_question_and_answer', ob_get_clean() ); |
| 1397 | |
| 1398 | if ( $echo ) { |
| 1399 | echo $output; |
| 1400 | } |
| 1401 | |
| 1402 | return $output; |
| 1403 | } |
| 1404 | } |
| 1405 | |
| 1406 | /** |
| 1407 | * @param bool $echo |
| 1408 | * |
| 1409 | * @return mixed|void |
| 1410 | * |
| 1411 | * Get Social Share button to share on social media |
| 1412 | */ |
| 1413 | |
| 1414 | if ( ! function_exists('tutor_social_share')) { |
| 1415 | function tutor_social_share( $echo = true ) { |
| 1416 | ob_start(); |
| 1417 | tutor_load_template( 'single.course.social_share' ); |
| 1418 | $output = apply_filters( 'tutor_course/single/social_share', ob_get_clean() ); |
| 1419 | |
| 1420 | if ( $echo ) { |
| 1421 | echo $output; |
| 1422 | } |
| 1423 | |
| 1424 | return $output; |
| 1425 | } |
| 1426 | } |
| 1427 | |
| 1428 | /** |
| 1429 | * @param bool $echo |
| 1430 | * |
| 1431 | * @return mixed |
| 1432 | * |
| 1433 | * Get Assignment content |
| 1434 | * |
| 1435 | * @since v.1.3.3 |
| 1436 | */ |
| 1437 | |
| 1438 | if ( ! function_exists('tutor_assignment_content')) { |
| 1439 | function tutor_assignment_content( $echo = true ) { |
| 1440 | ob_start(); |
| 1441 | tutor_load_template( 'single.assignment.content' ); |
| 1442 | $output = apply_filters( 'tutor_assignment/single/content', ob_get_clean() ); |
| 1443 | |
| 1444 | if ( $echo ) { |
| 1445 | echo $output; |
| 1446 | } |
| 1447 | |
| 1448 | return $output; |
| 1449 | } |
| 1450 | } |
| 1451 | |
| 1452 | /** |
| 1453 | * @param string $msg |
| 1454 | * @param string $title |
| 1455 | * @param string $type |
| 1456 | * |
| 1457 | * @return string |
| 1458 | * |
| 1459 | * @since v.1.4.0 |
| 1460 | */ |
| 1461 | |
| 1462 | if ( ! function_exists('get_tnotice')) { |
| 1463 | function get_tnotice( $msg = '', $title = 'Success', $type = 'success' ) { |
| 1464 | |
| 1465 | $output = '<div class="tnotice tnotice--' . $type . '"> |
| 1466 | <div class="tnotice__icon">¡</div> |
| 1467 | <div class="tnotice__content">'; |
| 1468 | |
| 1469 | if ($title){ |
| 1470 | $output .='<p class="tnotice__type">' . $title . '</p>'; |
| 1471 | } |
| 1472 | $output .='<p class="tnotice__message">' . $msg . '</p> |
| 1473 | </div> |
| 1474 | </div>'; |
| 1475 | |
| 1476 | return $output; |
| 1477 | } |
| 1478 | } |