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