| @@ -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>' ); | |
| 125 | 110 | } |
| 126 | 111 | return apply_filters( 'tutor_dashboard/index', ob_get_clean() ); |
| 127 | 112 | } |
| 128 | 113 | |
| @@ -152,11 +137,13 @@ | ||
| 152 | 137 | * |
| 153 | 138 | * @return string |
| 154 | 139 | */ |
| 155 | 140 | public function tutor_course( $atts ) { |
| 141 | + $course_post_type = tutor()->course_post_type; | |
| 142 | + | |
| 156 | 143 | $a = shortcode_atts( |
| 157 | 144 | array( |
| 158 | - 'post_type' => apply_filters( 'tutor_course_archive_post_types', array( tutor()->course_post_type ) ), | |
| 145 | + 'post_type' => $course_post_type, | |
| 159 | 146 | 'post_status' => 'publish', |
| 160 | 147 | |
| 161 | 148 | 'id' => '', |
| 162 | 149 | 'exclude_ids' => '', |
| @@ -163,38 +150,22 @@ | ||
| 163 | 150 | 'category' => '', |
| 164 | 151 | |
| 165 | 152 | 'orderby' => 'ID', |
| 166 | 153 | 'order' => 'DESC', |
| 167 | - 'count' => tutils()->get_option( 'courses_per_page', 12 ), | |
| 154 | + 'count' => 6, | |
| 168 | 155 | 'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1, |
| 169 | 156 | ), |
| 170 | 157 | $atts |
| 171 | 158 | ); |
| 172 | 159 | |
| 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 | 160 | if ( ! empty( $a['id'] ) ) { |
| 181 | 161 | $ids = (array) explode( ',', $a['id'] ); |
| 182 | 162 | $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 | 163 | } |
| 189 | 164 | |
| 190 | 165 | if ( ! empty( $a['exclude_ids'] ) ) { |
| 191 | 166 | $exclude_ids = (array) explode( ',', $a['exclude_ids'] ); |
| 192 | 167 | $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 | 168 | } |
| 198 | 169 | if ( ! empty( $a['category'] ) ) { |
| 199 | 170 | $category = (array) explode( ',', $a['category'] ); |
| 200 | 171 | |
| @@ -201,9 +172,9 @@ | ||
| 201 | 172 | $a['tax_query'] = array(); |
| 202 | 173 | |
| 203 | 174 | $category_ids = array_filter( |
| 204 | 175 | $category, |
| 205 | - function ( $id ) { | |
| 176 | + function( $id ) { | |
| 206 | 177 | return is_numeric( $id ); |
| 207 | 178 | } |
| 208 | 179 | ); |
| 209 | 180 | |
| @@ -208,9 +179,9 @@ | ||
| 208 | 179 | ); |
| 209 | 180 | |
| 210 | 181 | $category_names = array_filter( |
| 211 | 182 | $category, |
| 212 | - function ( $id ) { | |
| 183 | + function( $id ) { | |
| 213 | 184 | return ! is_numeric( $id ); |
| 214 | 185 | } |
| 215 | 186 | ); |
| 216 | 187 | |
| @@ -216,26 +187,20 @@ | ||
| 216 | 187 | |
| 217 | 188 | if ( ! empty( $category_ids ) ) { |
| 218 | 189 | $a['tax_query'] = array( |
| 219 | 190 | array( |
| 220 | - 'taxonomy' => CourseModel::COURSE_CATEGORY, | |
| 191 | + 'taxonomy' => 'course-category', | |
| 221 | 192 | 'field' => 'term_id', |
| 222 | 193 | 'terms' => $category_ids, |
| 223 | 194 | 'operator' => 'IN', |
| 224 | 195 | ), |
| 225 | 196 | ); |
| 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 | 197 | } |
| 233 | 198 | |
| 234 | 199 | if ( ! empty( $category_names ) ) { |
| 235 | 200 | $a['tax_query'] = array( |
| 236 | 201 | array( |
| 237 | - 'taxonomy' => CourseModel::COURSE_CATEGORY, | |
| 202 | + 'taxonomy' => 'course-category', | |
| 238 | 203 | 'field' => 'name', |
| 239 | 204 | 'terms' => $category_names, |
| 240 | 205 | 'operator' => 'IN', |
| 241 | 206 | ), |
| @@ -246,19 +211,8 @@ | ||
| 246 | 211 | |
| 247 | 212 | wp_reset_query(); |
| 248 | 213 | $the_query = new \WP_Query( $a ); |
| 249 | 214 | |
| 250 | - /** | |
| 251 | - * Pagination & course filter handle from query param on page load (without ajax) | |
| 252 | - * | |
| 253 | - * @since 2.4.0 | |
| 254 | - */ | |
| 255 | - $get = Input::has( 'course_filter' ) ? Input::sanitize_array( $_GET ) : array(); | |
| 256 | - if ( Input::has( 'course_filter' ) ) { | |
| 257 | - $filter = ( new \Tutor\Course_Filter( false ) )->load_listing( $get, true ); | |
| 258 | - $the_query = new \WP_Query( $filter ); | |
| 259 | - } | |
| 260 | - | |
| 261 | 215 | // Load the renderer now. |
| 262 | 216 | ob_start(); |
| 263 | 217 | |
| 264 | 218 | if ( $the_query->have_posts() ) { |
| @@ -264,19 +218,15 @@ | ||
| 264 | 218 | if ( $the_query->have_posts() ) { |
| 265 | 219 | tutor_load_template( |
| 266 | 220 | 'archive-course-init', |
| 267 | 221 | 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, | |
| 222 | + 'course_filter' => isset( $atts['course_filter'] ) && $atts['course_filter'] == 'on', | |
| 223 | + 'supported_filters' => tutor_utils()->get_option( 'supported_course_filters', array() ), | |
| 224 | + 'loop_content_only' => false, | |
| 225 | + 'column_per_row' => isset( $atts['column_per_row'] ) ? $atts['column_per_row'] : null, | |
| 226 | + 'course_per_page' => $a['posts_per_page'], | |
| 227 | + 'show_pagination' => isset( $atts['show_pagination'] ) && $atts['show_pagination'] == 'on', | |
| 228 | + 'the_query' => $the_query, | |
| 279 | 229 | ) |
| 280 | 230 | ); |
| 281 | 231 | } else { |
| 282 | 232 | tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); |
| @@ -338,8 +288,9 @@ | ||
| 338 | 288 | * |
| 339 | 289 | * @return string |
| 340 | 290 | */ |
| 341 | 291 | public function tutor_instructor_list( $atts ) { |
| 292 | + global $wpdb; | |
| 342 | 293 | ! is_array( $atts ) ? $atts = array() : 0; |
| 343 | 294 | |
| 344 | 295 | $current_page = (int) tutor_utils()->array_get( 'instructor-page', $_GET, 1 ); |
| 345 | 296 | $current_page = Input::get( 'instructor-page', 1, Input::TYPE_INT ); |
| @@ -345,10 +296,8 @@ | ||
| 345 | 296 | $current_page = Input::get( 'instructor-page', 1, Input::TYPE_INT ); |
| 346 | 297 | $current_page = $current_page >= 1 ? $current_page : 1; |
| 347 | 298 | |
| 348 | 299 | $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 | 300 | $atts['show_filter'] = $show_filter; |
| 352 | 301 | |
| 353 | 302 | // Get instructor list to sow. |
| 354 | 303 | $payload = $this->prepare_instructor_list( $current_page, $atts ); |
| @@ -358,18 +307,39 @@ | ||
| 358 | 307 | tutor_load_template( 'shortcode.tutor-instructor', $payload ); |
| 359 | 308 | $content = ob_get_clean(); |
| 360 | 309 | |
| 361 | 310 | 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, | |
| 311 | + $limit = 8; | |
| 312 | + $course_taxonomy = 'course-category'; | |
| 313 | + $course_cats = $wpdb->get_results( | |
| 314 | + $wpdb->prepare( | |
| 315 | + "SELECT | |
| 316 | + * | |
| 317 | + FROM {$wpdb->terms} AS term | |
| 318 | + | |
| 319 | + INNER JOIN {$wpdb->term_taxonomy} AS taxonomy | |
| 320 | + ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s | |
| 321 | + | |
| 322 | + ORDER BY term.term_id DESC | |
| 323 | + LIMIT %d | |
| 324 | + ", | |
| 325 | + $course_taxonomy, | |
| 326 | + $limit | |
| 327 | + ) | |
| 369 | 328 | ); |
| 370 | 329 | |
| 371 | - $course_cats = get_terms( $term_args ); | |
| 330 | + $all_cats = $wpdb->get_var( | |
| 331 | + $wpdb->prepare( | |
| 332 | + "SELECT | |
| 333 | + COUNT(*) as total | |
| 334 | + FROM {$wpdb->terms} AS term | |
| 335 | + INNER JOIN {$wpdb->term_taxonomy} AS taxonomy | |
| 336 | + ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s | |
| 337 | + ORDER BY term.term_id DESC | |
| 338 | + ", | |
| 339 | + $course_taxonomy | |
| 340 | + ) | |
| 341 | + ); | |
| 372 | 342 | |
| 373 | 343 | $attributes = $payload; |
| 374 | 344 | unset( $attributes['instructors'] ); |
| 375 | 345 | |
| @@ -376,8 +346,9 @@ | ||
| 376 | 346 | $payload = array( |
| 377 | 347 | 'show_filter' => $show_filter, |
| 378 | 348 | 'content' => $content, |
| 379 | 349 | 'categories' => $course_cats, |
| 350 | + 'all_cats' => $all_cats, | |
| 380 | 351 | 'attributes' => array_merge( $atts, $attributes ), |
| 381 | 352 | ); |
| 382 | 353 | |
| 383 | 354 | ob_start(); |
| @@ -402,9 +373,9 @@ | ||
| 402 | 373 | global $wpdb; |
| 403 | 374 | tutor_utils()->checking_nonce(); |
| 404 | 375 | $term_id = Input::post( 'term_id', 0, Input::TYPE_INT ); |
| 405 | 376 | $limit = 8; |
| 406 | - $course_taxonomy = CourseModel::COURSE_CATEGORY; | |
| 377 | + $course_taxonomy = 'course-category'; | |
| 407 | 378 | |
| 408 | 379 | $remaining_categories = $wpdb->get_var( |
| 409 | 380 | $wpdb->prepare( |
| 410 | 381 | "SElECT |
| @@ -466,9 +437,9 @@ | ||
| 466 | 437 | |
| 467 | 438 | $category = (array) tutor_utils()->array_get( 'category', $_post, array() ); |
| 468 | 439 | $category = array_filter( |
| 469 | 440 | $category, |
| 470 | - function ( $cat ) { | |
| 441 | + function( $cat ) { | |
| 471 | 442 | return is_numeric( $cat ); |
| 472 | 443 | } |
| 473 | 444 | ); |
| 474 | 445 | |
| @@ -480,29 +451,14 @@ | ||
| 480 | 451 | exit; |
| 481 | 452 | } |
| 482 | 453 | |
| 483 | 454 | /** |
| 484 | - * Tutor Cart Shortcode | |
| 455 | + * Show layout selection dashboard in instructor setting | |
| 485 | 456 | * |
| 486 | - * @since v.3.0.0 | |
| 457 | + * @since 1.0.0 | |
| 487 | 458 | * |
| 488 | - * @return mixed | |
| 459 | + * @return void | |
| 489 | 460 | */ |
| 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() ); | |
| 461 | + public function tutor_instructor_layout() { | |
| 462 | + tutor_load_template( 'instructor-setting', array( 'templates' => $this->instructor_layout ) ); | |
| 507 | 463 | } |
| 508 | 464 | } |