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