PluginProbe
Tutor LMS – eLearning and online course solution / 2.2.1
Tutor LMS – eLearning and online course solution v2.2.1
4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 All 191 releases
← All changes | classes/Template.php +69 -199 trunk2.2.1 View file →
@@ -9,10 +9,8 @@
9 9 */
10 10
11 11 namespace TUTOR;
12 12
13 -use Tutor\Helpers\UrlHelper;
14 -
15 13 if ( ! defined( 'ABSPATH' ) ) {
16 14 exit;
17 15 }
18 16
@@ -23,15 +21,8 @@
23 21 */
24 22 class Template extends Tutor_Base {
25 23
26 24 /**
27 - * Store Shortcode Object
28 - *
29 - * @var Shortcode
30 - */
31 - public $shortcode_obj;
32 -
33 - /**
34 25 * Register Hooks
35 26 *
36 27 * @since 1.0.0
37 28 */
@@ -50,11 +41,12 @@
50 41 }
51 42
52 43 add_filter( 'template_include', array( $this, 'load_course_archive_template' ), 99 );
53 44 add_filter( 'template_include', array( $this, 'load_single_course_template' ), 99 );
45 + add_filter( 'template_include', array( $this, 'load_single_lesson_template' ), 99 );
54 46 add_filter( 'template_include', array( $this, 'play_private_video' ), 99 );
55 - add_filter( 'tutor_single_content_template', array( $this, 'load_single_lesson_template' ), 99, 2 );
56 - add_filter( 'tutor_single_content_template', array( $this, 'load_quiz_template' ), 99, 2 );
47 + add_filter( 'template_include', array( $this, 'load_quiz_template' ), 99 );
48 + add_filter( 'template_include', array( $this, 'load_assignment_template' ), 99 );
57 49
58 50 add_filter( 'template_include', array( $this, 'student_public_profile' ), 99 );
59 51 add_filter( 'template_include', array( $this, 'tutor_dashboard' ), 99 );
60 52 add_filter( 'pre_get_document_title', array( $this, 'student_public_profile_title' ) );
@@ -60,11 +52,8 @@
60 52 add_filter( 'pre_get_document_title', array( $this, 'student_public_profile_title' ) );
61 53
62 54 add_filter( 'the_content', array( $this, 'convert_static_page_to_template' ) );
63 55 add_action( 'pre_get_posts', array( $this, 'limit_course_query_archive' ), 99 );
64 - add_filter( 'template_include', array( $this, 'load_learning_template' ) );
65 -
66 - $this->shortcode_obj = new Shortcode( false );
67 56 }
68 57
69 58 /**
70 59 * Load default template for course
@@ -77,16 +66,12 @@
77 66 */
78 67 public function load_course_archive_template( $template ) {
79 68 global $wp_query;
80 69
81 - $post_type = get_query_var( 'post_type' );
82 - if ( ! is_array( $post_type ) ) {
83 - $post_type = array( $post_type );
84 - }
85 -
70 + $post_type = get_query_var( 'post_type' );
86 71 $course_category = get_query_var( 'course-category' );
87 72
88 - if ( ( in_array( $this->course_post_type, $post_type, true ) || ! empty( $course_category ) ) && $wp_query->is_archive ) {
73 + if ( ( $post_type === $this->course_post_type || ! empty( $course_category ) ) && $wp_query->is_archive ) {
89 74 $template = tutor_get_template( 'archive-course' );
90 75 return $template;
91 76 }
92 77
@@ -110,9 +95,9 @@
110 95 if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && is_page() ) {
111 96 $queried_object = get_queried_object();
112 97 if ( $queried_object instanceof \WP_Post ) {
113 98 $page_id = $queried_object->ID;
114 - $selected_archive_page = (int) apply_filters( 'tutor_filter_course_archive_page', tutor_utils()->get_option( 'course_archive_page' ) );
99 + $selected_archive_page = (int) tutor_utils()->get_option( 'course_archive_page' );
115 100
116 101 if ( $page_id === $selected_archive_page ) {
117 102 $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
118 103 $search_query = get_search_query();
@@ -132,10 +117,8 @@
132 117 $post_type = get_query_var( 'post_type' );
133 118 $course_category = get_query_var( 'course-category' );
134 119 if ( ( $post_type === $this->course_post_type || ! empty( $course_category ) ) ) {
135 120 $query->set( 'posts_per_page', $courses_per_page );
136 - $query->set( 'post_type', apply_filters( 'tutor_course_archive_post_types', array( $this->course_post_type ) ) );
137 - $query = apply_filters( 'tutor_limit_course_archive_list_filter', $query );
138 121
139 122 $course_filter = 'newest_first';
140 123 if ( ! empty( Input::get( 'tutor_course_filter', '' ) ) ) {
141 124 $course_filter = Input::get( 'tutor_course_filter' );
@@ -141,13 +124,13 @@
141 124 $course_filter = Input::get( 'tutor_course_filter' );
142 125 }
143 126 switch ( $course_filter ) {
144 127 case 'newest_first':
145 - $query->set( 'orderby', 'post_date' );
128 + $query->set( 'orderby', 'ID' );
146 129 $query->set( 'order', 'desc' );
147 130 break;
148 131 case 'oldest_first':
149 - $query->set( 'orderby', 'post_date' );
132 + $query->set( 'orderby', 'ID' );
150 133 $query->set( 'order', 'asc' );
151 134 break;
152 135 case 'course_title_az':
153 136 $query->set( 'orderby', 'post_title' );
@@ -172,17 +155,13 @@
172 155 * @return bool|string
173 156 */
174 157 public function load_single_course_template( $template ) {
175 158 global $wp_query;
159 +
176 160 if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] === $this->course_post_type ) {
177 - // Check if the slug contains subpage of learning area.
178 - if ( Input::has( 'subpage' ) ) {
179 - $template = tutor_get_template( 'learning-area.index' );
180 - } else {
181 - do_action( 'single_course_template_before_load', get_the_ID() );
182 - wp_reset_query();
183 - $template = tutor_get_template( 'single-course' );
184 - }
161 + do_action( 'single_course_template_before_load', get_the_ID() );
162 + wp_reset_query();
163 + return tutor_get_template( 'single-course' );
185 164 }
186 165
187 166 return $template;
188 167 }
@@ -205,23 +184,16 @@
205 184 * Load lesson template
206 185 *
207 186 * @since v.1.0.0
208 187 *
209 - * @since 4.0.0 Post type argument added
210 - *
211 188 * @param string $template template name to load.
212 - * @param string $post_type Post type added.
213 189 *
214 190 * @return bool|string
215 191 */
216 - public function load_single_lesson_template( $template, $post_type ) {
217 - if ( tutor()->lesson_post_type !== $post_type ) {
218 - return $template;
219 - }
192 + public function load_single_lesson_template( $template ) {
193 + global $wp_query;
220 194
221 - $is_lesson_post_type = apply_filters( 'tutor_is_lesson_post_type', true, $post_type );
222 -
223 - if ( $is_lesson_post_type ) {
195 + if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] === $this->lesson_post_type ) {
224 196 $page_id = get_the_ID();
225 197
226 198 do_action( 'tutor_lesson_load_before', $template );
227 199 setup_postdata( $page_id );
@@ -230,9 +202,9 @@
230 202 $has_content_access = tutor_utils()->has_enrolled_content_access( 'lesson' );
231 203 if ( $has_content_access ) {
232 204 $template = tutor_get_template( 'single-lesson' );
233 205 } else {
234 - $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
206 + $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first
235 207 }
236 208 } else {
237 209 $template = tutor_get_template( 'login' );
238 210 }
@@ -245,9 +217,8 @@
245 217 }
246 218
247 219 return apply_filters( 'tutor_lesson_template', $template );
248 220 }
249 -
250 221 return $template;
251 222 }
252 223
253 224 /**
@@ -289,9 +260,9 @@
289 260
290 261 /**
291 262 * Tutor Dashboard Page, Responsible to show dashboard stuffs
292 263 *
293 - * @since 1.0.0
264 + * @since v.1.0.0
294 265 *
295 266 * @param string $content page content.
296 267 *
297 268 * @return mixed
@@ -296,56 +267,28 @@
296 267 *
297 268 * @return mixed
298 269 */
299 270 public function convert_static_page_to_template( $content ) {
300 - /**
301 - * Avoid rendering dynamic templates or shortcodes during head generation.
302 - *
303 - * Some plugins (e.g., Yoast SEO) may process `the_content` while generating
304 - * frontend metadata in `wp_head`, which can cause templates or shortcodes
305 - * to be rendered multiple times within the same request.
306 - *
307 - * @since 4.0.0
308 - */
309 - if ( ! is_admin() && doing_action( 'wp_head' ) ) {
310 - return $content;
311 - }
312 -
313 - $page_id = get_the_ID();
314 -
315 271 // Dashboard Page.
316 272 $student_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' );
317 - if ( $page_id === $student_dashboard_page_id ) {
318 - return $this->shortcode_obj->tutor_dashboard();
273 + if ( get_the_ID() === $student_dashboard_page_id ) {
274 + $shortcode = new Shortcode();
275 + return $shortcode->tutor_dashboard();
319 276 }
320 277
321 278 // Instructor Registration Page.
322 279 $instructor_register_page_page_id = (int) tutor_utils()->get_option( 'instructor_register_page' );
323 - if ( $page_id === $instructor_register_page_page_id ) {
324 - return $this->shortcode_obj->instructor_registration_form();
280 + if ( get_the_ID() === $instructor_register_page_page_id ) {
281 + $shortcode = new Shortcode();
282 + return $shortcode->instructor_registration_form();
325 283 }
326 284
327 285 $student_register_page_id = (int) tutor_utils()->get_option( 'student_register_page' );
328 - if ( $page_id === $student_register_page_id ) {
329 - return $this->shortcode_obj->student_registration_form();
286 + if ( get_the_ID() === $student_register_page_id ) {
287 + $shortcode = new Shortcode();
288 + return $shortcode->student_registration_form();
330 289 }
331 290
332 - if ( tutor_utils()->is_monetize_by_tutor() ) {
333 - $tutor_cart_page_id = (int) tutor_utils()->get_option( 'tutor_cart_page_id' );
334 - if ( $page_id === $tutor_cart_page_id ) {
335 - return $this->shortcode_obj->tutor_cart_page();
336 - }
337 -
338 - $tutor_checkout_page_id = (int) tutor_utils()->get_option( 'tutor_checkout_page_id' );
339 - if ( $page_id === $tutor_checkout_page_id ) {
340 - if ( ! apply_filters( 'tutor_should_load_checkout_page', true ) ) {
341 - return '';
342 - }
343 -
344 - return $this->shortcode_obj->tutor_checkout_page();
345 - }
346 - }
347 -
348 291 return $content;
349 292 }
350 293
351 294 /**
@@ -405,38 +348,11 @@
405 348 $query_var = tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars );
406 349 $dashboard_pages = tutor_utils()->tutor_dashboard_pages();
407 350 $dashboard_page_item = tutor_utils()->array_get( $query_var, $dashboard_pages );
408 351 $auth_cap = tutor_utils()->array_get( 'auth_cap', $dashboard_page_item );
409 -
410 - $can_access_instructor_item = tutor()->instructor_role === $auth_cap && User::can_view_instructor_dashboard();
411 -
412 - if ( $auth_cap && ! User::is_admin() && ! current_user_can( $auth_cap ) && ! $can_access_instructor_item
413 - ) {
352 + if ( $auth_cap && ! current_user_can( $auth_cap ) ) {
414 353 $template = tutor_get_template( 'permission-denied' );
415 354 }
416 -
417 - /**
418 - * Account pages of dashboard.
419 - *
420 - * @since 4.0.0
421 - */
422 - if ( Dashboard::ACCOUNT_PAGE_SLUG === $dashboard_page ) {
423 - $subpage = tutor_utils()->array_get( 'tutor_dashboard_sub_page', $wp_query->query_vars, 'profile' );
424 - $account_pages = Dashboard::get_account_pages();
425 - $page_data = $account_pages[ $subpage ] ?? array();
426 - $page_template = $page_data['template'] ?? '';
427 -
428 - if ( file_exists( $page_template ) ) {
429 - $template = tutor_get_template( 'account' );
430 - }
431 - }
432 -
433 - $dashboard_subpage = tutor_utils()->array_get( 'tutor_dashboard_sub_page', $wp_query->query_vars );
434 - $is_isolated = Dashboard::is_isolated_page_request( $dashboard_page, $dashboard_subpage );
435 -
436 - if ( $is_isolated ) {
437 - $template = tutor_get_template( 'dashboard-isolated' );
438 - }
439 355 } else {
440 356 $template = tutor_get_template( 'login' );
441 357 }
442 358 }
@@ -452,35 +368,60 @@
452 368 *
453 369 * If course public then enrollment not required
454 370 *
455 371 * @since 2.0.2
456 - * @since 4.0.0 $post_type param added.
457 372 *
458 373 * @param string $template template to load.
459 - * @param string $post_type Post type.
460 374 *
461 375 * @return bool|string
462 376 */
463 - public function load_quiz_template( $template, $post_type ) {
464 - if ( tutor()->quiz_post_type !== $post_type ) {
377 + public function load_quiz_template( $template ) {
378 + global $wp_query, $post;
379 +
380 + if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && 'tutor_quiz' === $wp_query->query_vars['post_type'] ) {
381 + if ( is_user_logged_in() ) {
382 + $has_content_access = tutor_utils()->has_enrolled_content_access( 'quiz' );
383 + $course_id = tutor_utils()->get_course_id_by_content( $post );
384 + $is_public = Course_List::is_public( $course_id );
385 +
386 + // if public course don't need to be enrolled.
387 + if ( $has_content_access || $is_public ) {
388 + $template = tutor_get_template( 'single-quiz' );
389 + } else {
390 + $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
391 + }
392 + } else {
393 + $template = tutor_get_template( 'login' );
394 + }
465 395 return $template;
466 396 }
397 + return $template;
398 + }
467 399
468 - global $post;
400 + /**
401 + * Load assignment template
402 + *
403 + * @since 1.0.0
404 + *
405 + * @param string $template template file to load.
406 + *
407 + * @return string template path
408 + */
409 + public function load_assignment_template( $template ) {
410 + global $wp_query;
469 411
470 - if ( is_user_logged_in() ) {
471 - $has_content_access = tutor_utils()->has_enrolled_content_access( 'quiz' );
472 - $course_id = tutor_utils()->get_course_id_by_content( $post );
473 - $is_public = Course_List::is_public( $course_id );
474 -
475 - // if public course don't need to be enrolled.
476 - if ( $has_content_access || $is_public ) {
477 - $template = tutor_get_template( 'single-quiz' );
412 + if ( $wp_query->is_single && ! empty( $wp_query->query_vars['post_type'] ) && 'tutor_assignments' === $wp_query->query_vars['post_type'] ) {
413 + if ( is_user_logged_in() ) {
414 + $has_content_access = tutor_utils()->has_enrolled_content_access( 'assignment' );
415 + if ( $has_content_access ) {
416 + $template = tutor_get_template( 'single-assignment' );
417 + } else {
418 + $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first
419 + }
478 420 } else {
479 - $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
421 + $template = tutor_get_template( 'login' );
480 422 }
481 - } else {
482 - $template = tutor_get_template( 'login' );
423 + return $template;
483 424 }
484 425
485 426 return $template;
486 427 }
@@ -520,81 +461,10 @@
520 461 $user_name = sanitize_text_field( $wp_query->query['tutor_profile_username'] );
521 462 $user = $wpdb->get_row( $wpdb->prepare( "SELECT display_name from {$wpdb->users} WHERE user_login = %s limit 1; ", $user_name ) );
522 463
523 464 if ( ! empty( $user->display_name ) ) {
524 - return sprintf( "%s's %s", $user->display_name, __( 'Profile Page', 'tutor' ) );
465 + return sprintf( "%s's Profile page ", $user->display_name );
525 466 }
526 467 }
527 468 return '';
528 - }
529 -
530 - /**
531 - * Load learning template
532 - *
533 - * @since 4.0.0
534 - *
535 - * @param string $template template to load.
536 - *
537 - * @return string
538 - */
539 - public function load_learning_template( string $template ): string {
540 - if ( tutor_utils()->is_learning_area() ) {
541 - $user_id = get_current_user_id();
542 - $post_type = get_post_type();
543 - $post_id = get_the_ID();
544 - $course_id = tutor()->course_post_type === $post_type ? $post_id : tutor_utils()->get_course_id_by_subcontent( $post_id );
545 - if ( ! in_array( get_post_status( $course_id ), array( 'publish', 'private' ), true ) && ! tutor_utils()->has_user_course_content_access( $user_id, $course_id ) ) {
546 - global $wp_query;
547 - $wp_query->set_404();
548 - status_header( 404 );
549 - return get_404_template();
550 - }
551 -
552 - $legacy_mode = Options_V2::LEARNING_MODE_LEGACY === tutor_utils()->get_option( 'learning_mode' );
553 -
554 - $template_path = apply_filters( 'tutor_single_content_template', $template, $post_type );
555 -
556 - $template = $legacy_mode ? $template_path : tutor_get_template( 'learning-area.index' );
557 - }
558 -
559 - return $template;
560 - }
561 -
562 - /**
563 - * Make learning area sub pages nav items
564 - *
565 - * @since 4.0.0
566 - *
567 - * @param string $base_url Nav items base url.
568 - *
569 - * @return array
570 - */
571 - public static function make_learning_area_sub_page_nav_items( $base_url = '' ): array {
572 - if ( empty( $base_url ) ) {
573 - $base_url = get_permalink();
574 - }
575 -
576 - $menu_items = apply_filters( 'tutor_learning_area_sub_page_nav_item', array(), $base_url );
577 -
578 - $menu_items['course-info'] = array(
579 - 'title' => __( 'Course Info', 'tutor' ),
580 - 'icon' => Icon::INFO_OCTAGON,
581 - 'url' => UrlHelper::add_query_params( $base_url, array( 'subpage' => 'course-info' ) ),
582 - 'template' => tutor_get_template( 'learning-area.subpages.course-info' ),
583 - );
584 -
585 - return apply_filters( 'tutor_learning_area_sub_page_menu_items', $menu_items, $base_url );
586 - }
587 -
588 - /**
589 - * Get learning area active subpage
590 - *
591 - * @since 4.0.0
592 - *
593 - * @return string
594 - */
595 - public static function learning_area_active_subpage(): string {
596 - $active_menu = Input::get( 'subpage', '' );
597 -
598 - return apply_filters( 'tutor_learning_area_active_subpage', $active_menu );
599 469 }
600 470 }