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