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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 4 years ago Shortcode.php 3 years ago Student.php 4 years ago Students_List.php 4 years ago Taxonomies.php 4 years ago Template.php 3 years ago Theme_Compatibility.php 5 years ago Tools.php 3 years ago Tools_V2.php 4 years ago Tutor.php 3 years ago TutorEDD.php 4 years ago Tutor_Base.php 5 years ago Tutor_List_Table.php 3 years ago Tutor_Setup.php 3 years ago Upgrader.php 4 years ago User.php 4 years ago Utils.php 3 years ago Video_Stream.php 4 years ago Withdraw.php 3 years ago Withdraw_Requests_List.php 3 years ago WooCommerce.php 3 years ago
Shortcode.php
412 lines
1 <?php
2 /**
3 * Class Shortcode
4 *
5 * @package TUTOR
6 *
7 * @since v.1.0.0
8 */
9
10 namespace TUTOR;
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 class Shortcode {
17
18 private $instructor_layout = array(
19 'default',
20 'cover',
21 'minimal',
22 'portrait-horizontal',
23 'minimal-horizontal',
24 );
25
26 public function __construct() {
27 add_shortcode( 'tutor_student_registration_form', array( $this, 'student_registration_form' ) );
28 add_shortcode( 'tutor_dashboard', array( $this, 'tutor_dashboard' ) );
29 add_shortcode( 'tutor_instructor_registration_form', array( $this, 'instructor_registration_form' ) );
30 add_shortcode( 'tutor_course', array( $this, 'tutor_course' ) );
31
32 add_shortcode( 'tutor_instructor_list', array( $this, 'tutor_instructor_list' ) );
33 add_action( 'tutor_options_after_instructors', array( $this, 'tutor_instructor_layout' ) );
34 add_action( 'wp_ajax_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) );
35 add_action( 'wp_ajax_nopriv_load_filtered_instructor', array( $this, 'load_filtered_instructor' ) );
36
37 /**
38 * Load more categories
39 *
40 * @since 2.0.0
41 */
42 add_action( 'wp_ajax_show_more', array( $this, 'show_more' ) );
43 add_action( 'wp_ajax_nopriv_show_more', array( $this, 'show_more' ) );
44 }
45
46 /**
47 * @return mixed
48 *
49 * Instructor Registration Shortcode
50 *
51 * @since v.1.0.0
52 */
53 public function student_registration_form() {
54 ob_start();
55 if ( is_user_logged_in() ) {
56 tutor_load_template( 'dashboard.logged-in' );
57 } else {
58 tutor_load_template( 'dashboard.registration' );
59 }
60 return apply_filters( 'tutor/student/register', ob_get_clean() );
61 }
62
63 /**
64 * @return mixed
65 *
66 * Tutor Dashboard for students
67 *
68 * @since v.1.0.0
69 */
70 public function tutor_dashboard() {
71 global $wp_query;
72
73 ob_start();
74 if ( is_user_logged_in() ) {
75 /**
76 * Added isset() Condition to avoid infinite loop since v.1.5.4
77 * This has cause error by others plugin, Such AS SEO
78 */
79
80 if ( ! isset( $wp_query->query_vars['tutor_dashboard_page'] ) ) {
81 tutor_load_template( 'dashboard', array( 'is_shortcode' => true ) );
82 }
83 } else {
84 /**
85 * If user not logged in show login form instead of
86 * popup sign-in button
87 *
88 * @since 2.1.3
89 */
90 $login_url = tutor_utils()->get_option('enable_tutor_native_login', null, true, true) ? '' : wp_login_url(tutor()->current_url);
91 echo sprintf( __('Please %sSign-In%s to view this page', 'tutor'), '<a data-login_url="'.$login_url.'" href="#" class="tutor-open-login-modal">', '</a>');
92 }
93 return apply_filters( 'tutor_dashboard/index', ob_get_clean() );
94 }
95
96 /**
97 * @return mixed
98 *
99 * Instructor Registration Shortcode
100 *
101 * @since v.1.0.0
102 */
103 public function instructor_registration_form() {
104 ob_start();
105 if ( is_user_logged_in() ) {
106 tutor_load_template( 'dashboard.instructor.logged-in' );
107 } else {
108 tutor_load_template( 'dashboard.instructor.registration' );
109 }
110 return apply_filters( 'tutor_dashboard/student/index', ob_get_clean() );
111 }
112
113 /**
114 * @param $atts
115 *
116 * @return string
117 *
118 * Shortcode for getting course
119 */
120 public function tutor_course( $atts ) {
121 $course_post_type = tutor()->course_post_type;
122
123 $a = shortcode_atts(
124 array(
125 'post_type' => $course_post_type,
126 'post_status' => 'publish',
127
128 'id' => '',
129 'exclude_ids' => '',
130 'category' => '',
131
132 'orderby' => 'ID',
133 'order' => 'DESC',
134 'count' => 6,
135 'paged' => get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1,
136 ),
137 $atts
138 );
139
140 if ( ! empty( $a['id'] ) ) {
141 $ids = (array) explode( ',', $a['id'] );
142 $a['post__in'] = $ids;
143 }
144
145 if ( ! empty( $a['exclude_ids'] ) ) {
146 $exclude_ids = (array) explode( ',', $a['exclude_ids'] );
147 $a['post__not_in'] = $exclude_ids;
148 }
149 if ( ! empty( $a['category'] ) ) {
150 $category = (array) explode( ',', $a['category'] );
151
152 $a['tax_query'] = array();
153
154 $category_ids = array_filter($category, function($id){
155 return is_numeric($id);
156 });
157
158 $category_names = array_filter($category, function($id){
159 return !is_numeric($id);
160 });
161
162 if(!empty($category_ids)) {
163 $a['tax_query'] = array(
164 array(
165 'taxonomy' => 'course-category',
166 'field' => 'term_id',
167 'terms' => $category_ids,
168 'operator' => 'IN',
169 ),
170 );
171 }
172
173 if(!empty($category_names)) {
174 $a['tax_query'] = array(
175 array(
176 'taxonomy' => 'course-category',
177 'field' => 'name',
178 'terms' => $category_names,
179 'operator' => 'IN',
180 ),
181 );
182 }
183
184 }
185 $a['posts_per_page'] = (int) $a['count'];
186
187 wp_reset_query();
188 $the_query = new \WP_Query( $a );
189
190
191 // Load the renderer now
192 ob_start();
193
194 if ( $the_query->have_posts() ) {
195 tutor_load_template('archive-course-init', array(
196 'course_filter' => isset( $atts['course_filter'] ) && $atts['course_filter'] == 'on',
197 'supported_filters' => tutor_utils()->get_option( 'supported_course_filters', array() ),
198 'loop_content_only' => false,
199 'column_per_row' => isset( $atts['column_per_row'] ) ? $atts['column_per_row'] : null,
200 'course_per_page' => $a['posts_per_page'],
201 'show_pagination' => isset( $atts['show_pagination'] ) && $atts['show_pagination']=='on',
202 'the_query' => $the_query
203 ));
204 } else {
205 tutor_utils()->tutor_empty_state( tutor_utils()->not_found_text() );
206 }
207
208 $output = ob_get_clean();
209
210 wp_reset_postdata();
211
212 return $output;
213 }
214
215 private function prepare_instructor_list( $current_page, $atts, $cat_ids = array(), $keyword = '' ) {
216
217 $default_pagination = tutor_utils()->get_option('pagination_per_page', 9);
218 $limit = (int) sanitize_text_field( tutor_utils()->array_get( 'count', $atts, $default_pagination ) );
219 $page = $current_page - 1;
220 $rating_filter = isset( $_POST['rating_filter'] ) ? $_POST['rating_filter'] : '';
221
222 /**
223 * Sort by Relevant | New | Popular
224 *
225 * @since v2.0.0
226 */
227 $short_by = '';
228 if ( isset( $_POST['short_by'] ) && $_POST['short_by'] === 'new' ) {
229 $short_by = 'new';
230 } elseif ( isset( $_POST['short_by'] ) && $_POST['short_by'] === 'popular' ) {
231 $short_by = 'popular';
232 } else {
233 $short_by = 'ASC';
234 }
235 $instructors = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter );
236 $instructors_count = tutor_utils()->get_instructors( $limit * $page, $limit, $keyword, '', '', $short_by, 'approved', $cat_ids, $rating_filter, true );
237
238 $layout = sanitize_text_field( tutor_utils()->array_get( 'layout', $atts, '' ) );
239 $layout = in_array( $layout, $this->instructor_layout ) ? $layout : tutor_utils()->get_option( 'instructor_list_layout', $this->instructor_layout[0] );
240 $default_col = tutor_utils()->get_option( 'courses_col_per_row', 3 );
241
242 $payload = array(
243 'instructors' => is_array( $instructors ) ? $instructors : array(),
244 'instructors_count' => $instructors_count,
245 'column_count' => sanitize_text_field( tutor_utils()->array_get( 'column_per_row', $atts, $default_col ) ),
246 'layout' => $layout,
247 'limit' => $limit,
248 'current_page' => $current_page,
249 'filter' => $atts
250 );
251
252 return $payload;
253 }
254
255 /**
256 * @param $atts
257 *
258 * @return string
259 *
260 * Shortcode for getting instructors
261 */
262 public function tutor_instructor_list( $atts ) {
263 global $wpdb;
264 ! is_array( $atts ) ? $atts = array() : 0;
265
266 $current_page = (int) tutor_utils()->array_get( 'instructor-page', $_GET, 1 );
267 $current_page = $current_page >= 1 ? $current_page : 1;
268
269 $show_filter = isset( $atts['filter'] ) ? $atts['filter'] == 'on' : tutor_utils()->get_option( 'instructor_list_show_filter', false );
270 $atts['show_filter'] = $show_filter;
271
272 // Get instructor list to sow
273 $payload = $this->prepare_instructor_list( $current_page, $atts );
274 $payload['show_filter'] = $show_filter;
275
276 ob_start();
277 tutor_load_template( 'shortcode.tutor-instructor', $payload );
278 $content = ob_get_clean();
279
280 if ( $show_filter ) {
281 $limit = 8;
282 $course_taxonomy = 'course-category';
283 $course_cats = $wpdb->get_results($wpdb->prepare(
284 "SELECT * FROM {$wpdb->terms} AS term
285 INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
286 ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
287 ORDER BY term.term_id DESC
288 LIMIT %d",
289 $course_taxonomy,
290 $limit
291 ));
292
293 $all_cats = $wpdb->get_var(
294 $wpdb->prepare(
295 "SELECT COUNT(*) as total FROM {$wpdb->terms} AS term
296 INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
297 ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
298 ORDER BY term.term_id DESC",
299 $course_taxonomy
300 )
301 );
302
303 $attributes = $payload;
304 unset( $attributes['instructors'] );
305
306 $payload = array(
307 'show_filter' => $show_filter,
308 'content' => $content,
309 'categories' => $course_cats,
310 'all_cats' => $all_cats,
311 'attributes' => array_merge( $atts, $attributes ),
312 );
313
314 ob_start();
315
316 tutor_load_template( 'shortcode.instructor-filter', $payload );
317
318 $content = ob_get_clean();
319 }
320
321 return $content;
322 }
323
324 /**
325 * Load more categories
326 * handle ajax request
327 *
328 * @package Instructor List
329 * @return string
330 * @since v2.0.0
331 */
332 public function show_more() {
333 global $wpdb;
334 tutor_utils()->checking_nonce();
335 $term_id = isset( $_POST['term_id'] ) ? sanitize_text_field( $_POST['term_id'] ) : 0;
336 $limit = 8;
337 $course_taxonomy = 'course-category';
338
339 $remaining_categories = $wpdb->get_var(
340 $wpdb->prepare(
341 " SElECT COUNT(*) AS total FROM {$wpdb->terms} AS term
342 INNER JOIN {$wpdb->term_taxonomy} AS taxonomy
343 ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
344 WHERE term.term_id < %d
345 ORDER BY term.term_id DESC
346 ",
347 $course_taxonomy,
348 $term_id
349 )
350 );
351
352 $add_categories = $wpdb->get_results(
353 $wpdb->prepare(
354 " SElECT * FROM {$wpdb->terms} term
355 INNER JOIN {$wpdb->term_taxonomy} as taxonomy
356 ON taxonomy.term_id = term.term_id AND taxonomy.taxonomy = %s
357 WHERE term.term_id < %d
358 ORDER BY term.term_id DESC
359 LIMIT %d
360 ",
361 $course_taxonomy,
362 $term_id,
363 $limit
364 )
365 );
366 $show_more = false;
367 if ( $remaining_categories > $limit ) {
368 $show_more = true;
369 }
370 $response = array(
371 'categories' => $add_categories,
372 'show_more' => $show_more,
373 'remaining' => $remaining_categories,
374 );
375 wp_send_json_success( $response );
376 exit;
377 }
378
379 /**
380 * Filter instructor
381 */
382 public function load_filtered_instructor() {
383 tutor_utils()->checking_nonce();
384
385 $_post = tutor_sanitize_data($_POST);
386 $current_page = (int) sanitize_text_field( tutor_utils()->array_get( 'current_page', $_post, 1 ) );
387 $keyword = (string) sanitize_text_field( tutor_utils()->array_get( 'keyword', $_post, '' ) );
388
389 $category = (array) tutor_utils()->array_get( 'category', $_post, array() );
390 $category = array_filter(
391 $category,
392 function( $cat ) {
393 return is_numeric( $cat );
394 }
395 );
396
397 $data = $this->prepare_instructor_list( $current_page, $_post, $category, $keyword );
398
399 ob_start();
400 tutor_load_template( 'shortcode.tutor-instructor', $data );
401 wp_send_json_success( array('html' => ob_get_clean() ) );
402 exit;
403 }
404
405 /**
406 * Show layout selection dashboard in instructor setting
407 */
408 public function tutor_instructor_layout() {
409 tutor_load_template( 'instructor-setting', array( 'templates' => $this->instructor_layout ) );
410 }
411 }
412