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