| @@ -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' ) ); |
| @@ -58,14 +47,12 @@ | ||
| 58 | 47 | add_shortcode( 'tutor_instructor_registration_form', array( $this, 'instructor_registration_form' ) ); |
| 59 | 48 | add_shortcode( 'tutor_course', array( $this, 'tutor_course' ) ); |
| 60 | 49 | |
| 61 | 50 | add_shortcode( 'tutor_instructor_list', array( $this, 'tutor_instructor_list' ) ); |
| 51 | + add_action( 'tutor_options_after_instructors', array( $this, 'tutor_instructor_layout' ) ); | |
| 62 | 52 | add_action( 'wp_ajax_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) ); |
| 63 | 53 | add_action( 'wp_ajax_nopriv_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) ); |
| 64 | 54 | |
| 65 | - add_shortcode( 'tutor_cart', array( $this, 'tutor_cart_page' ) ); | |
| 66 | - add_shortcode( 'tutor_checkout', array( $this, 'tutor_checkout_page' ) ); | |
| 67 | - | |
| 68 | 55 | /** |
| 69 | 56 | * Load more categories |
| 70 | 57 | * |
| 71 | 58 | * @since 2.0.0 |
| @@ -117,12 +104,10 @@ | ||
| 117 | 104 | * popup sign-in button |
| 118 | 105 | * |
| 119 | 106 | * @since 2.1.3 |
| 120 | 107 | */ |
| 121 | - $login_url = tutor_utils()->get_option( 'enable_tutor_native_login', null, true, true ) ? '' : wp_login_url( tutor()->current_url ); | |
| 122 | - $signin_link = '<a data-login_url="' . esc_url( $login_url ) . '" href="#" class="tutor-open-login-modal">' . __( 'Sign-In', 'tutor' ) . '</a>'; | |
| 123 | - /* translators: %s is anchor link for signin */ | |
| 124 | - echo sprintf( __( 'Please %s to view this page', 'tutor' ), $signin_link ); //phpcs:ignore | |
| 108 | + $login_url = tutor_utils()->get_option( 'enable_tutor_native_login', null, true, true ) ? '' : wp_login_url( tutor()->current_url ); | |
| 109 | + echo sprintf( __( 'Please %1$sSign-In%2$s to view this page', 'tutor' ), '<a data-login_url="' . esc_url( $login_url ) . '" href="#" class="tutor-open-login-modal">', '</a>' );//phpcs:ignore | |
| 125 | 110 | } |
| 126 | 111 | return apply_filters( 'tutor_dashboard/index', ob_get_clean() ); |
| 127 | 112 | } |
| 128 | 113 | |
| @@ -169,32 +154,16 @@ | ||
| 169 | 154 | ), |
| 170 | 155 | $atts |
| 171 | 156 | ); |
| 172 | 157 | |
| 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 | 158 | if ( ! empty( $a['id'] ) ) { |
| 181 | 159 | $ids = (array) explode( ',', $a['id'] ); |
| 182 | 160 | $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 | 161 | } |
| 189 | 162 | |
| 190 | 163 | if ( ! empty( $a['exclude_ids'] ) ) { |
| 191 | 164 | $exclude_ids = (array) explode( ',', $a['exclude_ids'] ); |
| 192 | 165 | $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 | 166 | } |
| 198 | 167 | if ( ! empty( $a['category'] ) ) { |
| 199 | 168 | $category = (array) explode( ',', $a['category'] ); |
| 200 | 169 | |
| @@ -201,9 +170,9 @@ | ||
| 201 | 170 | $a['tax_query'] = array(); |
| 202 | 171 | |
| 203 | 172 | $category_ids = array_filter( |
| 204 | 173 | $category, |
| 205 | - function ( $id ) { | |
| 174 | + function( $id ) { | |
| 206 | 175 | return is_numeric( $id ); |
| 207 | 176 | } |
| 208 | 177 | ); |
| 209 | 178 | |
| @@ -208,9 +177,9 @@ | ||
| 208 | 177 | ); |
| 209 | 178 | |
| 210 | 179 | $category_names = array_filter( |
| 211 | 180 | $category, |
| 212 | - function ( $id ) { | |
| 181 | + function( $id ) { | |
| 213 | 182 | return ! is_numeric( $id ); |
| 214 | 183 | } |
| 215 | 184 | ); |
| 216 | 185 | |
| @@ -216,26 +185,20 @@ | ||
| 216 | 185 | |
| 217 | 186 | if ( ! empty( $category_ids ) ) { |
| 218 | 187 | $a['tax_query'] = array( |
| 219 | 188 | array( |
| 220 | - 'taxonomy' => CourseModel::COURSE_CATEGORY, | |
| 189 | + 'taxonomy' => 'course-category', | |
| 221 | 190 | 'field' => 'term_id', |
| 222 | 191 | 'terms' => $category_ids, |
| 223 | 192 | 'operator' => 'IN', |
| 224 | 193 | ), |
| 225 | 194 | ); |
| 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 | 195 | } |
| 233 | 196 | |
| 234 | 197 | if ( ! empty( $category_names ) ) { |
| 235 | 198 | $a['tax_query'] = array( |
| 236 | 199 | array( |
| 237 | - 'taxonomy' => CourseModel::COURSE_CATEGORY, | |
| 200 | + 'taxonomy' => 'course-category', | |
| 238 | 201 | 'field' => 'name', |
| 239 | 202 | 'terms' => $category_names, |
| 240 | 203 | 'operator' => 'IN', |
| 241 | 204 | ), |
| @@ -264,19 +227,16 @@ | ||
| 264 | 227 | if ( $the_query->have_posts() ) { |
| 265 | 228 | tutor_load_template( |
| 266 | 229 | 'archive-course-init', |
| 267 | 230 | 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, | |
| 231 | + 'course_filter' => isset( $atts['course_filter'] ) && 'on' === $atts['course_filter'], | |
| 232 | + 'supported_filters' => tutor_utils()->get_option( 'supported_course_filters', array() ), | |
| 233 | + 'loop_content_only' => false, | |
| 234 | + 'column_per_row' => isset( $atts['column_per_row'] ) ? $atts['column_per_row'] : null, | |
| 235 | + 'course_per_page' => $a['posts_per_page'], | |
| 236 | + 'show_pagination' => isset( $atts['show_pagination'] ) && 'on' === $atts['show_pagination'], | |
| 237 | + 'the_query' => $the_query, | |
| 238 | + 'current_page' => isset( $get['current_page'] ) ? (int) $get['current_page'] : 1, | |
| 279 | 239 | ) |
| 280 | 240 | ); |
| 281 | 241 | } else { |
| 282 | 242 | tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); |
| @@ -338,8 +298,9 @@ | ||
| 338 | 298 | * |
| 339 | 299 | * @return string |
| 340 | 300 | */ |
| 341 | 301 | public function tutor_instructor_list( $atts ) { |
| 302 | + global $wpdb; | |
| 342 | 303 | ! is_array( $atts ) ? $atts = array() : 0; |
| 343 | 304 | |
| 344 | 305 | $current_page = (int) tutor_utils()->array_get( 'instructor-page', $_GET, 1 ); |
| 345 | 306 | $current_page = Input::get( 'instructor-page', 1, Input::TYPE_INT ); |
| @@ -345,10 +306,8 @@ | ||
| 345 | 306 | $current_page = Input::get( 'instructor-page', 1, Input::TYPE_INT ); |
| 346 | 307 | $current_page = $current_page >= 1 ? $current_page : 1; |
| 347 | 308 | |
| 348 | 309 | $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 | 310 | $atts['show_filter'] = $show_filter; |
| 352 | 311 | |
| 353 | 312 | // Get instructor list to sow. |
| 354 | 313 | $payload = $this->prepare_instructor_list( $current_page, $atts ); |
| @@ -358,18 +317,39 @@ | ||
| 358 | 317 | tutor_load_template( 'shortcode.tutor-instructor', $payload ); |
| 359 | 318 | $content = ob_get_clean(); |
| 360 | 319 | |
| 361 | 320 | 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, | |
| 321 | + $limit = 8; | |
| 322 | + $course_taxonomy = 'course-category'; | |
| 323 | + $course_cats = $wpdb->get_results( | |
| 324 | + $wpdb->prepare( | |
| 325 | + "SELECT | |
| 326 | + * | |
| 327 | + FROM {$wpdb->terms} AS term | |
| 328 | + | |
| 329 | + INNER JOIN {$wpdb->term_taxonomy} AS taxonomy | |
| 330 | + ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s | |
| 331 | + | |
| 332 | + ORDER BY term.term_id DESC | |
| 333 | + LIMIT %d | |
| 334 | + ", | |
| 335 | + $course_taxonomy, | |
| 336 | + $limit | |
| 337 | + ) | |
| 369 | 338 | ); |
| 370 | 339 | |
| 371 | - $course_cats = get_terms( $term_args ); | |
| 340 | + $all_cats = $wpdb->get_var( | |
| 341 | + $wpdb->prepare( | |
| 342 | + "SELECT | |
| 343 | + COUNT(*) as total | |
| 344 | + FROM {$wpdb->terms} AS term | |
| 345 | + INNER JOIN {$wpdb->term_taxonomy} AS taxonomy | |
| 346 | + ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s | |
| 347 | + ORDER BY term.term_id DESC | |
| 348 | + ", | |
| 349 | + $course_taxonomy | |
| 350 | + ) | |
| 351 | + ); | |
| 372 | 352 | |
| 373 | 353 | $attributes = $payload; |
| 374 | 354 | unset( $attributes['instructors'] ); |
| 375 | 355 | |
| @@ -376,8 +356,9 @@ | ||
| 376 | 356 | $payload = array( |
| 377 | 357 | 'show_filter' => $show_filter, |
| 378 | 358 | 'content' => $content, |
| 379 | 359 | 'categories' => $course_cats, |
| 360 | + 'all_cats' => $all_cats, | |
| 380 | 361 | 'attributes' => array_merge( $atts, $attributes ), |
| 381 | 362 | ); |
| 382 | 363 | |
| 383 | 364 | ob_start(); |
| @@ -402,13 +383,13 @@ | ||
| 402 | 383 | global $wpdb; |
| 403 | 384 | tutor_utils()->checking_nonce(); |
| 404 | 385 | $term_id = Input::post( 'term_id', 0, Input::TYPE_INT ); |
| 405 | 386 | $limit = 8; |
| 406 | - $course_taxonomy = CourseModel::COURSE_CATEGORY; | |
| 387 | + $course_taxonomy = 'course-category'; | |
| 407 | 388 | |
| 408 | 389 | $remaining_categories = $wpdb->get_var( |
| 409 | 390 | $wpdb->prepare( |
| 410 | - "SELECT | |
| 391 | + "SElECT | |
| 411 | 392 | COUNT(*) AS total |
| 412 | 393 | FROM {$wpdb->terms} AS term |
| 413 | 394 | INNER JOIN {$wpdb->term_taxonomy} AS taxonomy |
| 414 | 395 | ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s |
| @@ -421,9 +402,9 @@ | ||
| 421 | 402 | ); |
| 422 | 403 | |
| 423 | 404 | $add_categories = $wpdb->get_results( |
| 424 | 405 | $wpdb->prepare( |
| 425 | - "SELECT | |
| 406 | + "SElECT | |
| 426 | 407 | * |
| 427 | 408 | FROM {$wpdb->terms} term |
| 428 | 409 | INNER JOIN {$wpdb->term_taxonomy} as taxonomy |
| 429 | 410 | ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s |
| @@ -466,9 +447,9 @@ | ||
| 466 | 447 | |
| 467 | 448 | $category = (array) tutor_utils()->array_get( 'category', $_post, array() ); |
| 468 | 449 | $category = array_filter( |
| 469 | 450 | $category, |
| 470 | - function ( $cat ) { | |
| 451 | + function( $cat ) { | |
| 471 | 452 | return is_numeric( $cat ); |
| 472 | 453 | } |
| 473 | 454 | ); |
| 474 | 455 | |
| @@ -480,29 +461,14 @@ | ||
| 480 | 461 | exit; |
| 481 | 462 | } |
| 482 | 463 | |
| 483 | 464 | /** |
| 484 | - * Tutor Cart Shortcode | |
| 465 | + * Show layout selection dashboard in instructor setting | |
| 485 | 466 | * |
| 486 | - * @since v.3.0.0 | |
| 467 | + * @since 1.0.0 | |
| 487 | 468 | * |
| 488 | - * @return mixed | |
| 469 | + * @return void | |
| 489 | 470 | */ |
| 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() ); | |
| 471 | + public function tutor_instructor_layout() { | |
| 472 | + tutor_load_template( 'instructor-setting', array( 'templates' => $this->instructor_layout ) ); | |
| 507 | 473 | } |
| 508 | 474 | } |