PluginProbe
Tutor LMS – eLearning and online course solution / 1.7.6
Tutor LMS – eLearning and online course solution v1.7.6
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 +229 -382 trunk1.7.6 View file →
@@ -1,44 +1,25 @@
1 1 <?php
2 2 /**
3 3 * Template Class
4 4 *
5 - * @package Tutor\Template
6 - * @author Themeum <support@themeum.com>
7 - * @link https://themeum.com
8 - * @since 1.0.0
5 + * @since: v.1.0.0
9 6 */
10 -
11 7 namespace TUTOR;
12 8
13 -use Tutor\Helpers\UrlHelper;
14 9
15 -if ( ! defined( 'ABSPATH' ) ) {
10 +if ( ! defined( 'ABSPATH' ) )
16 11 exit;
17 -}
18 12
19 -/**
20 - * Handle template before include
21 - *
22 - * @since 1.0.0
23 - */
13 +
24 14 class Template extends Tutor_Base {
25 15
26 - /**
27 - * Store Shortcode Object
28 - *
29 - * @var Shortcode
30 - */
31 - public $shortcode_obj;
32 -
33 - /**
34 - * Register Hooks
35 - *
36 - * @since 1.0.0
37 - */
38 16 public function __construct() {
39 17 parent::__construct();
40 18
19 + add_action( 'pre_get_posts', array($this, 'limit_course_query_archive'), 99 );
20 +
21 +
41 22 /**
42 23 * Should Load Template Override
43 24 * Integration for specially oxygen builder
44 25 * If we found false of below filter, then we will not use this file
@@ -43,51 +24,45 @@
43 24 * Integration for specially oxygen builder
44 25 * If we found false of below filter, then we will not use this file
45 26 */
46 27
47 - $template_override = apply_filters( 'tutor_lms_should_template_override', true );
48 - if ( ! $template_override ) {
28 + $template_override = apply_filters('tutor_lms_should_template_override', true);
29 + if ( ! $template_override){
49 30 return;
50 31 }
51 32
52 - add_filter( 'template_include', array( $this, 'load_course_archive_template' ), 99 );
53 - add_filter( 'template_include', array( $this, 'load_single_course_template' ), 99 );
54 - 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 );
33 + add_filter( 'template_include', array($this, 'load_course_archive_template'), 99 );
34 + add_filter( 'template_include', array($this, 'load_single_course_template'), 99 );
35 + add_filter( 'template_include', array($this, 'load_single_lesson_template'), 99 );
36 + add_filter( 'template_include', array($this, 'play_private_video'), 99 );
37 + add_filter( 'template_include', array($this, 'load_quiz_template'), 99 );
38 + add_filter( 'template_include', array($this, 'load_assignment_template'), 99 );
57 39
58 - add_filter( 'template_include', array( $this, 'student_public_profile' ), 99 );
59 - add_filter( 'template_include', array( $this, 'tutor_dashboard' ), 99 );
60 - add_filter( 'pre_get_document_title', array( $this, 'student_public_profile_title' ) );
40 + add_filter( 'template_include', array($this, 'student_public_profile'), 99 );
41 + add_filter( 'template_include', array($this, 'tutor_dashboard'), 99 );
42 + add_filter( 'pre_get_document_title', array($this, 'student_public_profile_title') );
61 43
62 - add_filter( 'the_content', array( $this, 'convert_static_page_to_template' ) );
63 - 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 );
44 + add_filter( 'the_content', array($this, 'convert_static_page_to_template'));
67 45 }
68 46
69 47 /**
48 + * @param $template
49 + *
50 + * @return bool|string
51 + *
70 52 * Load default template for course
71 53 *
72 54 * @since v.1.0.0
73 55 *
74 - * @param sting $template template name.
75 - *
76 - * @return bool|string
77 56 */
78 - public function load_course_archive_template( $template ) {
57 + public function load_course_archive_template($template){
79 58 global $wp_query;
80 59
81 - $post_type = get_query_var( 'post_type' );
82 - if ( ! is_array( $post_type ) ) {
83 - $post_type = array( $post_type );
84 - }
60 + $post_type = get_query_var('post_type');
61 + $course_category = get_query_var('course-category');
85 62
86 - $course_category = get_query_var( 'course-category' );
87 -
88 - if ( ( in_array( $this->course_post_type, $post_type, true ) || ! empty( $course_category ) ) && $wp_query->is_archive ) {
89 - $template = tutor_get_template( 'archive-course' );
63 + if ( ($post_type === $this->course_post_type || ! empty($course_category) ) && $wp_query->is_archive){
64 + $template = tutor_get_template('archive-course');
90 65 return $template;
91 66 }
92 67
93 68 return $template;
@@ -93,178 +68,195 @@
93 68 return $template;
94 69 }
95 70
96 71 /**
97 - * Limit for course archive listing
72 + * @param $query
98 73 *
74 + * limit for course archive listing
75 + *
99 76 * Make a page to archive listing for courses
100 - *
101 - * @since 1.0.0
102 - *
103 - * @param mixed $query query argument.
104 - *
105 - * @return void
106 77 */
107 - public function limit_course_query_archive( $query ) {
108 - $courses_per_page = (int) tutor_utils()->get_option( 'courses_per_page', 12 );
78 + public function limit_course_query_archive($query){
79 + $courses_per_page = (int) tutor_utils()->get_option('courses_per_page', 10);
109 80
110 - if ( $query->is_main_query() && ! $query->is_feed() && ! is_admin() && is_page() ) {
81 + if ($query->is_main_query() && ! $query->is_feed() && ! is_admin() && is_page() ){
111 82 $queried_object = get_queried_object();
112 - if ( $queried_object instanceof \WP_Post ) {
113 - $page_id = $queried_object->ID;
114 - $selected_archive_page = (int) apply_filters( 'tutor_filter_course_archive_page', tutor_utils()->get_option( 'course_archive_page' ) );
83 + if ($queried_object instanceof \WP_Post){
84 + $page_id = $queried_object->ID;
85 + $selected_archive_page = (int) tutor_utils()->get_option('course_archive_page');
115 86
116 - if ( $page_id === $selected_archive_page ) {
117 - $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
87 + if ($page_id === $selected_archive_page){
88 + $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
118 89 $search_query = get_search_query();
119 - query_posts(
120 - array(
121 - 'post_type' => $this->course_post_type,
122 - 'paged' => $paged,
123 - 's' => $search_query,
124 - 'posts_per_page' => $courses_per_page,
125 - )
126 - );
90 + query_posts(array('post_type' => $this->course_post_type, 'paged' => $paged, 's' => $search_query, 'posts_per_page' => $courses_per_page ));
127 91 }
128 92 }
129 93 }
130 94
131 - if ( $query->is_archive && $query->is_main_query() && ! $query->is_feed() && ! is_admin() ) {
132 - $post_type = get_query_var( 'post_type' );
133 - $course_category = get_query_var( 'course-category' );
134 - if ( ( $post_type === $this->course_post_type || ! empty( $course_category ) ) ) {
135 - $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 );
95 + if ( $query->is_archive && $query->is_main_query() && ! $query->is_feed() && ! is_admin() ){
96 + $post_type = get_query_var('post_type');
97 + $course_category = get_query_var('course-category');
98 + if ( ($post_type === $this->course_post_type || ! empty($course_category) )){
99 + $query->set('posts_per_page', $courses_per_page);
138 100
139 101 $course_filter = 'newest_first';
140 - if ( ! empty( Input::get( 'tutor_course_filter', '' ) ) ) {
141 - $course_filter = Input::get( 'tutor_course_filter' );
102 + if ( ! empty($_GET['tutor_course_filter'])){
103 + $course_filter = sanitize_text_field($_GET['tutor_course_filter']);
142 104 }
143 - switch ( $course_filter ) {
105 + switch ($course_filter){
144 106 case 'newest_first':
145 - $query->set( 'orderby', 'post_date' );
146 - $query->set( 'order', 'desc' );
107 + $query->set('orderby', 'ID');
108 + $query->set('order', 'desc');
147 109 break;
148 110 case 'oldest_first':
149 - $query->set( 'orderby', 'post_date' );
150 - $query->set( 'order', 'asc' );
111 + $query->set('orderby', 'ID');
112 + $query->set('order', 'asc');
151 113 break;
152 114 case 'course_title_az':
153 - $query->set( 'orderby', 'post_title' );
154 - $query->set( 'order', 'asc' );
115 + $query->set('orderby', 'post_title');
116 + $query->set('order', 'asc');
155 117 break;
156 118 case 'course_title_za':
157 - $query->set( 'orderby', 'post_title' );
158 - $query->set( 'order', 'desc' );
119 + $query->set('orderby', 'post_title');
120 + $query->set('order', 'desc');
159 121 break;
160 122 }
123 +
161 124 }
162 125 }
163 126 }
164 127
165 128 /**
129 + * @param $template
130 + *
131 + * @return bool|string
132 + *
166 133 * Load Single Course Template
167 134 *
168 135 * @since v.1.0.0
169 - *
170 - * @param string $template template name to load.
171 - *
172 - * @return bool|string
136 + * @updated v.1.3.5
173 137 */
174 - public function load_single_course_template( $template ) {
138 + public function load_single_course_template($template){
175 139 global $wp_query;
176 - 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();
140 +
141 + if ($wp_query->is_single && ! empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] === $this->course_post_type){
142 + $student_must_login_to_view_course = tutor_utils()->get_option('student_must_login_to_view_course');
143 + if ($student_must_login_to_view_course){
144 + if ( ! is_user_logged_in() ) {
145 + return tutor_get_template( 'login' );
146 + }
147 + }
148 +
149 + wp_reset_query();
150 + if (empty( $wp_query->query_vars['course_subpage'])) {
183 151 $template = tutor_get_template( 'single-course' );
152 + if ( is_user_logged_in() ) {
153 + $is_administrator = current_user_can('administrator');
154 + $is_instructor = tutor_utils()->is_instructor_of_this_course();
155 + $course_content_access = (bool) get_tutor_option('course_content_access_for_ia');
156 + if ( tutor_utils()->is_enrolled() ) {
157 + $template = tutor_get_template( 'single-course-enrolled' );
158 + } else if ( $course_content_access && ($is_administrator || $is_instructor) ) {
159 + $template = tutor_get_template( 'single-course-instructor' );
160 + }
161 + }
162 + }else{
163 + //If Course Subpage Exists
164 + if ( is_user_logged_in() ) {
165 + $course_subpage = $wp_query->query_vars['course_subpage'];
166 + $template = tutor_get_template_path( 'single-course-enrolled-' . $course_subpage );
167 + if ( ! file_exists( $template ) ) {
168 + $template = tutor_get_template( 'single-course-enrolled-subpage' );
169 + }
170 + }else{
171 + $template = tutor_get_template('login');
172 + }
184 173 }
174 + return $template;
185 175 }
186 -
187 176 return $template;
188 177 }
189 178
190 - /**
191 - * Get root post parent id
192 - *
193 - * @param int $id post id.
194 - *
195 - * @return int root post id
196 - */
197 - private function get_root_post_parent_id( $id ) {
198 - $ancestors = get_post_ancestors( $id );
199 - $root = is_array( $ancestors ) ? end( $ancestors ) : null;
179 + private function get_root_post_parent_id($id){
180 + $ancestors = get_post_ancestors($id);
181 + $root = is_array($ancestors) ? end($ancestors) : null;
200 182
201 - return is_numeric( $root ) ? $root : $id;
183 + return is_numeric($root) ? $root : $id;
202 184 }
203 185
204 186 /**
187 + * @param $template
188 + *
189 + * @return bool|string
190 + *
205 191 * Load lesson template
206 192 *
207 193 * @since v.1.0.0
208 - *
209 - * @since 4.0.0 Post type argument added
210 - *
211 - * @param string $template template name to load.
212 - * @param string $post_type Post type added.
213 - *
214 - * @return bool|string
215 194 */
216 - public function load_single_lesson_template( $template, $post_type ) {
217 - if ( tutor()->lesson_post_type !== $post_type ) {
218 - return $template;
219 - }
220 195
221 - $is_lesson_post_type = apply_filters( 'tutor_is_lesson_post_type', true, $post_type );
196 + public function load_single_lesson_template($template){
197 + global $wp_query;
222 198
223 - if ( $is_lesson_post_type ) {
199 + if ($wp_query->is_single && ! empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] === $this->lesson_post_type){
224 200 $page_id = get_the_ID();
225 201
226 - do_action( 'tutor_lesson_load_before', $template );
227 - setup_postdata( $page_id );
202 + do_action('tutor_lesson_load_before', $template);
228 203
229 - if ( is_user_logged_in() ) {
230 - $has_content_access = tutor_utils()->has_enrolled_content_access( 'lesson' );
231 - if ( $has_content_access ) {
204 + setup_postdata($page_id);
205 +
206 + if (is_user_logged_in()){
207 + $is_course_enrolled = tutor_utils()->is_course_enrolled_by_lesson();
208 +
209 + if ($is_course_enrolled) {
232 210 $template = tutor_get_template( 'single-lesson' );
233 - } else {
234 - $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
211 + }else{
212 + //You need to enroll first
213 + $template = tutor_get_template( 'single.lesson.required-enroll' );
214 +
215 + //Check Lesson edit access to support page builders
216 + if(current_user_can(tutor()->instructor_role) && tutils()->has_lesson_edit_access()){
217 + $template = tutor_get_template( 'single-lesson' );
218 + }
219 +
220 + /*
221 + * Check access for admin
222 + * @since 1.6.9
223 + */
224 + $course_content_access = (bool) get_tutor_option('course_content_access_for_ia');
225 + if($course_content_access && current_user_can('administrator')) {
226 + $template = tutor_get_template( 'single-lesson' );
227 + }
235 228 }
236 - } else {
237 - $template = tutor_get_template( 'login' );
229 + }else{
230 + $template = tutor_get_template('login');
238 231 }
239 232 wp_reset_postdata();
240 233
241 - // Forcefully show lessons if it is public and not paid.
242 - $course_id = $this->get_root_post_parent_id( $page_id );
243 - if ( 'yes' === get_post_meta( $course_id, '_tutor_is_public_course', true ) && ! tutor_utils()->is_course_purchasable( $course_id ) ) {
234 + // Forcefully show lessons if it is public and not paid
235 + $course_id = $this->get_root_post_parent_id($page_id);
236 + if(get_post_meta($course_id, '_tutor_is_public_course', true)=='yes' && !tutor_utils()->is_course_purchasable($course_id)){
244 237 $template = tutor_get_template( 'single-lesson' );
245 238 }
246 -
247 - return apply_filters( 'tutor_lesson_template', $template );
239 +
240 + return apply_filters('tutor_lesson_template', $template);
248 241 }
249 -
250 242 return $template;
251 243 }
252 244
253 245 /**
254 - * Play the video in this url.
246 + * @param $template
255 247 *
256 - * @param string $template template to load.
248 + * @return mixed
257 249 *
258 - * @return mixed
250 + * Play the video in this url.
259 251 */
260 - public function play_private_video( $template ) {
252 + public function play_private_video($template){
261 253 global $wp_query;
262 254
263 - if ( $wp_query->is_single && ! empty( $wp_query->query_vars['lesson_video'] ) && 'true' === $wp_query->query_vars['lesson_video'] ) {
255 + if ($wp_query->is_single && ! empty($wp_query->query_vars['lesson_video']) && $wp_query->query_vars['lesson_video'] === 'true') {
264 256
265 - $is_public_video = apply_filters( 'tutor_video_stream_is_public', false, get_the_ID() );
266 - if ( $is_public_video ) {
257 + $isPublicVideo = apply_filters('tutor_video_stream_is_public', false, get_the_ID());
258 + if ($isPublicVideo){
267 259 $video_info = tutor_utils()->get_video_info();
268 260 if ( $video_info ) {
269 261 $stream = new Video_Stream( $video_info->path );
270 262 $stream->start();
@@ -271,16 +263,16 @@
271 263 }
272 264 exit();
273 265 }
274 266
275 - if ( tutor_utils()->is_course_enrolled_by_lesson() ) {
267 + if (tutor_utils()->is_course_enrolled_by_lesson()) {
276 268 $video_info = tutor_utils()->get_video_info();
277 269 if ( $video_info ) {
278 270 $stream = new Video_Stream( $video_info->path );
279 271 $stream->start();
280 272 }
281 - } else {
282 - esc_html_e( 'Permission denied', 'tutor' );
273 + }else{
274 + _e('Permission denied', 'tutor');
283 275 }
284 276 exit();
285 277 }
286 278
@@ -287,200 +279,127 @@
287 279 return $template;
288 280 }
289 281
290 282 /**
291 - * Tutor Dashboard Page, Responsible to show dashboard stuffs
283 + * @param $content
292 284 *
293 - * @since 1.0.0
285 + * @return mixed
294 286 *
295 - * @param string $content page content.
287 + * Tutor Dashboard Page, Responsible to show dashboard stuffs
296 288 *
297 - * @return mixed
289 + * @since v.1.0.0
298 290 */
299 - 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;
291 + public function convert_static_page_to_template($content){
292 + //Dashboard Page
293 + $student_dashboard_page_id = (int) tutor_utils()->get_option('tutor_dashboard_page_id');
294 + if ($student_dashboard_page_id === get_the_ID()){
295 + $shortcode = new Shortcode();
296 + return $shortcode->tutor_dashboard();
311 297 }
312 298
313 - $page_id = get_the_ID();
314 -
315 - // Dashboard Page.
316 - $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();
299 + //Instructor Registration Page
300 + $instructor_register_page_page_id = (int) tutor_utils()->get_option('instructor_register_page');
301 + if ($instructor_register_page_page_id === get_the_ID()){
302 + $shortcode = new Shortcode();
303 + return $shortcode->instructor_registration_form();
319 304 }
320 305
321 - // Instructor Registration Page.
322 - $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();
306 + $student_register_page_id = (int) tutor_utils()->get_option('student_register_page');
307 + if ($student_register_page_id === get_the_ID()){
308 + $shortcode = new Shortcode();
309 + return $shortcode->student_registration_form();
325 310 }
326 311
327 - $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();
330 - }
331 -
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 312 return $content;
349 313 }
350 314
351 - /**
352 - * Tutor dashboard
353 - *
354 - * @since 1.0.0
355 - *
356 - * @param string $template template name.
357 - *
358 - * @return string
359 - */
360 - public function tutor_dashboard( $template ) {
315 + public function tutor_dashboard($template){
361 316 global $wp_query;
362 - $is_page = apply_filters( 'tutor_determine_is_page', $wp_query->is_page, $template );
363 - if ( $is_page ) {
364 - $student_dashboard_page_id = (int) tutor_utils()->get_option( 'tutor_dashboard_page_id' );
365 - $student_dashboard_page_id = apply_filters( 'tutor_dashboard_page_id_filter', $student_dashboard_page_id );
366 - $is_dashboard_page = apply_filters( 'tutor_determine_is_dashboard_page', get_the_ID() == $student_dashboard_page_id );
367 317
368 - if ( $is_dashboard_page ) {
318 + if ($wp_query->is_page) {
319 + $student_dashboard_page_id = (int) tutor_utils()->get_option('tutor_dashboard_page_id');
320 + if ($student_dashboard_page_id === get_the_ID()) {
369 321 /**
370 322 * Handle if logout URL
371 - *
372 323 * @since v.1.1.2
373 324 */
374 - if ( tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars ) === 'logout' ) {
375 - $redirect = apply_filters( 'tutor_dashboard_logout_redirect_url', get_permalink( $student_dashboard_page_id ) );
325 + if (tutor_utils()->array_get('tutor_dashboard_page', $wp_query->query_vars) === 'logout'){
326 + $redirect = get_permalink($student_dashboard_page_id);
376 327 wp_logout();
377 - wp_safe_redirect( $redirect );
328 + wp_redirect($redirect);
378 329 die();
379 330 }
380 331
381 - $dashboard_page = tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars );
382 332
383 - $get_dashboard_config = tutor_utils()->tutor_dashboard_permalinks();
384 - $target_dashboard_page = tutor_utils()->array_get( $dashboard_page, $get_dashboard_config );
333 + $dashboard_page = tutor_utils()->array_get('tutor_dashboard_page', $wp_query->query_vars);
334 + $get_dashboard_config = tutils()->tutor_dashboard_permalinks();
335 + $target_dashboard_page = tutils()->array_get($dashboard_page, $get_dashboard_config);
385 336
386 - if ( isset( $target_dashboard_page['login_require'] ) && false === $target_dashboard_page['login_require'] ) {
337 + if (isset($target_dashboard_page['login_require']) && $target_dashboard_page['login_require'] === false){
387 338 $template = tutor_load_template_part( "template-part.{$dashboard_page}" );
388 - } else {
339 + }else{
389 340
390 341 /**
391 342 * Load view page based on dashboard Endpoint
392 343 */
393 - if ( is_user_logged_in() ) {
394 -
395 - global $wp;
396 - $full_path = explode( '/', trim( str_replace( get_home_url(), '', home_url( $wp->request ) ), '/' ) );
397 -
398 - $template = tutor_get_template( 'create-course' === end( $full_path ) ? 'dashboard.create-course' : 'dashboard' );
399 -
344 + if (is_user_logged_in()) {
345 + $template = tutor_get_template( 'dashboard' );
400 346 /**
401 347 * Check page page permission
402 348 *
403 - * @since 1.3.4
349 + * @since v.1.3.4
404 350 */
405 - $query_var = tutor_utils()->array_get( 'tutor_dashboard_page', $wp_query->query_vars );
406 - $dashboard_pages = tutor_utils()->tutor_dashboard_pages();
407 - $dashboard_page_item = tutor_utils()->array_get( $query_var, $dashboard_pages );
408 - $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 - ) {
414 - $template = tutor_get_template( 'permission-denied' );
351 + $query_var = tutor_utils()->array_get('tutor_dashboard_page', $wp_query->query_vars);
352 + $dashboard_pages = tutor_utils()->tutor_dashboard_pages();
353 + $dashboard_page_item = tutor_utils()->array_get($query_var, $dashboard_pages);
354 + $auth_cap = tutor_utils()->array_get('auth_cap', $dashboard_page_item);
355 + if ($auth_cap && ! current_user_can($auth_cap) ){
356 + wp_die(__('Permission Denied', 'tutor'));
415 357 }
416 358
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 - } else {
359 + }else{
440 360 $template = tutor_get_template( 'login' );
441 361 }
362 +
442 363 }
364 +
443 365 }
444 366 }
367 +
445 368 return $template;
446 369 }
447 370
448 371 /**
449 - * Load quiz template
372 + * @param $template
450 373 *
451 - * @since 1.0.0
374 + * @return bool|string
452 375 *
453 - * If course public then enrollment not required
454 - *
455 - * @since 2.0.2
456 - * @since 4.0.0 $post_type param added.
457 - *
458 - * @param string $template template to load.
459 - * @param string $post_type Post type.
460 - *
461 - * @return bool|string
376 + * @since v.1.0.0
462 377 */
463 - public function load_quiz_template( $template, $post_type ) {
464 - if ( tutor()->quiz_post_type !== $post_type ) {
378 + public function load_quiz_template($template){
379 + global $wp_query;
380 +
381 + if ($wp_query->is_single && ! empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] === 'tutor_quiz'){
382 + if (is_user_logged_in()){
383 + $template = tutor_get_template( 'single-quiz' );
384 + }else{
385 + $template = tutor_get_template('login');
386 + }
465 387 return $template;
466 388 }
389 + return $template;
390 + }
467 391
468 - global $post;
392 + public function load_assignment_template($template){
393 + global $wp_query;
469 394
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' );
478 - } else {
479 - $template = tutor_get_template( 'single.lesson.required-enroll' ); // You need to enroll first.
395 + if ($wp_query->is_single && ! empty($wp_query->query_vars['post_type']) && $wp_query->query_vars['post_type'] === 'tutor_assignments'){
396 + if (is_user_logged_in()){
397 + $template = tutor_get_template( 'single-assignment' );
398 + }else{
399 + $template = tutor_get_template('login');
480 400 }
481 - } else {
482 - $template = tutor_get_template( 'login' );
401 + return $template;
483 402 }
484 403
485 404 return $template;
486 405 }
@@ -485,21 +404,19 @@
485 404 return $template;
486 405 }
487 406
488 407 /**
489 - * Student public profile
408 + * @param $template
490 409 *
491 - * @since 1.0.0
410 + * @return bool|string
492 411 *
493 - * @param string $template profile template.
494 - *
495 - * @return bool|string
412 + * @since v.1.0.0
496 413 */
497 - public function student_public_profile( $template ) {
414 + public function student_public_profile($template){
498 415 global $wp_query;
499 - $query_var = $wp_query->query_vars;
500 - if ( ! empty( $wp_query->query['tutor_profile_username'] ) ) {
501 - $template = tutor_get_template( 'public-profile' );
416 +
417 + if ( ! empty($wp_query->query['tutor_student_username'])){
418 + $template = tutor_get_template( 'student-public-profile' );
502 419 }
503 420
504 421 return $template;
505 422 }
@@ -504,97 +421,27 @@
504 421 return $template;
505 422 }
506 423
507 424 /**
425 + * @return string
508 426 * Show student Profile
509 427 *
510 - * @since 1.0.0
511 - *
512 - * @return string
428 + * @since v.1.0.0
513 429 */
514 - public function student_public_profile_title() {
430 + public function student_public_profile_title(){
515 431 global $wp_query;
516 432
517 - if ( ! empty( $wp_query->query['tutor_profile_username'] ) ) {
433 + if ( ! empty($wp_query->query['tutor_student_username'])){
518 434 global $wpdb;
519 435
520 - $user_name = sanitize_text_field( $wp_query->query['tutor_profile_username'] );
521 - $user = $wpdb->get_row( $wpdb->prepare( "SELECT display_name from {$wpdb->users} WHERE user_login = %s limit 1; ", $user_name ) );
436 + $user_name = sanitize_text_field($wp_query->query['tutor_student_username']);
437 + $user = $wpdb->get_row("select display_name from {$wpdb->users} WHERE user_login = '{$user_name}' limit 1; ");
522 438
523 - if ( ! empty( $user->display_name ) ) {
524 - return sprintf( "%s's %s", $user->display_name, __( 'Profile Page', 'tutor' ) );
439 + if ( ! empty($user->display_name)){
440 + return sprintf("%s's Profile page ", $user->display_name );
525 441 }
526 442 }
527 443 return '';
528 444 }
529 445
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 446
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 - }
600 -}
447 +}