| @@ -15,13 +15,13 @@ | ||
| 15 | 15 | |
| 16 | 16 | class Shortcode { |
| 17 | 17 | |
| 18 | 18 | private $instructor_layout = array( |
| 19 | - 'pp-top-full', | |
| 20 | - 'pp-cp', | |
| 21 | - 'pp-top-left', | |
| 22 | - 'pp-left-middle', | |
| 23 | - 'pp-left-full', | |
| 19 | + 'default', | |
| 20 | + 'cover', | |
| 21 | + 'minimal', | |
| 22 | + 'portrait-horizontal', | |
| 23 | + 'minimal-horizontal', | |
| 24 | 24 | ); |
| 25 | 25 | |
| 26 | 26 | public function __construct() { |
| 27 | 27 | add_shortcode( 'tutor_student_registration_form', array( $this, 'student_registration_form' ) ); |
| @@ -28,14 +28,8 @@ | ||
| 28 | 28 | add_shortcode( 'tutor_dashboard', array( $this, 'tutor_dashboard' ) ); |
| 29 | 29 | add_shortcode( 'tutor_instructor_registration_form', array( $this, 'instructor_registration_form' ) ); |
| 30 | 30 | add_shortcode( 'tutor_course', array( $this, 'tutor_course' ) ); |
| 31 | 31 | |
| 32 | - // Check if WP version is equal to or greater than 5.9. | |
| 33 | - global $wp_version; | |
| 34 | - if ( version_compare( $wp_version, '5.9', '>=' ) && function_exists( 'wp_is_block_theme' ) && wp_is_block_theme() ) { | |
| 35 | - add_shortcode( 'tutor_dashboard_menu', array( $this, 'tutor_dashboard_menu' ) ); | |
| 36 | - } | |
| 37 | - | |
| 38 | 32 | add_shortcode( 'tutor_instructor_list', array( $this, 'tutor_instructor_list' ) ); |
| 39 | 33 | add_action( 'tutor_options_after_instructors', array( $this, 'tutor_instructor_layout' ) ); |
| 40 | 34 | add_action( 'wp_ajax_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) ); |
| 41 | 35 | add_action( 'wp_ajax_nopriv_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) ); |
| @@ -110,23 +104,8 @@ | ||
| 110 | 104 | return apply_filters( 'tutor_dashboard/student/index', ob_get_clean() ); |
| 111 | 105 | } |
| 112 | 106 | |
| 113 | 107 | /** |
| 114 | - * @return mixed | |
| 115 | - * | |
| 116 | - * Dashboard Menu Shortcode | |
| 117 | - * | |
| 118 | - * @since v.2.0.0 | |
| 119 | - */ | |
| 120 | - public function tutor_dashboard_menu() { | |
| 121 | - ob_start(); | |
| 122 | - if ( is_user_logged_in() ) { | |
| 123 | - tutor_load_template( 'dashboard.dashboard-menu' ); | |
| 124 | - } | |
| 125 | - return apply_filters( 'tutor_dashboard/header/menu', ob_get_clean() ); | |
| 126 | - } | |
| 127 | - | |
| 128 | - /** | |
| 129 | 108 | * @param $atts |
| 130 | 109 | * |
| 131 | 110 | * @return string |
| 132 | 111 | * |
| @@ -176,22 +155,23 @@ | ||
| 176 | 155 | $a['posts_per_page'] = (int) $a['count']; |
| 177 | 156 | |
| 178 | 157 | wp_reset_query(); |
| 179 | 158 | $the_query = new \WP_Query( $a ); |
| 159 | + | |
| 160 | + | |
| 161 | + // Load the renderer now | |
| 180 | 162 | ob_start(); |
| 163 | + tutor_load_template('archive-course-init', array( | |
| 164 | + 'course_filter' => isset( $atts['course_filter'] ) && $atts['course_filter'] == 'on', | |
| 165 | + 'supported_filters' => tutor_utils()->get_option( 'supported_course_filters', array() ), | |
| 166 | + 'loop_content_only' => false, | |
| 167 | + 'column_per_row' => isset( $atts['column_per_row'] ) ? $atts['column_per_row'] : null, | |
| 168 | + 'course_per_page' => $a['posts_per_page'], | |
| 169 | + 'show_pagination' => isset( $atts['show_pagination'] ) && $atts['show_pagination']=='on', | |
| 170 | + 'the_query' => $the_query | |
| 171 | + )); | |
| 172 | + $output = ob_get_clean(); | |
| 181 | 173 | |
| 182 | - $GLOBALS['the_custom_query'] = $the_query; | |
| 183 | - | |
| 184 | - $GLOBALS['tutor_shortcode_arg'] = array( | |
| 185 | - 'shortcode_enabled' => true, | |
| 186 | - 'include_course_filter' => isset( $atts['course_filter'] ) ? $atts['course_filter'] === 'on' : null, | |
| 187 | - 'column_per_row' => isset( $atts['column_per_row'] ) ? $atts['column_per_row'] : null, | |
| 188 | - 'course_per_page' => $a['posts_per_page'], | |
| 189 | - 'show_pagination' => isset( $atts['show_pagination'] ) ? $atts['show_pagination'] : 'off', | |
| 190 | - ); | |
| 191 | - | |
| 192 | - tutor_load_template( 'shortcode.tutor-course' ); | |
| 193 | - $output = ob_get_clean(); | |
| 194 | 174 | wp_reset_postdata(); |
| 195 | 175 | |
| 196 | 176 | return $output; |
| 197 | 177 | } |
| @@ -197,11 +177,13 @@ | ||
| 197 | 177 | } |
| 198 | 178 | |
| 199 | 179 | private function prepare_instructor_list( $current_page, $atts, $cat_ids = array(), $keyword = '' ) { |
| 200 | 180 | |
| 201 | - $limit = (int) sanitize_text_field( tutor_utils()->array_get( 'count', $atts, 9 ) ); | |
| 181 | + $default_pagination = tutor_utils()->get_option('pagination_per_page', 9); | |
| 182 | + $limit = (int) sanitize_text_field( tutor_utils()->array_get( 'count', $atts, $default_pagination ) ); | |
| 202 | 183 | $page = $current_page - 1; |
| 203 | 184 | $rating_filter = isset( $_POST['rating_filter'] ) ? $_POST['rating_filter'] : ''; |
| 185 | + | |
| 204 | 186 | /** |
| 205 | 187 | * Short by Relevant | New | Popular |
| 206 | 188 | * |
| 207 | 189 | * @since v2.0.0 |
| @@ -214,24 +196,22 @@ | ||
| 214 | 196 | } else { |
| 215 | 197 | $short_by = 'ASC'; |
| 216 | 198 | } |
| 217 | 199 | $instructors = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter ); |
| 218 | - $next_instructors = tutor_utils()->get_instructors( $limit * $current_page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter ); | |
| 200 | + $instructors_count = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter, true ); | |
| 219 | 201 | |
| 220 | - $previous_page = $page > 0 ? $current_page - 1 : null; | |
| 221 | - $next_page = ( is_array( $next_instructors ) && count( $next_instructors ) > 0 ) ? $current_page + 1 : null; | |
| 222 | - | |
| 223 | 202 | $layout = sanitize_text_field( tutor_utils()->array_get( 'layout', $atts, '' ) ); |
| 224 | 203 | $layout = in_array( $layout, $this->instructor_layout ) ? $layout : tutor_utils()->get_option( 'instructor_list_layout', $this->instructor_layout[0] ); |
| 204 | + $default_col = tutor_utils()->get_option( 'courses_col_per_row', 3 ); | |
| 225 | 205 | |
| 226 | 206 | $payload = array( |
| 227 | 207 | 'instructors' => is_array( $instructors ) ? $instructors : array(), |
| 228 | - 'next_page' => $next_page, | |
| 229 | - 'previous_page' => $previous_page, | |
| 230 | - 'column_count' => sanitize_text_field( tutor_utils()->array_get( 'column_per_row', $atts, 3 ) ), | |
| 208 | + 'instructors_count' => $instructors_count, | |
| 209 | + 'column_count' => sanitize_text_field( tutor_utils()->array_get( 'column_per_row', $atts, $default_col ) ), | |
| 231 | 210 | 'layout' => $layout, |
| 232 | 211 | 'limit' => $limit, |
| 233 | 212 | 'current_page' => $current_page, |
| 213 | + 'filter' => $atts | |
| 234 | 214 | ); |
| 235 | 215 | |
| 236 | 216 | return $payload; |
| 237 | 217 | } |
| @@ -250,8 +230,9 @@ | ||
| 250 | 230 | $current_page = (int) tutor_utils()->array_get( 'instructor-page', $_GET, 1 ); |
| 251 | 231 | $current_page = $current_page >= 1 ? $current_page : 1; |
| 252 | 232 | |
| 253 | 233 | $show_filter = isset( $atts['filter'] ) ? $atts['filter'] == 'on' : tutor_utils()->get_option( 'instructor_list_show_filter', false ); |
| 234 | + $atts['show_filter'] = $show_filter; | |
| 254 | 235 | |
| 255 | 236 | // Get instructor list to sow |
| 256 | 237 | $payload = $this->prepare_instructor_list( $current_page, $atts ); |
| 257 | 238 | $payload['show_filter'] = $show_filter; |
| @@ -274,13 +255,12 @@ | ||
| 274 | 255 | )); |
| 275 | 256 | |
| 276 | 257 | $all_cats = $wpdb->get_var( |
| 277 | 258 | $wpdb->prepare( |
| 278 | - " SElECT COUNT(*) as total FROM {$wpdb->terms} AS term | |
| 259 | + "SELECT COUNT(*) as total FROM {$wpdb->terms} AS term | |
| 279 | 260 | INNER JOIN {$wpdb->term_taxonomy} AS taxonomy |
| 280 | 261 | ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s |
| 281 | - ORDER BY term.term_id DESC | |
| 282 | - ", | |
| 262 | + ORDER BY term.term_id DESC", | |
| 283 | 263 | $course_taxonomy |
| 284 | 264 | ) |
| 285 | 265 | ); |
| 286 | 266 | |
| @@ -366,10 +346,9 @@ | ||
| 366 | 346 | public function load_filtered_instructor() { |
| 367 | 347 | tutor_utils()->checking_nonce(); |
| 368 | 348 | |
| 369 | 349 | $_post = tutor_sanitize_data($_POST); |
| 370 | - $attributes = (array) tutor_utils()->array_get( 'attributes', $_post, array() ); | |
| 371 | - $current_page = (int) sanitize_text_field( tutor_utils()->array_get( 'current_page', $attributes, 1 ) ); | |
| 350 | + $current_page = (int) sanitize_text_field( tutor_utils()->array_get( 'current_page', $_post, 1 ) ); | |
| 372 | 351 | $keyword = (string) sanitize_text_field( tutor_utils()->array_get( 'keyword', $_post, '' ) ); |
| 373 | 352 | |
| 374 | 353 | $category = (array) tutor_utils()->array_get( 'category', $_post, array() ); |
| 375 | 354 | $category = array_filter( |
| @@ -378,11 +357,13 @@ | ||
| 378 | 357 | return is_numeric( $cat ); |
| 379 | 358 | } |
| 380 | 359 | ); |
| 381 | 360 | |
| 382 | - $payload = $this->prepare_instructor_list( $current_page, $attributes, $category, $keyword ); | |
| 361 | + $data = $this->prepare_instructor_list( $current_page, $_post, $category, $keyword ); | |
| 383 | 362 | |
| 384 | - tutor_load_template( 'shortcode.tutor-instructor', $payload ); | |
| 363 | + ob_start(); | |
| 364 | + tutor_load_template( 'shortcode.tutor-instructor', $data ); | |
| 365 | + wp_send_json_success( array('html' => ob_get_clean() ) ); | |
| 385 | 366 | exit; |
| 386 | 367 | } |
| 387 | 368 | |
| 388 | 369 | /** |