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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
498 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 ! is_array( $atts ) ? $atts = array() : 0;
332
333 $current_page = (int) tutor_utils()->array_get( 'instructor-page', $_GET, 1 );
334 $current_page = Input::get( 'instructor-page', 1, Input::TYPE_INT );
335 $current_page = $current_page >= 1 ? $current_page : 1;
336
337 $show_filter = isset( $atts['filter'] ) ? 'on' === $atts['filter'] : tutor_utils()->get_option( 'instructor_list_show_filter', false );
338 $category_limit = (int) isset( $atts['category_limit'] ) ? $atts['category_limit'] : 0;
339 $hide_empty_category = isset( $atts['hide_empty_category'] ) ? '1' == $atts['hide_empty_category'] : false;
340 $atts['show_filter'] = $show_filter;
341
342 // Get instructor list to sow.
343 $payload = $this->prepare_instructor_list( $current_page, $atts );
344 $payload['show_filter'] = $show_filter;
345
346 ob_start();
347 tutor_load_template( 'shortcode.tutor-instructor', $payload );
348 $content = ob_get_clean();
349
350 if ( $show_filter ) {
351 $course_taxonomy = CourseModel::COURSE_CATEGORY;
352 $term_args = array(
353 'taxonomy' => $course_taxonomy,
354 'hide_empty' => $hide_empty_category,
355 'orderby' => 'count',
356 'order' => 'DESC',
357 'number' => $category_limit,
358 );
359
360 $course_cats = get_terms( $term_args );
361
362 $attributes = $payload;
363 unset( $attributes['instructors'] );
364
365 $payload = array(
366 'show_filter' => $show_filter,
367 'content' => $content,
368 'categories' => $course_cats,
369 'attributes' => array_merge( $atts, $attributes ),
370 );
371
372 ob_start();
373
374 tutor_load_template( 'shortcode.instructor-filter', $payload );
375
376 $content = ob_get_clean();
377 }
378
379 return $content;
380 }
381
382 /**
383 * Load more categories
384 * handle ajax request
385 *
386 * @since 2.0.0
387 *
388 * @return void send wp_json response
389 */
390 public function show_more() {
391 global $wpdb;
392 tutor_utils()->checking_nonce();
393 $term_id = Input::post( 'term_id', 0, Input::TYPE_INT );
394 $limit = 8;
395 $course_taxonomy = CourseModel::COURSE_CATEGORY;
396
397 $remaining_categories = $wpdb->get_var(
398 $wpdb->prepare(
399 "SElECT
400 COUNT(*) AS total
401 FROM {$wpdb->terms} AS term
402 INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
403 ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
404 WHERE term.term_id < %d
405 ORDER BY term.term_id DESC
406 ",
407 $course_taxonomy,
408 $term_id
409 )
410 );
411
412 $add_categories = $wpdb->get_results(
413 $wpdb->prepare(
414 "SElECT
415 *
416 FROM {$wpdb->terms} term
417 INNER JOIN {$wpdb->term_taxonomy} as taxonomy
418 ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
419 WHERE term.term_id < %d
420 ORDER BY term.term_id DESC
421 LIMIT %d
422 ",
423 $course_taxonomy,
424 $term_id,
425 $limit
426 )
427 );
428 $show_more = false;
429 if ( $remaining_categories > $limit ) {
430 $show_more = true;
431 }
432 $response = array(
433 'categories' => $add_categories,
434 'show_more' => $show_more,
435 'remaining' => $remaining_categories,
436 );
437 wp_send_json_success( $response );
438 exit;
439 }
440
441 /**
442 * Filter instructor
443 *
444 * @since 1.0.0
445 *
446 * @return void send wp_json response
447 */
448 public function load_filtered_instructor() {
449 tutor_utils()->checking_nonce();
450
451 // phpcs:disable WordPress.Security.NonceVerification.Missing --nonce already verified
452 $_post = tutor_sanitize_data( $_POST );
453 $current_page = (int) sanitize_text_field( tutor_utils()->array_get( 'current_page', $_post, 1 ) );
454 $keyword = (string) sanitize_text_field( tutor_utils()->array_get( 'keyword', $_post, '' ) );
455
456 $category = (array) tutor_utils()->array_get( 'category', $_post, array() );
457 $category = array_filter(
458 $category,
459 function( $cat ) {
460 return is_numeric( $cat );
461 }
462 );
463
464 $data = $this->prepare_instructor_list( $current_page, $_post, $category, $keyword );
465
466 ob_start();
467 tutor_load_template( 'shortcode.tutor-instructor', $data );
468 wp_send_json_success( array( 'html' => ob_get_clean() ) );
469 exit;
470 }
471
472 /**
473 * Tutor Cart Shortcode
474 *
475 * @since v.3.0.0
476 *
477 * @return mixed
478 */
479 public function tutor_cart_page() {
480 ob_start();
481 tutor_load_template( 'ecommerce.cart' );
482 return apply_filters( 'tutor_ecommerce/cart', ob_get_clean() );
483 }
484
485 /**
486 * Tutor Checkout Shortcode
487 *
488 * @since v.3.0.0
489 *
490 * @return mixed
491 */
492 public function tutor_checkout_page() {
493 ob_start();
494 tutor_load_template( 'ecommerce.checkout' );
495 return apply_filters( 'tutor_ecommerce/checkout', ob_get_clean() );
496 }
497 }
498