| @@ -1,390 +1,239 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Manage short codes | |
| 3 | + * Class Shortcode | |
| 4 | + * @package TUTOR | |
| 4 | 5 | * |
| 5 | - * @package Tutor\ShortCode | |
| 6 | - * @author Themeum <support@themeum.com> | |
| 7 | - * @link https://themeum.com | |
| 8 | - * @since 1.0.0 | |
| 6 | + * @since v.1.0.0 | |
| 9 | 7 | */ |
| 10 | 8 | |
| 11 | 9 | namespace TUTOR; |
| 12 | 10 | |
| 13 | -use Tutor\Models\CourseModel; | |
| 14 | - | |
| 15 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 11 | +if (!defined('ABSPATH')) | |
| 16 | 12 | exit; |
| 17 | -} | |
| 18 | 13 | |
| 19 | -/** | |
| 20 | - * Short code class | |
| 21 | - * | |
| 22 | - * @since 1.0.0 | |
| 23 | - */ | |
| 24 | 14 | class Shortcode { |
| 25 | 15 | |
| 26 | - /** | |
| 27 | - * Instructor page design layouts | |
| 28 | - * | |
| 29 | - * @since 1.0.0 | |
| 30 | - * | |
| 31 | - * @var array | |
| 32 | - */ | |
| 33 | 16 | private $instructor_layout = array( |
| 34 | - 'default', | |
| 35 | - 'cover', | |
| 36 | - 'minimal', | |
| 37 | - 'portrait-horizontal', | |
| 38 | - 'minimal-horizontal', | |
| 17 | + 'pp-top-full', | |
| 18 | + 'pp-cp', | |
| 19 | + 'pp-top-left', | |
| 20 | + 'pp-left-middle', | |
| 21 | + 'pp-left-full' | |
| 39 | 22 | ); |
| 23 | + | |
| 24 | + public function __construct() { | |
| 25 | + add_shortcode('tutor_student_registration_form', array($this, 'student_registration_form')); | |
| 26 | + add_shortcode('tutor_dashboard', array($this, 'tutor_dashboard')); | |
| 27 | + add_shortcode('tutor_instructor_registration_form', array($this, 'instructor_registration_form')); | |
| 28 | + add_shortcode('tutor_course', array($this, 'tutor_course')); | |
| 40 | 29 | |
| 41 | - /** | |
| 42 | - * Register hooks | |
| 43 | - * | |
| 44 | - * @since 1.0.0 | |
| 45 | - * @since 3.8.0 | |
| 46 | - * | |
| 47 | - * @param bool $register_hooks register hooks or not. | |
| 48 | - * | |
| 49 | - * @return void | |
| 50 | - */ | |
| 51 | - public function __construct( $register_hooks = true ) { | |
| 52 | - if ( ! $register_hooks ) { | |
| 53 | - return; | |
| 54 | - } | |
| 55 | - | |
| 56 | - add_shortcode( 'tutor_student_registration_form', array( $this, 'student_registration_form' ) ); | |
| 57 | - add_shortcode( 'tutor_dashboard', array( $this, 'tutor_dashboard' ) ); | |
| 58 | - add_shortcode( 'tutor_instructor_registration_form', array( $this, 'instructor_registration_form' ) ); | |
| 59 | - add_shortcode( 'tutor_course', array( $this, 'tutor_course' ) ); | |
| 60 | - | |
| 61 | - add_shortcode( 'tutor_instructor_list', array( $this, 'tutor_instructor_list' ) ); | |
| 62 | - add_action( 'wp_ajax_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) ); | |
| 63 | - add_action( 'wp_ajax_nopriv_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) ); | |
| 64 | - | |
| 65 | - add_shortcode( 'tutor_cart', array( $this, 'tutor_cart_page' ) ); | |
| 66 | - add_shortcode( 'tutor_checkout', array( $this, 'tutor_checkout_page' ) ); | |
| 67 | - | |
| 68 | - /** | |
| 69 | - * Load more categories | |
| 70 | - * | |
| 71 | - * @since 2.0.0 | |
| 72 | - */ | |
| 73 | - add_action( 'wp_ajax_show_more', array( $this, 'show_more' ) ); | |
| 74 | - add_action( 'wp_ajax_nopriv_show_more', array( $this, 'show_more' ) ); | |
| 30 | + add_shortcode('tutor_instructor_list', array($this, 'tutor_instructor_list')); | |
| 31 | + add_action('tutor_options_after_instructors', array($this, 'tutor_instructor_layout')); | |
| 32 | + add_action( 'wp_ajax_load_filtered_instructor', array($this, 'load_filtered_instructor') ); | |
| 33 | + add_action( 'wp_ajax_nopriv_load_filtered_instructor', array($this, 'load_filtered_instructor') ); | |
| 75 | 34 | } |
| 76 | 35 | |
| 77 | 36 | /** |
| 78 | - * Instructor Registration Shortcode | |
| 37 | + * @return mixed | |
| 79 | 38 | * |
| 80 | - * @since 1.0.0 | |
| 39 | + * Instructor Registration Shortcode | |
| 81 | 40 | * |
| 82 | - * @return mixed | |
| 41 | + * @since v.1.0.0 | |
| 83 | 42 | */ |
| 84 | 43 | public function student_registration_form() { |
| 85 | 44 | ob_start(); |
| 86 | - if ( is_user_logged_in() ) { | |
| 87 | - tutor_load_template( 'dashboard.logged-in' ); | |
| 45 | + if (is_user_logged_in()) { | |
| 46 | + tutor_load_template('dashboard.logged-in'); | |
| 88 | 47 | } else { |
| 89 | - tutor_load_template( 'dashboard.registration' ); | |
| 48 | + tutor_load_template('dashboard.registration'); | |
| 90 | 49 | } |
| 91 | - return apply_filters( 'tutor/student/register', ob_get_clean() ); | |
| 50 | + return apply_filters('tutor/student/register', ob_get_clean()); | |
| 92 | 51 | } |
| 93 | 52 | |
| 94 | 53 | /** |
| 54 | + * @return mixed | |
| 55 | + * | |
| 95 | 56 | * Tutor Dashboard for students |
| 96 | 57 | * |
| 97 | - * @since 1.0.0 | |
| 98 | - * | |
| 99 | - * @return mixed | |
| 58 | + * @since v.1.0.0 | |
| 100 | 59 | */ |
| 101 | 60 | public function tutor_dashboard() { |
| 102 | 61 | global $wp_query; |
| 103 | 62 | |
| 104 | 63 | ob_start(); |
| 105 | - if ( is_user_logged_in() ) { | |
| 64 | + if (is_user_logged_in()) { | |
| 106 | 65 | /** |
| 107 | 66 | * Added isset() Condition to avoid infinite loop since v.1.5.4 |
| 108 | 67 | * This has cause error by others plugin, Such AS SEO |
| 109 | 68 | */ |
| 110 | 69 | |
| 111 | - if ( ! isset( $wp_query->query_vars['tutor_dashboard_page'] ) ) { | |
| 112 | - tutor_load_template( 'dashboard', array( 'is_shortcode' => true ) ); | |
| 70 | + if (!isset($wp_query->query_vars['tutor_dashboard_page'])) { | |
| 71 | + tutor_load_template('dashboard', array('is_shortcode' => true)); | |
| 113 | 72 | } |
| 114 | 73 | } else { |
| 115 | - /** | |
| 116 | - * If user not logged in show login form instead of | |
| 117 | - * popup sign-in button | |
| 118 | - * | |
| 119 | - * @since 2.1.3 | |
| 120 | - */ | |
| 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 | |
| 74 | + tutor_load_template('global.login'); | |
| 125 | 75 | } |
| 126 | - return apply_filters( 'tutor_dashboard/index', ob_get_clean() ); | |
| 76 | + return apply_filters('tutor_dashboard/index', ob_get_clean()); | |
| 127 | 77 | } |
| 128 | 78 | |
| 129 | 79 | /** |
| 80 | + * @return mixed | |
| 81 | + * | |
| 130 | 82 | * Instructor Registration Shortcode |
| 131 | 83 | * |
| 132 | 84 | * @since v.1.0.0 |
| 133 | - * | |
| 134 | - * @return mixed | |
| 135 | 85 | */ |
| 136 | 86 | public function instructor_registration_form() { |
| 137 | 87 | ob_start(); |
| 138 | - if ( is_user_logged_in() ) { | |
| 139 | - tutor_load_template( 'dashboard.instructor.logged-in' ); | |
| 88 | + if (is_user_logged_in()) { | |
| 89 | + tutor_load_template('dashboard.instructor.logged-in'); | |
| 140 | 90 | } else { |
| 141 | - tutor_load_template( 'dashboard.instructor.registration' ); | |
| 91 | + tutor_load_template('dashboard.instructor.registration'); | |
| 142 | 92 | } |
| 143 | - return apply_filters( 'tutor_dashboard/student/index', ob_get_clean() ); | |
| 93 | + return apply_filters('tutor_dashboard/student/index', ob_get_clean()); | |
| 144 | 94 | } |
| 145 | 95 | |
| 146 | 96 | /** |
| 147 | - * Short code for getting course | |
| 97 | + * @param $atts | |
| 148 | 98 | * |
| 149 | - * @since 1.0.0 | |
| 99 | + * @return string | |
| 150 | 100 | * |
| 151 | - * @param mixed $atts attributes. | |
| 152 | - * | |
| 153 | - * @return string | |
| 101 | + * Shortcode for getting course | |
| 154 | 102 | */ |
| 155 | - public function tutor_course( $atts ) { | |
| 156 | - $a = shortcode_atts( | |
| 157 | - array( | |
| 158 | - 'post_type' => apply_filters( 'tutor_course_archive_post_types', array( tutor()->course_post_type ) ), | |
| 159 | - 'post_status' => 'publish', | |
| 103 | + public function tutor_course($atts) { | |
| 104 | + $course_post_type = tutor()->course_post_type; | |
| 160 | 105 | |
| 161 | - 'id' => '', | |
| 162 | - 'exclude_ids' => '', | |
| 163 | - 'category' => '', | |
| 106 | + $a = shortcode_atts(array( | |
| 107 | + 'post_type' => $course_post_type, | |
| 108 | + 'post_status' => 'publish', | |
| 164 | 109 | |
| 165 | - 'orderby' => 'ID', | |
| 166 | - 'order' => 'DESC', | |
| 167 | - 'count' => tutils()->get_option( 'courses_per_page', 12 ), | |
| 168 | - 'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1, | |
| 169 | - ), | |
| 170 | - $atts | |
| 171 | - ); | |
| 110 | + 'id' => '', | |
| 111 | + 'exclude_ids' => '', | |
| 112 | + 'category' => '', | |
| 172 | 113 | |
| 173 | - $a = apply_filters( 'tutor_get_course_list_filter_args', $a ); | |
| 114 | + 'orderby' => 'ID', | |
| 115 | + 'order' => 'DESC', | |
| 116 | + 'count' => 6, | |
| 117 | + 'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1, | |
| 118 | + ), $atts); | |
| 174 | 119 | |
| 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 | - if ( ! empty( $a['id'] ) ) { | |
| 181 | - $ids = (array) explode( ',', $a['id'] ); | |
| 120 | + if (!empty($a['id'])) { | |
| 121 | + $ids = (array) explode(',', $a['id']); | |
| 182 | 122 | $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 | 123 | } |
| 189 | 124 | |
| 190 | - if ( ! empty( $a['exclude_ids'] ) ) { | |
| 191 | - $exclude_ids = (array) explode( ',', $a['exclude_ids'] ); | |
| 125 | + if (!empty($a['exclude_ids'])) { | |
| 126 | + $exclude_ids = (array) explode(',', $a['exclude_ids']); | |
| 192 | 127 | $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 | 128 | } |
| 198 | - if ( ! empty( $a['category'] ) ) { | |
| 199 | - $category = (array) explode( ',', $a['category'] ); | |
| 129 | + if (!empty($a['category'])) { | |
| 130 | + $category = (array) explode(',', $a['category']); | |
| 200 | 131 | |
| 201 | - $a['tax_query'] = array(); | |
| 202 | - | |
| 203 | - $category_ids = array_filter( | |
| 204 | - $category, | |
| 205 | - function ( $id ) { | |
| 206 | - return is_numeric( $id ); | |
| 207 | - } | |
| 132 | + $a['tax_query'] = array( | |
| 133 | + array( | |
| 134 | + 'taxonomy' => 'course-category', | |
| 135 | + 'field' => 'term_id', | |
| 136 | + 'terms' => $category, | |
| 137 | + 'operator' => 'IN', | |
| 138 | + ), | |
| 208 | 139 | ); |
| 209 | - | |
| 210 | - $category_names = array_filter( | |
| 211 | - $category, | |
| 212 | - function ( $id ) { | |
| 213 | - return ! is_numeric( $id ); | |
| 214 | - } | |
| 215 | - ); | |
| 216 | - | |
| 217 | - if ( ! empty( $category_ids ) ) { | |
| 218 | - $a['tax_query'] = array( | |
| 219 | - array( | |
| 220 | - 'taxonomy' => CourseModel::COURSE_CATEGORY, | |
| 221 | - 'field' => 'term_id', | |
| 222 | - 'terms' => $category_ids, | |
| 223 | - 'operator' => 'IN', | |
| 224 | - ), | |
| 225 | - ); | |
| 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 | - } | |
| 233 | - | |
| 234 | - if ( ! empty( $category_names ) ) { | |
| 235 | - $a['tax_query'] = array( | |
| 236 | - array( | |
| 237 | - 'taxonomy' => CourseModel::COURSE_CATEGORY, | |
| 238 | - 'field' => 'name', | |
| 239 | - 'terms' => $category_names, | |
| 240 | - 'operator' => 'IN', | |
| 241 | - ), | |
| 242 | - ); | |
| 243 | - } | |
| 244 | 140 | } |
| 245 | 141 | $a['posts_per_page'] = (int) $a['count']; |
| 246 | 142 | |
| 247 | 143 | wp_reset_query(); |
| 248 | 144 | $the_query = new \WP_Query( $a ); |
| 145 | + ob_start(); | |
| 249 | 146 | |
| 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 | - } | |
| 147 | + $GLOBALS['the_custom_query'] = $the_query; | |
| 260 | 148 | |
| 261 | - // Load the renderer now. | |
| 262 | - ob_start(); | |
| 149 | + $GLOBALS['tutor_shortcode_arg'] = array( | |
| 150 | + 'include_course_filter' => isset($atts['course_filter']) ? $atts['course_filter'] === 'on' : null, | |
| 151 | + 'column_per_row' => isset($atts['column_per_row']) ? $atts['column_per_row'] : null, | |
| 152 | + 'course_per_page' => $a['posts_per_page'], | |
| 153 | + 'show_pagination' => isset( $atts['show_pagination'] ) ? $atts['show_pagination'] : 'off', | |
| 154 | + ); | |
| 263 | 155 | |
| 264 | - if ( $the_query->have_posts() ) { | |
| 265 | - tutor_load_template( | |
| 266 | - 'archive-course-init', | |
| 267 | - 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, | |
| 279 | - ) | |
| 280 | - ); | |
| 281 | - } else { | |
| 282 | - tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() ); | |
| 283 | - } | |
| 284 | - | |
| 156 | + tutor_load_template('shortcode.tutor-course'); | |
| 285 | 157 | $output = ob_get_clean(); |
| 286 | 158 | wp_reset_postdata(); |
| 159 | + | |
| 287 | 160 | return $output; |
| 288 | 161 | } |
| 289 | 162 | |
| 290 | - /** | |
| 291 | - * Prepare instructor list | |
| 292 | - * | |
| 293 | - * @param string $current_page current page. | |
| 294 | - * @param mixed $atts atts for query. | |
| 295 | - * @param array $cat_ids category ids. | |
| 296 | - * @param string $keyword search keyword. | |
| 297 | - * | |
| 298 | - * @return array | |
| 299 | - */ | |
| 300 | - private function prepare_instructor_list( $current_page, $atts, $cat_ids = array(), $keyword = '' ) { | |
| 163 | + private function prepare_instructor_list($current_page, $atts, $cat_ids = array(), $keyword = '') { | |
| 301 | 164 | |
| 302 | - $default_pagination = tutor_utils()->get_option( 'pagination_per_page', 9 ); | |
| 303 | - $limit = (int) sanitize_text_field( tutor_utils()->array_get( 'count', $atts, $default_pagination ) ); | |
| 304 | - $page = $current_page - 1; | |
| 305 | - $rating_filter = Input::post( 'rating_filter', '' ); | |
| 165 | + $limit = (int)sanitize_text_field(tutils()->array_get('count', $atts, 9)); | |
| 166 | + $page = $current_page - 1; | |
| 306 | 167 | |
| 307 | - /** | |
| 308 | - * Sort by Relevant | New | Popular | |
| 309 | - * | |
| 310 | - * @since 2.0.0 | |
| 311 | - */ | |
| 312 | - $short_by = Input::post( 'short_by', 'ASC' ); | |
| 168 | + $instructors = tutor_utils()->get_instructors($limit*$page, $limit, $keyword, '', '', '', 'approved', $cat_ids); | |
| 169 | + $next_instructors = tutor_utils()->get_instructors($limit*$current_page, $limit, $keyword, '', '', '', 'approved', $cat_ids); | |
| 313 | 170 | |
| 314 | - $instructors = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter ); | |
| 315 | - $instructors_count = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter, true ); | |
| 171 | + $previous_page = $page>0 ? $current_page-1 : null; | |
| 172 | + $next_page = (is_array($next_instructors) && count($next_instructors)>0) ? $current_page+1 : null; | |
| 173 | + | |
| 174 | + $layout = sanitize_text_field(tutils()->array_get('layout', $atts, '')); | |
| 175 | + $layout = in_array($layout, $this->instructor_layout) ? $layout : tutor_utils()->get_option('instructor_list_layout', $this->instructor_layout[0]); | |
| 316 | 176 | |
| 317 | - $layout = sanitize_text_field( tutor_utils()->array_get( 'layout', $atts, '' ) ); | |
| 318 | - $layout = in_array( $layout, $this->instructor_layout ) ? $layout : tutor_utils()->get_option( 'instructor_list_layout', $this->instructor_layout[0] ); | |
| 319 | - $default_col = tutor_utils()->get_option( 'courses_col_per_row', 3 ); | |
| 320 | - | |
| 321 | - $payload = array( | |
| 322 | - 'instructors' => is_array( $instructors ) ? $instructors : array(), | |
| 323 | - 'instructors_count' => $instructors_count, | |
| 324 | - 'column_count' => sanitize_text_field( tutor_utils()->array_get( 'column_per_row', $atts, $default_col ) ), | |
| 325 | - 'layout' => $layout, | |
| 326 | - 'limit' => $limit, | |
| 327 | - 'current_page' => $current_page, | |
| 328 | - 'filter' => $atts, | |
| 177 | + $payload=array( | |
| 178 | + 'instructors' => is_array($instructors) ? $instructors : array(), | |
| 179 | + 'next_page' => $next_page, | |
| 180 | + 'previous_page' => $previous_page, | |
| 181 | + 'column_count' => sanitize_text_field(tutils()->array_get('column_per_row', $atts, 3)), | |
| 182 | + 'layout' => $layout, | |
| 183 | + 'limit' => $limit, | |
| 184 | + 'current_page' => $current_page | |
| 329 | 185 | ); |
| 330 | 186 | |
| 331 | 187 | return $payload; |
| 332 | 188 | } |
| 333 | - | |
| 189 | + | |
| 334 | 190 | /** |
| 335 | - * Short code for getting instructors | |
| 191 | + * @param $atts | |
| 336 | 192 | * |
| 337 | - * @param array $atts array of attrs. | |
| 193 | + * @return string | |
| 338 | 194 | * |
| 339 | - * @return string | |
| 195 | + * Shortcode for getting instructors | |
| 340 | 196 | */ |
| 341 | - public function tutor_instructor_list( $atts ) { | |
| 342 | - ! is_array( $atts ) ? $atts = array() : 0; | |
| 197 | + public function tutor_instructor_list($atts) { | |
| 343 | 198 | |
| 344 | - $current_page = (int) tutor_utils()->array_get( 'instructor-page', $_GET, 1 ); | |
| 345 | - $current_page = Input::get( 'instructor-page', 1, Input::TYPE_INT ); | |
| 346 | - $current_page = $current_page >= 1 ? $current_page : 1; | |
| 199 | + !is_array( $atts ) ? $atts = array() : 0; | |
| 347 | 200 | |
| 348 | - $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 | - $atts['show_filter'] = $show_filter; | |
| 352 | - | |
| 353 | - // Get instructor list to sow. | |
| 354 | - $payload = $this->prepare_instructor_list( $current_page, $atts ); | |
| 201 | + $current_page = (int)tutor_utils()->array_get('instructor-page', $_GET, 1); | |
| 202 | + $current_page = $current_page>=1 ? $current_page : 1; | |
| 203 | + | |
| 204 | + $show_filter = isset( $atts['filter'] ) ? $atts['filter']=='on' : tutor_utils()->get_option( 'instructor_list_show_filter', false ); | |
| 205 | + | |
| 206 | + // Get instructor list to sow | |
| 207 | + $payload = $this->prepare_instructor_list($current_page, $atts); | |
| 355 | 208 | $payload['show_filter'] = $show_filter; |
| 356 | 209 | |
| 357 | 210 | ob_start(); |
| 358 | - tutor_load_template( 'shortcode.tutor-instructor', $payload ); | |
| 211 | + tutor_load_template('shortcode.tutor-instructor', $payload); | |
| 359 | 212 | $content = ob_get_clean(); |
| 360 | 213 | |
| 361 | - 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, | |
| 369 | - ); | |
| 214 | + if($show_filter) { | |
| 215 | + | |
| 216 | + $course_cats = get_terms( array( | |
| 217 | + 'taxonomy' => 'course-category', | |
| 218 | + 'hide_empty' => true, | |
| 219 | + 'childless' => true | |
| 220 | + ) ); | |
| 370 | 221 | |
| 371 | - $course_cats = get_terms( $term_args ); | |
| 372 | - | |
| 373 | 222 | $attributes = $payload; |
| 374 | 223 | unset( $attributes['instructors'] ); |
| 375 | 224 | |
| 376 | - $payload = array( | |
| 225 | + $payload = array( | |
| 377 | 226 | 'show_filter' => $show_filter, |
| 378 | - 'content' => $content, | |
| 379 | - 'categories' => $course_cats, | |
| 380 | - 'attributes' => array_merge( $atts, $attributes ), | |
| 227 | + 'content' => $content, | |
| 228 | + 'categories' => $course_cats, | |
| 229 | + 'attributes' => array_merge( $atts, $attributes ) | |
| 381 | 230 | ); |
| 382 | 231 | |
| 383 | 232 | ob_start(); |
| 384 | 233 | |
| 385 | - tutor_load_template( 'shortcode.instructor-filter', $payload ); | |
| 386 | - | |
| 234 | + tutor_load_template('shortcode.instructor-filter', $payload); | |
| 235 | + | |
| 387 | 236 | $content = ob_get_clean(); |
| 388 | 237 | } |
| 389 | 238 | |
| 390 | 239 | return $content; |
| @@ -389,120 +238,29 @@ | ||
| 389 | 238 | |
| 390 | 239 | return $content; |
| 391 | 240 | } |
| 392 | 241 | |
| 393 | - /** | |
| 394 | - * Load more categories | |
| 395 | - * handle ajax request | |
| 396 | - * | |
| 397 | - * @since 2.0.0 | |
| 398 | - * | |
| 399 | - * @return void send wp_json response | |
| 400 | - */ | |
| 401 | - public function show_more() { | |
| 402 | - global $wpdb; | |
| 403 | - tutor_utils()->checking_nonce(); | |
| 404 | - $term_id = Input::post( 'term_id', 0, Input::TYPE_INT ); | |
| 405 | - $limit = 8; | |
| 406 | - $course_taxonomy = CourseModel::COURSE_CATEGORY; | |
| 407 | - | |
| 408 | - $remaining_categories = $wpdb->get_var( | |
| 409 | - $wpdb->prepare( | |
| 410 | - "SELECT | |
| 411 | - COUNT(*) AS total | |
| 412 | - FROM {$wpdb->terms} AS term | |
| 413 | - INNER JOIN {$wpdb->term_taxonomy} AS taxonomy | |
| 414 | - ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s | |
| 415 | - WHERE term.term_id < %d | |
| 416 | - ORDER BY term.term_id DESC | |
| 417 | - ", | |
| 418 | - $course_taxonomy, | |
| 419 | - $term_id | |
| 420 | - ) | |
| 421 | - ); | |
| 422 | - | |
| 423 | - $add_categories = $wpdb->get_results( | |
| 424 | - $wpdb->prepare( | |
| 425 | - "SELECT | |
| 426 | - * | |
| 427 | - FROM {$wpdb->terms} term | |
| 428 | - INNER JOIN {$wpdb->term_taxonomy} as taxonomy | |
| 429 | - ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s | |
| 430 | - WHERE term.term_id < %d | |
| 431 | - ORDER BY term.term_id DESC | |
| 432 | - LIMIT %d | |
| 433 | - ", | |
| 434 | - $course_taxonomy, | |
| 435 | - $term_id, | |
| 436 | - $limit | |
| 437 | - ) | |
| 438 | - ); | |
| 439 | - $show_more = false; | |
| 440 | - if ( $remaining_categories > $limit ) { | |
| 441 | - $show_more = true; | |
| 442 | - } | |
| 443 | - $response = array( | |
| 444 | - 'categories' => $add_categories, | |
| 445 | - 'show_more' => $show_more, | |
| 446 | - 'remaining' => $remaining_categories, | |
| 447 | - ); | |
| 448 | - wp_send_json_success( $response ); | |
| 449 | - exit; | |
| 450 | - } | |
| 451 | - | |
| 452 | - /** | |
| 453 | - * Filter instructor | |
| 454 | - * | |
| 455 | - * @since 1.0.0 | |
| 456 | - * | |
| 457 | - * @return void send wp_json response | |
| 458 | - */ | |
| 459 | 242 | public function load_filtered_instructor() { |
| 460 | 243 | tutor_utils()->checking_nonce(); |
| 461 | 244 | |
| 462 | - // phpcs:disable WordPress.Security.NonceVerification.Missing --nonce already verified | |
| 463 | - $_post = tutor_sanitize_data( $_POST ); | |
| 464 | - $current_page = (int) sanitize_text_field( tutor_utils()->array_get( 'current_page', $_post, 1 ) ); | |
| 465 | - $keyword = (string) sanitize_text_field( tutor_utils()->array_get( 'keyword', $_post, '' ) ); | |
| 245 | + $attributes = (array)tutils()->array_get('attributes', $_POST, array()); | |
| 246 | + $current_page = (int)sanitize_text_field(tutils()->array_get('current_page', $attributes, 1)); | |
| 247 | + $keyword = (string)sanitize_text_field(tutils()->array_get('keyword', $_POST, '')); | |
| 466 | 248 | |
| 467 | - $category = (array) tutor_utils()->array_get( 'category', $_post, array() ); | |
| 468 | - $category = array_filter( | |
| 469 | - $category, | |
| 470 | - function ( $cat ) { | |
| 471 | - return is_numeric( $cat ); | |
| 472 | - } | |
| 473 | - ); | |
| 249 | + $category = (array)tutils()->array_get('category', $_POST, array()); | |
| 250 | + $category = array_filter($category, function($cat) { | |
| 251 | + return is_numeric($cat); | |
| 252 | + }); | |
| 474 | 253 | |
| 475 | - $data = $this->prepare_instructor_list( $current_page, $_post, $category, $keyword ); | |
| 254 | + $payload = $this->prepare_instructor_list($current_page, $attributes, $category, $keyword); | |
| 476 | 255 | |
| 477 | - ob_start(); | |
| 478 | - tutor_load_template( 'shortcode.tutor-instructor', $data ); | |
| 479 | - wp_send_json_success( array( 'html' => ob_get_clean() ) ); | |
| 256 | + tutor_load_template('shortcode.tutor-instructor', $payload); | |
| 480 | 257 | exit; |
| 481 | 258 | } |
| 482 | - | |
| 259 | + | |
| 483 | 260 | /** |
| 484 | - * Tutor Cart Shortcode | |
| 485 | - * | |
| 486 | - * @since v.3.0.0 | |
| 487 | - * | |
| 488 | - * @return mixed | |
| 261 | + * Show layout selection dashboard in instructor setting | |
| 489 | 262 | */ |
| 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() ); | |
| 263 | + public function tutor_instructor_layout(){ | |
| 264 | + tutor_load_template('instructor-setting', array('templates'=>$this->instructor_layout)); | |
| 507 | 265 | } |
| 508 | 266 | } |