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