Addons.php
4 years ago
Admin.php
4 years ago
Ajax.php
4 years ago
Announcements.php
4 years ago
Assets.php
4 years ago
Backend_Page_Trait.php
4 years ago
Course.php
4 years ago
Course_Filter.php
4 years ago
Course_List.php
4 years ago
Course_Settings_Tabs.php
4 years ago
Course_Widget.php
4 years ago
Custom_Validation.php
5 years ago
Dashboard.php
4 years ago
FormHandler.php
4 years ago
Frontend.php
4 years ago
Gutenberg.php
4 years ago
Instructor.php
4 years ago
Instructors_List.php
4 years ago
Lesson.php
4 years ago
Options_V2.php
4 years ago
Post_types.php
4 years ago
Private_Course_Access.php
4 years ago
Q_and_A.php
4 years ago
Question_Answers_List.php
4 years ago
Quiz.php
4 years ago
Quiz_Attempts_List.php
4 years ago
RestAPI.php
4 years ago
Reviews.php
4 years ago
Rewrite_Rules.php
4 years ago
Shortcode.php
4 years ago
Student.php
4 years ago
Students_List.php
4 years ago
Taxonomies.php
4 years ago
Template.php
4 years ago
Theme_Compatibility.php
5 years ago
Tools.php
4 years ago
Tools_V2.php
4 years ago
Tutor.php
4 years ago
TutorEDD.php
4 years ago
Tutor_Base.php
5 years ago
Tutor_List_Table.php
4 years ago
Tutor_Setup.php
4 years ago
Upgrader.php
4 years ago
User.php
4 years ago
Utils.php
4 years ago
Video_Stream.php
4 years ago
Withdraw.php
4 years ago
Withdraw_Requests_List.php
4 years ago
WooCommerce.php
4 years ago
Shortcode.php
395 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Class Shortcode |
| 4 | * |
| 5 | * @package TUTOR |
| 6 | * |
| 7 | * @since v.1.0.0 |
| 8 | */ |
| 9 | |
| 10 | namespace TUTOR; |
| 11 | |
| 12 | if ( ! defined( 'ABSPATH' ) ) { |
| 13 | exit; |
| 14 | } |
| 15 | |
| 16 | class Shortcode { |
| 17 | |
| 18 | private $instructor_layout = array( |
| 19 | 'pp-top-full', |
| 20 | 'pp-cp', |
| 21 | 'pp-top-left', |
| 22 | 'pp-left-middle', |
| 23 | 'pp-left-full', |
| 24 | ); |
| 25 | |
| 26 | public function __construct() { |
| 27 | add_shortcode( 'tutor_student_registration_form', array( $this, 'student_registration_form' ) ); |
| 28 | add_shortcode( 'tutor_dashboard', array( $this, 'tutor_dashboard' ) ); |
| 29 | add_shortcode( 'tutor_instructor_registration_form', array( $this, 'instructor_registration_form' ) ); |
| 30 | add_shortcode( 'tutor_course', array( $this, 'tutor_course' ) ); |
| 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 | add_shortcode( 'tutor_instructor_list', array( $this, 'tutor_instructor_list' ) ); |
| 39 | add_action( 'tutor_options_after_instructors', array( $this, 'tutor_instructor_layout' ) ); |
| 40 | add_action( 'wp_ajax_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) ); |
| 41 | add_action( 'wp_ajax_nopriv_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) ); |
| 42 | |
| 43 | /** |
| 44 | * Load more categories |
| 45 | * |
| 46 | * @since 2.0.0 |
| 47 | */ |
| 48 | add_action( 'wp_ajax_show_more', array( $this, 'show_more' ) ); |
| 49 | add_action( 'wp_ajax_nopriv_show_more', array( $this, 'show_more' ) ); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @return mixed |
| 54 | * |
| 55 | * Instructor Registration Shortcode |
| 56 | * |
| 57 | * @since v.1.0.0 |
| 58 | */ |
| 59 | public function student_registration_form() { |
| 60 | ob_start(); |
| 61 | if ( is_user_logged_in() ) { |
| 62 | tutor_load_template( 'dashboard.logged-in' ); |
| 63 | } else { |
| 64 | tutor_load_template( 'dashboard.registration' ); |
| 65 | } |
| 66 | return apply_filters( 'tutor/student/register', ob_get_clean() ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @return mixed |
| 71 | * |
| 72 | * Tutor Dashboard for students |
| 73 | * |
| 74 | * @since v.1.0.0 |
| 75 | */ |
| 76 | public function tutor_dashboard() { |
| 77 | global $wp_query; |
| 78 | |
| 79 | ob_start(); |
| 80 | if ( is_user_logged_in() ) { |
| 81 | /** |
| 82 | * Added isset() Condition to avoid infinite loop since v.1.5.4 |
| 83 | * This has cause error by others plugin, Such AS SEO |
| 84 | */ |
| 85 | |
| 86 | if ( ! isset( $wp_query->query_vars['tutor_dashboard_page'] ) ) { |
| 87 | tutor_load_template( 'dashboard', array( 'is_shortcode' => true ) ); |
| 88 | } |
| 89 | } else { |
| 90 | $login_url = tutor_utils()->get_option('enable_tutor_native_login', null, true, true) ? '' : wp_login_url(tutor()->current_url); |
| 91 | echo sprintf( __('Please %sSign-In%s to view this page', 'tutor'), '<a data-login_url="'.$login_url.'" href="#" class="tutor-open-login-modal">', '</a>'); |
| 92 | } |
| 93 | return apply_filters( 'tutor_dashboard/index', ob_get_clean() ); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @return mixed |
| 98 | * |
| 99 | * Instructor Registration Shortcode |
| 100 | * |
| 101 | * @since v.1.0.0 |
| 102 | */ |
| 103 | public function instructor_registration_form() { |
| 104 | ob_start(); |
| 105 | if ( is_user_logged_in() ) { |
| 106 | tutor_load_template( 'dashboard.instructor.logged-in' ); |
| 107 | } else { |
| 108 | tutor_load_template( 'dashboard.instructor.registration' ); |
| 109 | } |
| 110 | return apply_filters( 'tutor_dashboard/student/index', ob_get_clean() ); |
| 111 | } |
| 112 | |
| 113 | /** |
| 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 | * @param $atts |
| 130 | * |
| 131 | * @return string |
| 132 | * |
| 133 | * Shortcode for getting course |
| 134 | */ |
| 135 | public function tutor_course( $atts ) { |
| 136 | $course_post_type = tutor()->course_post_type; |
| 137 | |
| 138 | $a = shortcode_atts( |
| 139 | array( |
| 140 | 'post_type' => $course_post_type, |
| 141 | 'post_status' => 'publish', |
| 142 | |
| 143 | 'id' => '', |
| 144 | 'exclude_ids' => '', |
| 145 | 'category' => '', |
| 146 | |
| 147 | 'orderby' => 'ID', |
| 148 | 'order' => 'DESC', |
| 149 | 'count' => 6, |
| 150 | 'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1, |
| 151 | ), |
| 152 | $atts |
| 153 | ); |
| 154 | |
| 155 | if ( ! empty( $a['id'] ) ) { |
| 156 | $ids = (array) explode( ',', $a['id'] ); |
| 157 | $a['post__in'] = $ids; |
| 158 | } |
| 159 | |
| 160 | if ( ! empty( $a['exclude_ids'] ) ) { |
| 161 | $exclude_ids = (array) explode( ',', $a['exclude_ids'] ); |
| 162 | $a['post__not_in'] = $exclude_ids; |
| 163 | } |
| 164 | if ( ! empty( $a['category'] ) ) { |
| 165 | $category = (array) explode( ',', $a['category'] ); |
| 166 | |
| 167 | $a['tax_query'] = array( |
| 168 | array( |
| 169 | 'taxonomy' => 'course-category', |
| 170 | 'field' => 'term_id', |
| 171 | 'terms' => $category, |
| 172 | 'operator' => 'IN', |
| 173 | ), |
| 174 | ); |
| 175 | } |
| 176 | $a['posts_per_page'] = (int) $a['count']; |
| 177 | |
| 178 | wp_reset_query(); |
| 179 | $the_query = new \WP_Query( $a ); |
| 180 | ob_start(); |
| 181 | |
| 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 | wp_reset_postdata(); |
| 195 | |
| 196 | return $output; |
| 197 | } |
| 198 | |
| 199 | private function prepare_instructor_list( $current_page, $atts, $cat_ids = array(), $keyword = '' ) { |
| 200 | |
| 201 | $limit = (int) sanitize_text_field( tutor_utils()->array_get( 'count', $atts, 9 ) ); |
| 202 | $page = $current_page - 1; |
| 203 | $rating_filter = isset( $_POST['rating_filter'] ) ? $_POST['rating_filter'] : ''; |
| 204 | /** |
| 205 | * Short by Relevant | New | Popular |
| 206 | * |
| 207 | * @since v2.0.0 |
| 208 | */ |
| 209 | $short_by = ''; |
| 210 | if ( isset( $_POST['short_by'] ) && $_POST['short_by'] === 'new' ) { |
| 211 | $short_by = 'new'; |
| 212 | } elseif ( isset( $_POST['short_by'] ) && $_POST['short_by'] === 'popular' ) { |
| 213 | $short_by = 'popular'; |
| 214 | } else { |
| 215 | $short_by = 'ASC'; |
| 216 | } |
| 217 | $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 ); |
| 219 | |
| 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 | $layout = sanitize_text_field( tutor_utils()->array_get( 'layout', $atts, '' ) ); |
| 224 | $layout = in_array( $layout, $this->instructor_layout ) ? $layout : tutor_utils()->get_option( 'instructor_list_layout', $this->instructor_layout[0] ); |
| 225 | |
| 226 | $payload = array( |
| 227 | '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 ) ), |
| 231 | 'layout' => $layout, |
| 232 | 'limit' => $limit, |
| 233 | 'current_page' => $current_page, |
| 234 | ); |
| 235 | |
| 236 | return $payload; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * @param $atts |
| 241 | * |
| 242 | * @return string |
| 243 | * |
| 244 | * Shortcode for getting instructors |
| 245 | */ |
| 246 | public function tutor_instructor_list( $atts ) { |
| 247 | global $wpdb; |
| 248 | ! is_array( $atts ) ? $atts = array() : 0; |
| 249 | |
| 250 | $current_page = (int) tutor_utils()->array_get( 'instructor-page', $_GET, 1 ); |
| 251 | $current_page = $current_page >= 1 ? $current_page : 1; |
| 252 | |
| 253 | $show_filter = isset( $atts['filter'] ) ? $atts['filter'] == 'on' : tutor_utils()->get_option( 'instructor_list_show_filter', false ); |
| 254 | |
| 255 | // Get instructor list to sow |
| 256 | $payload = $this->prepare_instructor_list( $current_page, $atts ); |
| 257 | $payload['show_filter'] = $show_filter; |
| 258 | |
| 259 | ob_start(); |
| 260 | tutor_load_template( 'shortcode.tutor-instructor', $payload ); |
| 261 | $content = ob_get_clean(); |
| 262 | |
| 263 | if ( $show_filter ) { |
| 264 | $limit = 8; |
| 265 | $course_taxonomy = 'course-category'; |
| 266 | $course_cats = $wpdb->get_results($wpdb->prepare( |
| 267 | "SELECT * FROM {$wpdb->terms} AS term |
| 268 | INNER JOIN {$wpdb->term_taxonomy} AS taxonomy |
| 269 | ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s |
| 270 | ORDER BY term.term_id DESC |
| 271 | LIMIT %d", |
| 272 | $course_taxonomy, |
| 273 | $limit |
| 274 | )); |
| 275 | |
| 276 | $all_cats = $wpdb->get_var( |
| 277 | $wpdb->prepare( |
| 278 | " SElECT COUNT(*) as total FROM {$wpdb->terms} AS term |
| 279 | INNER JOIN {$wpdb->term_taxonomy} AS taxonomy |
| 280 | ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s |
| 281 | ORDER BY term.term_id DESC |
| 282 | ", |
| 283 | $course_taxonomy |
| 284 | ) |
| 285 | ); |
| 286 | |
| 287 | $attributes = $payload; |
| 288 | unset( $attributes['instructors'] ); |
| 289 | |
| 290 | $payload = array( |
| 291 | 'show_filter' => $show_filter, |
| 292 | 'content' => $content, |
| 293 | 'categories' => $course_cats, |
| 294 | 'all_cats' => $all_cats, |
| 295 | 'attributes' => array_merge( $atts, $attributes ), |
| 296 | ); |
| 297 | |
| 298 | ob_start(); |
| 299 | |
| 300 | tutor_load_template( 'shortcode.instructor-filter', $payload ); |
| 301 | |
| 302 | $content = ob_get_clean(); |
| 303 | } |
| 304 | |
| 305 | return $content; |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Load more categories |
| 310 | * handle ajax request |
| 311 | * |
| 312 | * @package Instructor List |
| 313 | * @return string |
| 314 | * @since v2.0.0 |
| 315 | */ |
| 316 | public function show_more() { |
| 317 | global $wpdb; |
| 318 | tutor_utils()->checking_nonce(); |
| 319 | $term_id = isset( $_POST['term_id'] ) ? sanitize_text_field( $_POST['term_id'] ) : 0; |
| 320 | $limit = 8; |
| 321 | $course_taxonomy = 'course-category'; |
| 322 | |
| 323 | $remaining_categories = $wpdb->get_var( |
| 324 | $wpdb->prepare( |
| 325 | " SElECT COUNT(*) AS total FROM {$wpdb->terms} AS term |
| 326 | INNER JOIN {$wpdb->term_taxonomy} AS taxonomy |
| 327 | ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s |
| 328 | WHERE term.term_id < %d |
| 329 | ORDER BY term.term_id DESC |
| 330 | ", |
| 331 | $course_taxonomy, |
| 332 | $term_id |
| 333 | ) |
| 334 | ); |
| 335 | |
| 336 | $add_categories = $wpdb->get_results( |
| 337 | $wpdb->prepare( |
| 338 | " SElECT * FROM {$wpdb->terms} term |
| 339 | INNER JOIN {$wpdb->term_taxonomy} as taxonomy |
| 340 | ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s |
| 341 | WHERE term.term_id < %d |
| 342 | ORDER BY term.term_id DESC |
| 343 | LIMIT %d |
| 344 | ", |
| 345 | $course_taxonomy, |
| 346 | $term_id, |
| 347 | $limit |
| 348 | ) |
| 349 | ); |
| 350 | $show_more = false; |
| 351 | if ( $remaining_categories > $limit ) { |
| 352 | $show_more = true; |
| 353 | } |
| 354 | $response = array( |
| 355 | 'categories' => $add_categories, |
| 356 | 'show_more' => $show_more, |
| 357 | 'remaining' => $remaining_categories, |
| 358 | ); |
| 359 | wp_send_json_success( $response ); |
| 360 | exit; |
| 361 | } |
| 362 | |
| 363 | /** |
| 364 | * Filter instructor |
| 365 | */ |
| 366 | public function load_filtered_instructor() { |
| 367 | tutor_utils()->checking_nonce(); |
| 368 | |
| 369 | $_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 ) ); |
| 372 | $keyword = (string) sanitize_text_field( tutor_utils()->array_get( 'keyword', $_post, '' ) ); |
| 373 | |
| 374 | $category = (array) tutor_utils()->array_get( 'category', $_post, array() ); |
| 375 | $category = array_filter( |
| 376 | $category, |
| 377 | function( $cat ) { |
| 378 | return is_numeric( $cat ); |
| 379 | } |
| 380 | ); |
| 381 | |
| 382 | $payload = $this->prepare_instructor_list( $current_page, $attributes, $category, $keyword ); |
| 383 | |
| 384 | tutor_load_template( 'shortcode.tutor-instructor', $payload ); |
| 385 | exit; |
| 386 | } |
| 387 | |
| 388 | /** |
| 389 | * Show layout selection dashboard in instructor setting |
| 390 | */ |
| 391 | public function tutor_instructor_layout() { |
| 392 | tutor_load_template( 'instructor-setting', array( 'templates' => $this->instructor_layout ) ); |
| 393 | } |
| 394 | } |
| 395 |