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