| @@ -9,10 +9,8 @@ | ||
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | 11 | namespace TUTOR; |
| 12 | 12 | |
| 13 | -use Tutor\Models\CourseModel; | |
| 14 | - | |
| 15 | 13 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | 14 | exit; |
| 17 | 15 | } |
| 18 | 16 | |
| @@ -41,19 +39,10 @@ | ||
| 41 | 39 | /** |
| 42 | 40 | * Register hooks |
| 43 | 41 | * |
| 44 | 42 | * @since 1.0.0 |
| 45 | - * @since 3.8.0 | |
| 46 | - * | |
| 47 | - * @param bool $register_hooks register hooks or not. | |
| 48 | - * | |
| 49 | - * @return void | |
| 50 | 43 | */ |
| 51 | - public function __construct( $register_hooks = true ) { | |
| 52 | - if ( ! $register_hooks ) { | |
| 53 | - return; | |
| 54 | - } | |
| 55 | - | |
| 44 | + public function __construct() { | |
| 56 | 45 | add_shortcode( 'tutor_student_registration_form', array( $this, 'student_registration_form' ) ); |
| 57 | 46 | add_shortcode( 'tutor_dashboard', array( $this, 'tutor_dashboard' ) ); |
| 58 | 47 | add_shortcode( 'tutor_instructor_registration_form', array( $this, 'instructor_registration_form' ) ); |
| 59 | 48 | add_shortcode( 'tutor_course', array( $this, 'tutor_course' ) ); |
| @@ -61,11 +50,8 @@ | ||
| 61 | 50 | add_shortcode( 'tutor_instructor_list', array( $this, 'tutor_instructor_list' ) ); |
| 62 | 51 | add_action( 'wp_ajax_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) ); |
| 63 | 52 | add_action( 'wp_ajax_nopriv_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) ); |
| 64 | 53 | |
| 65 | - add_shortcode( 'tutor_cart', array( $this, 'tutor_cart_page' ) ); | |
| 66 | - add_shortcode( 'tutor_checkout', array( $this, 'tutor_checkout_page' ) ); | |
| 67 | - | |
| 68 | 54 | /** |
| 69 | 55 | * Load more categories |
| 70 | 56 | * |
| 71 | 57 | * @since 2.0.0 |
| @@ -117,9 +103,9 @@ | ||
| 117 | 103 | * popup sign-in button |
| 118 | 104 | * |
| 119 | 105 | * @since 2.1.3 |
| 120 | 106 | */ |
| 121 | - $login_url = tutor_utils()->get_option( 'enable_tutor_native_login', null, true, true ) ? '' : wp_login_url( tutor()->current_url ); | |
| 107 | + $login_url = tutor_utils()->get_option( 'enable_tutor_native_login', null, true, true ) ? '' : wp_login_url( tutor()->current_url ); | |
| 122 | 108 | $signin_link = '<a data-login_url="' . esc_url( $login_url ) . '" href="#" class="tutor-open-login-modal">' . __( 'Sign-In', 'tutor' ) . '</a>'; |
| 123 | 109 | /* translators: %s is anchor link for signin */ |
| 124 | 110 | echo sprintf( __( 'Please %s to view this page', 'tutor' ), $signin_link ); //phpcs:ignore |
| 125 | 111 | } |
| @@ -169,32 +155,16 @@ | ||
| 169 | 155 | ), |
| 170 | 156 | $atts |
| 171 | 157 | ); |
| 172 | 158 | |
| 173 | - $a = apply_filters( 'tutor_get_course_list_filter_args', $a ); | |
| 174 | - | |
| 175 | - $supported_filters = tutor_utils()->get_option( 'supported_course_filters', array() ); | |
| 176 | - $course_filter_category = array(); | |
| 177 | - $course_filter_exclude_ids = array(); | |
| 178 | - $course_filter_post_ids = array(); | |
| 179 | - | |
| 180 | 159 | if ( ! empty( $a['id'] ) ) { |
| 181 | 160 | $ids = (array) explode( ',', $a['id'] ); |
| 182 | 161 | $a['post__in'] = $ids; |
| 183 | - | |
| 184 | - if ( is_array( $ids ) && count( $ids ) && ! wp_doing_ajax() ) { | |
| 185 | - $_GET['tutor-course-filter-post-ids'] = $ids; | |
| 186 | - $course_filter_post_ids = $ids; | |
| 187 | - } | |
| 188 | 162 | } |
| 189 | 163 | |
| 190 | 164 | if ( ! empty( $a['exclude_ids'] ) ) { |
| 191 | 165 | $exclude_ids = (array) explode( ',', $a['exclude_ids'] ); |
| 192 | 166 | $a['post__not_in'] = $exclude_ids; |
| 193 | - if ( is_array( $exclude_ids ) && count( $exclude_ids ) && ! wp_doing_ajax() ) { | |
| 194 | - $_GET['tutor-course-filter-exclude-ids'] = $exclude_ids; | |
| 195 | - $course_filter_exclude_ids = $exclude_ids; | |
| 196 | - } | |
| 197 | 167 | } |
| 198 | 168 | if ( ! empty( $a['category'] ) ) { |
| 199 | 169 | $category = (array) explode( ',', $a['category'] ); |
| 200 | 170 | |
| @@ -201,9 +171,9 @@ | ||
| 201 | 171 | $a['tax_query'] = array(); |
| 202 | 172 | |
| 203 | 173 | $category_ids = array_filter( |
| 204 | 174 | $category, |
| 205 | - function ( $id ) { | |
| 175 | + function( $id ) { | |
| 206 | 176 | return is_numeric( $id ); |
| 207 | 177 | } |
| 208 | 178 | ); |
| 209 | 179 | |
| @@ -208,9 +178,9 @@ | ||
| 208 | 178 | ); |
| 209 | 179 | |
| 210 | 180 | $category_names = array_filter( |
| 211 | 181 | $category, |
| 212 | - function ( $id ) { | |
| 182 | + function( $id ) { | |
| 213 | 183 | return ! is_numeric( $id ); |
| 214 | 184 | } |
| 215 | 185 | ); |
| 216 | 186 | |
| @@ -216,26 +186,20 @@ | ||
| 216 | 186 | |
| 217 | 187 | if ( ! empty( $category_ids ) ) { |
| 218 | 188 | $a['tax_query'] = array( |
| 219 | 189 | array( |
| 220 | - 'taxonomy' => CourseModel::COURSE_CATEGORY, | |
| 190 | + 'taxonomy' => 'course-category', | |
| 221 | 191 | 'field' => 'term_id', |
| 222 | 192 | 'terms' => $category_ids, |
| 223 | 193 | 'operator' => 'IN', |
| 224 | 194 | ), |
| 225 | 195 | ); |
| 226 | - | |
| 227 | - if ( is_array( $category_ids ) && count( $category_ids ) && ! wp_doing_ajax() ) { | |
| 228 | - $_GET['tutor-course-filter-category'] = $category_ids; | |
| 229 | - $course_filter_category = $category_ids; | |
| 230 | - unset( $supported_filters['category'] ); | |
| 231 | - } | |
| 232 | 196 | } |
| 233 | 197 | |
| 234 | 198 | if ( ! empty( $category_names ) ) { |
| 235 | 199 | $a['tax_query'] = array( |
| 236 | 200 | array( |
| 237 | - 'taxonomy' => CourseModel::COURSE_CATEGORY, | |
| 201 | + 'taxonomy' => 'course-category', | |
| 238 | 202 | 'field' => 'name', |
| 239 | 203 | 'terms' => $category_names, |
| 240 | 204 | 'operator' => 'IN', |
| 241 | 205 | ), |
| @@ -264,19 +228,16 @@ | ||
| 264 | 228 | if ( $the_query->have_posts() ) { |
| 265 | 229 | tutor_load_template( |
| 266 | 230 | 'archive-course-init', |
| 267 | 231 | array( |
| 268 | - 'course_filter' => isset( $atts['course_filter'] ) && 'on' === $atts['course_filter'], | |
| 269 | - 'supported_filters' => $supported_filters, | |
| 270 | - 'loop_content_only' => false, | |
| 271 | - 'column_per_row' => isset( $atts['column_per_row'] ) ? $atts['column_per_row'] : null, | |
| 272 | - 'course_per_page' => $a['posts_per_page'], | |
| 273 | - 'show_pagination' => isset( $atts['show_pagination'] ) && 'on' === $atts['show_pagination'], | |
| 274 | - 'the_query' => $the_query, | |
| 275 | - 'current_page' => isset( $get['current_page'] ) ? (int) $get['current_page'] : 1, | |
| 276 | - 'course_filter_category' => ! empty( $course_filter_category ) ? json_encode( $course_filter_category ) : null, | |
| 277 | - 'course_filter_exclude_ids' => ! empty( $course_filter_exclude_ids ) ? json_encode( $course_filter_exclude_ids ) : null, | |
| 278 | - 'course_filter_post_ids' => ! empty( $course_filter_post_ids ) ? json_encode( $course_filter_post_ids ) : null, | |
| 232 | + 'course_filter' => isset( $atts['course_filter'] ) && 'on' === $atts['course_filter'], | |
| 233 | + 'supported_filters' => tutor_utils()->get_option( 'supported_course_filters', array() ), | |
| 234 | + 'loop_content_only' => false, | |
| 235 | + 'column_per_row' => isset( $atts['column_per_row'] ) ? $atts['column_per_row'] : null, | |
| 236 | + 'course_per_page' => $a['posts_per_page'], | |
| 237 | + 'show_pagination' => isset( $atts['show_pagination'] ) && 'on' === $atts['show_pagination'], | |
| 238 | + 'the_query' => $the_query, | |
| 239 | + 'current_page' => isset( $get['current_page'] ) ? (int) $get['current_page'] : 1, | |
| 279 | 240 | ) |
| 280 | 241 | ); |
| 281 | 242 | } else { |
| 282 | 243 | tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); |
| @@ -338,8 +299,9 @@ | ||
| 338 | 299 | * |
| 339 | 300 | * @return string |
| 340 | 301 | */ |
| 341 | 302 | public function tutor_instructor_list( $atts ) { |
| 303 | + global $wpdb; | |
| 342 | 304 | ! is_array( $atts ) ? $atts = array() : 0; |
| 343 | 305 | |
| 344 | 306 | $current_page = (int) tutor_utils()->array_get( 'instructor-page', $_GET, 1 ); |
| 345 | 307 | $current_page = Input::get( 'instructor-page', 1, Input::TYPE_INT ); |
| @@ -345,10 +307,8 @@ | ||
| 345 | 307 | $current_page = Input::get( 'instructor-page', 1, Input::TYPE_INT ); |
| 346 | 308 | $current_page = $current_page >= 1 ? $current_page : 1; |
| 347 | 309 | |
| 348 | 310 | $show_filter = isset( $atts['filter'] ) ? 'on' === $atts['filter'] : tutor_utils()->get_option( 'instructor_list_show_filter', false ); |
| 349 | - $category_limit = (int) isset( $atts['category_limit'] ) ? $atts['category_limit'] : 0; | |
| 350 | - $hide_empty_category = isset( $atts['hide_empty_category'] ) ? '1' == $atts['hide_empty_category'] : false; | |
| 351 | 311 | $atts['show_filter'] = $show_filter; |
| 352 | 312 | |
| 353 | 313 | // Get instructor list to sow. |
| 354 | 314 | $payload = $this->prepare_instructor_list( $current_page, $atts ); |
| @@ -358,18 +318,39 @@ | ||
| 358 | 318 | tutor_load_template( 'shortcode.tutor-instructor', $payload ); |
| 359 | 319 | $content = ob_get_clean(); |
| 360 | 320 | |
| 361 | 321 | if ( $show_filter ) { |
| 362 | - $course_taxonomy = CourseModel::COURSE_CATEGORY; | |
| 363 | - $term_args = array( | |
| 364 | - 'taxonomy' => $course_taxonomy, | |
| 365 | - 'hide_empty' => $hide_empty_category, | |
| 366 | - 'orderby' => 'count', | |
| 367 | - 'order' => 'DESC', | |
| 368 | - 'number' => $category_limit, | |
| 322 | + $limit = 8; | |
| 323 | + $course_taxonomy = 'course-category'; | |
| 324 | + $course_cats = $wpdb->get_results( | |
| 325 | + $wpdb->prepare( | |
| 326 | + "SELECT | |
| 327 | + * | |
| 328 | + FROM {$wpdb->terms} AS term | |
| 329 | + | |
| 330 | + INNER JOIN {$wpdb->term_taxonomy} AS taxonomy | |
| 331 | + ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s | |
| 332 | + | |
| 333 | + ORDER BY term.term_id DESC | |
| 334 | + LIMIT %d | |
| 335 | + ", | |
| 336 | + $course_taxonomy, | |
| 337 | + $limit | |
| 338 | + ) | |
| 369 | 339 | ); |
| 370 | 340 | |
| 371 | - $course_cats = get_terms( $term_args ); | |
| 341 | + $all_cats = $wpdb->get_var( | |
| 342 | + $wpdb->prepare( | |
| 343 | + "SELECT | |
| 344 | + COUNT(*) as total | |
| 345 | + FROM {$wpdb->terms} AS term | |
| 346 | + INNER JOIN {$wpdb->term_taxonomy} AS taxonomy | |
| 347 | + ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s | |
| 348 | + ORDER BY term.term_id DESC | |
| 349 | + ", | |
| 350 | + $course_taxonomy | |
| 351 | + ) | |
| 352 | + ); | |
| 372 | 353 | |
| 373 | 354 | $attributes = $payload; |
| 374 | 355 | unset( $attributes['instructors'] ); |
| 375 | 356 | |
| @@ -376,8 +357,9 @@ | ||
| 376 | 357 | $payload = array( |
| 377 | 358 | 'show_filter' => $show_filter, |
| 378 | 359 | 'content' => $content, |
| 379 | 360 | 'categories' => $course_cats, |
| 361 | + 'all_cats' => $all_cats, | |
| 380 | 362 | 'attributes' => array_merge( $atts, $attributes ), |
| 381 | 363 | ); |
| 382 | 364 | |
| 383 | 365 | ob_start(); |
| @@ -402,13 +384,13 @@ | ||
| 402 | 384 | global $wpdb; |
| 403 | 385 | tutor_utils()->checking_nonce(); |
| 404 | 386 | $term_id = Input::post( 'term_id', 0, Input::TYPE_INT ); |
| 405 | 387 | $limit = 8; |
| 406 | - $course_taxonomy = CourseModel::COURSE_CATEGORY; | |
| 388 | + $course_taxonomy = 'course-category'; | |
| 407 | 389 | |
| 408 | 390 | $remaining_categories = $wpdb->get_var( |
| 409 | 391 | $wpdb->prepare( |
| 410 | - "SELECT | |
| 392 | + "SElECT | |
| 411 | 393 | COUNT(*) AS total |
| 412 | 394 | FROM {$wpdb->terms} AS term |
| 413 | 395 | INNER JOIN {$wpdb->term_taxonomy} AS taxonomy |
| 414 | 396 | ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s |
| @@ -421,9 +403,9 @@ | ||
| 421 | 403 | ); |
| 422 | 404 | |
| 423 | 405 | $add_categories = $wpdb->get_results( |
| 424 | 406 | $wpdb->prepare( |
| 425 | - "SELECT | |
| 407 | + "SElECT | |
| 426 | 408 | * |
| 427 | 409 | FROM {$wpdb->terms} term |
| 428 | 410 | INNER JOIN {$wpdb->term_taxonomy} as taxonomy |
| 429 | 411 | ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s |
| @@ -466,9 +448,9 @@ | ||
| 466 | 448 | |
| 467 | 449 | $category = (array) tutor_utils()->array_get( 'category', $_post, array() ); |
| 468 | 450 | $category = array_filter( |
| 469 | 451 | $category, |
| 470 | - function ( $cat ) { | |
| 452 | + function( $cat ) { | |
| 471 | 453 | return is_numeric( $cat ); |
| 472 | 454 | } |
| 473 | 455 | ); |
| 474 | 456 | |
| @@ -477,32 +459,6 @@ | ||
| 477 | 459 | ob_start(); |
| 478 | 460 | tutor_load_template( 'shortcode.tutor-instructor', $data ); |
| 479 | 461 | wp_send_json_success( array( 'html' => ob_get_clean() ) ); |
| 480 | 462 | exit; |
| 481 | - } | |
| 482 | - | |
| 483 | - /** | |
| 484 | - * Tutor Cart Shortcode | |
| 485 | - * | |
| 486 | - * @since v.3.0.0 | |
| 487 | - * | |
| 488 | - * @return mixed | |
| 489 | - */ | |
| 490 | - public function tutor_cart_page() { | |
| 491 | - ob_start(); | |
| 492 | - tutor_load_template( 'ecommerce.cart' ); | |
| 493 | - return apply_filters( 'tutor_ecommerce/cart', ob_get_clean() ); | |
| 494 | - } | |
| 495 | - | |
| 496 | - /** | |
| 497 | - * Tutor Checkout Shortcode | |
| 498 | - * | |
| 499 | - * @since v.3.0.0 | |
| 500 | - * | |
| 501 | - * @return mixed | |
| 502 | - */ | |
| 503 | - public function tutor_checkout_page() { | |
| 504 | - ob_start(); | |
| 505 | - tutor_load_template( 'ecommerce.checkout' ); | |
| 506 | - return apply_filters( 'tutor_ecommerce/checkout', ob_get_clean() ); | |
| 507 | 463 | } |
| 508 | 464 | } |