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.0 3.6.0 3.6.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 / Dashboard.php
tutor / classes Last commit date
Addons.php 20 hours ago Admin.php 20 hours ago Ajax.php 20 hours ago Announcements.php 20 hours ago Assets.php 20 hours ago Backend_Page_Trait.php 1 year ago BaseController.php 1 year ago Config.php 20 hours ago Container.php 11 months ago Course.php 20 hours ago Course_Embed.php 3 years ago Course_Filter.php 20 hours ago Course_List.php 20 hours ago Course_Settings_Tabs.php 20 hours ago Course_Widget.php 1 year ago Custom_Validation.php 20 hours ago Dashboard.php 20 hours ago Earnings.php 9 months ago FormHandler.php 20 hours ago Frontend.php 20 hours ago Gutenberg.php 1 year ago Icon.php 20 hours ago Input.php 20 hours ago Instructor.php 20 hours ago Instructors_List.php 20 hours ago Lesson.php 20 hours ago Options_V2.php 20 hours ago Permalink.php 20 hours ago Post_types.php 1 day ago Private_Course_Access.php 20 hours ago Q_And_A.php 20 hours ago Question_Answers_List.php 11 months ago Quiz.php 20 hours ago QuizBuilder.php 20 hours ago Quiz_Attempts_List.php 20 hours ago RestAPI.php 2 years ago Reviews.php 20 hours ago Rewrite_Rules.php 2 years ago SampleCourse.php 20 hours ago Shortcode.php 20 hours ago Singleton.php 1 year ago Student.php 20 hours ago Students_List.php 1 year ago Taxonomies.php 1 year ago Template.php 20 hours ago Theme_Compatibility.php 3 years ago Tools.php 1 year ago Tools_V2.php 4 weeks ago Tutor.php 20 hours ago TutorEDD.php 20 hours ago Tutor_Base.php 2 years ago Tutor_Setup.php 20 hours ago Upgrader.php 20 hours ago User.php 20 hours ago UserPreference.php 20 hours ago Utils.php 20 hours ago Video_Stream.php 3 years ago WhatsNew.php 10 months ago Withdraw.php 20 hours ago Withdraw_Requests_List.php 11 months ago WooCommerce.php 20 hours ago
Dashboard.php
371 lines
1 <?php
2 /**
3 * Manage Frontend Dashboard
4 *
5 * @package Tutor
6 * @author Themeum <support@themeum.com>
7 * @link https://themeum.com
8 * @since 1.3.4
9 */
10
11 namespace TUTOR;
12
13 defined( 'ABSPATH' ) || exit;
14
15 use Tutor\Helpers\UrlHelper;
16
17 /**
18 * Dashboard Class
19 *
20 * @since 1.3.4
21 */
22 class Dashboard {
23
24 /**
25 * Dashboard page constants
26 *
27 * @since 4.0.0
28 */
29 const ACCOUNT_PAGE_SLUG = 'account';
30 const COURSES_PAGE_SLUG = 'courses';
31 const QUIZ_ATTEMPTS_PAGE_SLUG = 'quiz-attempts';
32 const MY_QUIZ_ATTEMPTS_SUBPAGE_SLUG = 'my-quiz-attempts';
33 const REVIEW_PAGE_SLUG = 'reviews';
34 const PROFILE_PAGE_SLUG = 'my-profile';
35 const SETTINGS_PAGE_SLUG = 'settings';
36 const Q_AND_A_PAGE_SLUG = 'question-answer';
37 const DISCUSSION_PAGE_SLUG = 'discussions';
38 const PURCHASE_HISTORY_PAGE_SLUG = 'purchase_history';
39 const BILLING_PAGE_SLUG = 'billing';
40 const WISHLIST_PAGE_SLUG = 'wishlist';
41 const ENROLLED_COURSES_PAGE_SLUG = 'enrolled-courses';
42
43 /**
44 * Constructor
45 *
46 * @since 1.3.4
47 *
48 * @return void
49 */
50 public function __construct() {
51 add_action( 'tutor_load_template_after', array( $this, 'tutor_load_template_after' ), 10, 2 );
52 add_filter( 'should_tutor_load_template', array( $this, 'should_tutor_load_template' ), 10, 2 );
53 add_action( 'template_redirect', array( $this, 'redirect_old_dashboard_pages' ) );
54 add_filter( 'tutor_dashboard_back_url', array( $this, 'filter_dashboard_back_url' ) );
55 }
56
57 /**
58 * Redirect user old dashboard page slugs to new slugs.
59 *
60 * @since 4.0.0
61 *
62 * @return void
63 */
64 public function redirect_old_dashboard_pages() {
65 $current_url = rtrim( UrlHelper::current(), '/' );
66
67 if ( ! is_admin() ) {
68 // Redirect logic here.
69 $redirect_mappings = array(
70 tutor_utils()->tutor_dashboard_url( self::PROFILE_PAGE_SLUG ) => self::get_account_page_url( 'profile' ),
71 tutor_utils()->tutor_dashboard_url( self::REVIEW_PAGE_SLUG ) => self::get_account_page_url( self::REVIEW_PAGE_SLUG ),
72 tutor_utils()->tutor_dashboard_url( self::SETTINGS_PAGE_SLUG ) => self::get_account_page_url( self::SETTINGS_PAGE_SLUG ),
73 tutor_utils()->tutor_dashboard_url( self::Q_AND_A_PAGE_SLUG ) => tutor_utils()->tutor_dashboard_url( self::DISCUSSION_PAGE_SLUG ),
74 tutor_utils()->tutor_dashboard_url( self::PURCHASE_HISTORY_PAGE_SLUG ) => self::get_account_page_url( self::BILLING_PAGE_SLUG ),
75 tutor_utils()->tutor_dashboard_url( self::WISHLIST_PAGE_SLUG ) => tutor_utils()->tutor_dashboard_url( 'courses/wishlist' ),
76 tutor_utils()->tutor_dashboard_url( self::MY_QUIZ_ATTEMPTS_SUBPAGE_SLUG ) => tutor_utils()->tutor_dashboard_url( 'courses/my-quiz-attempts' ),
77 tutor_utils()->tutor_dashboard_url( self::ENROLLED_COURSES_PAGE_SLUG ) => tutor_utils()->tutor_dashboard_url( self::COURSES_PAGE_SLUG ),
78 tutor_utils()->get_tutor_dashboard_page_permalink( 'logout' ) => UrlHelper::add_query_params( wp_logout_url(), array( '_wpnonce' => wp_create_nonce( 'log-out' ) ) ),
79 );
80
81 if ( ! isset( $redirect_mappings[ $current_url ] ) ) {
82 return;
83 }
84
85 $redirect_url = $redirect_mappings[ $current_url ];
86
87 if ( tutor_utils()->count( $_GET ) ) {
88 $redirect_url = UrlHelper::add_query_params( $redirect_url, $_GET );
89 }
90
91 wp_safe_redirect( $redirect_url );
92 exit;
93 }
94 }
95
96
97 /**
98 * Get account page URL.
99 *
100 * @since 4.0.0
101 *
102 * @param string $page page name.
103 *
104 * @return string
105 */
106 public static function get_account_page_url( $page = '' ) {
107 $account_page_url = tutor_utils()->tutor_dashboard_url( self::ACCOUNT_PAGE_SLUG );
108 if ( empty( $page ) ) {
109 return $account_page_url;
110 }
111
112 return trailingslashit( $account_page_url ) . $page;
113 }
114
115 /**
116 * Get account pages.
117 *
118 * @since 4.0.0
119 *
120 * @return array
121 */
122 public static function get_account_pages() {
123 $pages = array(
124 'profile' => array(
125 'title' => esc_html__( 'Profile', 'tutor' ),
126 'icon' => Icon::USER_CIRCLE,
127 'icon_active' => Icon::USER_CIRCLE_FILL,
128 'url' => self::get_account_page_url( 'profile' ),
129 'template' => tutor_get_template( 'dashboard.account.profile' ),
130 ),
131 'reviews' => array(
132 'title' => esc_html__( 'Reviews', 'tutor' ),
133 'icon' => Icon::RATINGS,
134 'icon_active' => Icon::RATINGS,
135 'url' => self::get_account_page_url( 'reviews' ),
136 'template' => tutor_get_template( 'dashboard.account.reviews' ),
137 ),
138 );
139
140 if ( User::is_student_view() ) {
141 $pages['billing'] = array(
142 'title' => esc_html__( 'Billing', 'tutor' ),
143 'icon' => Icon::BILLING,
144 'icon_active' => Icon::BILLING,
145 'url' => self::get_account_page_url( 'billing' ),
146 'template' => tutor_get_template( 'dashboard.account.billing' ),
147 );
148 }
149
150 if ( User::is_instructor_view() ) {
151 $pages['withdrawals'] = array(
152 'title' => esc_html__( 'Withdrawals', 'tutor' ),
153 'icon' => Icon::WALLET,
154 'icon_active' => Icon::WALLET,
155 'url' => self::get_account_page_url( 'withdrawals' ),
156 'template' => tutor_get_template( 'dashboard.account.withdrawals' ),
157 );
158 }
159
160 $pages['settings'] = array(
161 'title' => esc_html__( 'Settings', 'tutor' ),
162 'icon' => Icon::SETTING,
163 'icon_active' => Icon::SETTING,
164 'url' => self::get_account_page_url( 'settings' ),
165 'template' => tutor_get_template( 'dashboard.account.settings' ),
166 );
167
168 return apply_filters( 'tutor_dashboard_account_pages', $pages );
169 }
170
171 /**
172 * Get isolated dashboard pages.
173 *
174 * @since 4.0.0
175 *
176 * @return array
177 */
178 public static function get_isolated_pages() {
179 $pages = array(
180 self::QUIZ_ATTEMPTS_PAGE_SLUG => array(
181 'title' => esc_html__( 'Quiz attempts', 'tutor' ),
182 'template' => tutor_get_template( 'dashboard.quiz-attempts.quiz-reviews' ),
183 'requires_param' => 'attempt_id',
184 ),
185 self::COURSES_PAGE_SLUG . '/' . self::MY_QUIZ_ATTEMPTS_SUBPAGE_SLUG => array(
186 'title' => esc_html__( 'Quiz details', 'tutor' ),
187 'template' => tutor_get_template( 'dashboard.my-quiz-attempts.attempts-details' ),
188 'requires_param' => 'attempt_id',
189 ),
190 );
191
192 return apply_filters( 'tutor_dashboard_isolated_pages', $pages );
193 }
194
195 /**
196 * Get isolated dashboard page key.
197 *
198 * @since 4.0.0
199 *
200 * @param string $dashboard_page Dashboard page slug.
201 * @param string $dashboard_subpage Dashboard subpage slug.
202 *
203 * @return string
204 */
205 public static function get_isolated_page_key( string $dashboard_page = '', string $dashboard_subpage = '' ): string {
206 if ( self::QUIZ_ATTEMPTS_PAGE_SLUG === $dashboard_page ) {
207 return self::QUIZ_ATTEMPTS_PAGE_SLUG;
208 }
209
210 if ( self::COURSES_PAGE_SLUG === $dashboard_page && self::MY_QUIZ_ATTEMPTS_SUBPAGE_SLUG === $dashboard_subpage ) {
211 return self::COURSES_PAGE_SLUG . '/' . self::MY_QUIZ_ATTEMPTS_SUBPAGE_SLUG;
212 }
213
214 return '';
215 }
216
217 /**
218 * Check if the current request should use an isolated dashboard page.
219 *
220 * @since 4.0.0
221 *
222 * @param string $dashboard_page Dashboard page slug.
223 * @param string $dashboard_subpage Dashboard subpage slug.
224 *
225 * @return bool
226 */
227 public static function is_isolated_page_request( string $dashboard_page = '', string $dashboard_subpage = '' ): bool {
228 $page_key = self::get_isolated_page_key( $dashboard_page, $dashboard_subpage );
229 $isolated_pages = self::get_isolated_pages();
230 $page_data = $isolated_pages[ $page_key ] ?? array();
231
232 if ( empty( $page_data ) ) {
233 return false;
234 }
235
236 $required_param = $page_data['requires_param'] ?? '';
237
238 return '' === $required_param ? true : Input::has( $required_param );
239 }
240
241 /**
242 * Load template after
243 *
244 * @since 1.3.4
245 * @return void
246 */
247 public function tutor_load_template_after() {
248 global $wp_query;
249
250 $tutor_dashboard_page = tutor_utils()->array_get( 'query_vars.tutor_dashboard_page', $wp_query );
251 if ( 'create-course' === $tutor_dashboard_page ) {
252 wp_reset_query();
253 }
254 }
255
256 /**
257 * Check template need to load or not
258 *
259 * @since 1.3.4
260 *
261 * @param bool $bool true or false.
262 * @param string $template template name.
263 *
264 * @return boolean
265 */
266 public function should_tutor_load_template( $bool, $template ) {
267 if ( 'dashboard.create-course' === $template && ! tutor()->has_pro ) {
268 return false;
269 }
270 return $bool;
271 }
272
273 /**
274 * Filter dashboard back URL.
275 *
276 * @since 4.0.0
277 *
278 * @param string $url URL.
279 *
280 * @return string
281 */
282 public function filter_dashboard_back_url( string $url ): string {
283 if ( ! Input::has( 'back_url', Input::GET_REQUEST ) ) {
284 return $url;
285 }
286
287 $back_url = Input::get( 'back_url', '' );
288 $decoded = urldecode( $back_url );
289 if ( ! str_starts_with( $decoded, home_url() ) ) {
290 return $url;
291 }
292
293 return esc_url_raw( $decoded );
294 }
295
296 /**
297 * Build page metadata from page configuration.
298 *
299 * @since 4.0.0
300 *
301 * @param string $page_slug Page slug.
302 * @param string $page_subslug Page subpage slug.
303 * @param array $pages Page definitions.
304 *
305 * @return array
306 */
307 public static function get_page_meta_data( string $page_slug = '', string $page_subslug = '', array $pages = array() ): array {
308 $page_data = array();
309 $page_meta_data = array(
310 'page_data' => array(),
311 'meta_title' => '',
312 );
313 $page_key = trim( $page_slug . '/' . $page_subslug, '/' );
314
315 if ( $page_subslug && isset( $pages[ $page_subslug ] ) ) {
316 $page_data = $pages[ $page_subslug ];
317 }
318
319 if ( $page_slug && isset( $pages[ $page_slug ] ) ) {
320 $page_data = $pages[ $page_slug ];
321 }
322
323 if ( $page_key && isset( $pages[ $page_key ] ) ) {
324 $page_data = $pages[ $page_key ];
325 }
326
327 if ( empty( $page_data ) ) {
328 return $page_meta_data;
329 }
330
331 $page_title = isset( $page_data['title'] ) ? $page_data['title'] : '';
332
333 if ( $page_subslug ) {
334 $slug = str_replace( array( '-', '_', '/' ), ' ', (string) $page_subslug );
335 $page_title = wp_strip_all_tags( ucfirst( $slug ) );
336 }
337
338 $site_name = get_bloginfo( 'name' );
339 $meta_title = '';
340
341 if ( '' !== $page_title ) {
342 /* translators: 1: current page title, 2: site name. */
343 $meta_title = sprintf( __( '%1$s - %2$s', 'tutor' ), $page_title, $site_name );
344 }
345
346 $page_meta_data['page_data'] = $page_data;
347 $page_meta_data['meta_title'] = $meta_title;
348
349 return $page_meta_data;
350 }
351
352 /**
353 * Set the document title for custom frontend templates.
354 *
355 * @since 4.0.0
356 *
357 * @param string $title Document title.
358 *
359 * @return void
360 */
361 public static function set_document_title( string $title ): void {
362 add_filter(
363 'pre_get_document_title',
364 static function () use ( $title ) {
365 return $title;
366 },
367 999
368 );
369 }
370 }
371