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