Skip to content

Commit 138ddd1

Browse files
authored
Merge pull request #2294 from themeum/harun-v4
🎉 Account page routing and template loading mechanism
2 parents 0b0e396 + 563e55b commit 138ddd1

File tree

12 files changed

+256
-40
lines changed

12 files changed

+256
-40
lines changed

assets/src/scss/frontend/dashboard/_index.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@forward 'layout/nav-mobile';
99
@forward 'layout/profile-header';
1010
@forward 'layout/profile-pages';
11+
@forward 'layout/account';
1112

1213
// Dashboard components
1314
@forward "stat-card";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@use '@Core/scss/mixins' as *;
2+
@use '@Core/scss/tokens' as *;
3+
4+
.tutor-account-page-wrapper {
5+
.tutor-account-header {
6+
@include tutor-breakpoint-down(sm) {
7+
display: none;
8+
}
9+
}
10+
11+
.tutor-account-header {
12+
background-color: $tutor-surface-base;
13+
border-bottom: 1px solid $tutor-border-idle;
14+
padding-block: $tutor-spacing-5;
15+
16+
&-title {
17+
@include tutor-typography(h4, semibold, primary, heading);
18+
19+
@include tutor-breakpoint-up(sm) {
20+
margin-inline-end: auto;
21+
margin-inline-start: $tutor-spacing-4;
22+
}
23+
}
24+
}
25+
26+
.tutor-account-container {
27+
max-width: 728px;
28+
margin: 0 auto;
29+
padding-inline: $tutor-spacing-6;
30+
}
31+
}

classes/Dashboard.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
namespace TUTOR;
1212

13+
use Tutor\Helpers\UrlHelper;
14+
1315
if ( ! defined( 'ABSPATH' ) ) {
1416
exit;
1517
}
@@ -20,6 +22,14 @@
2022
*/
2123
class Dashboard {
2224

25+
/**
26+
* Account page constants
27+
*
28+
* @since 4.0.0
29+
*/
30+
const ACCOUNT_PAGE_SLUG = 'account';
31+
const ACCOUNT_PAGE_QUERY_PARAM = 'subpage';
32+
2333
/**
2434
* Constructor
2535
*
@@ -31,6 +41,60 @@ public function __construct() {
3141
add_filter( 'should_tutor_load_template', array( $this, 'should_tutor_load_template' ), 10, 2 );
3242
}
3343

44+
45+
/**
46+
* Get account page URL.
47+
*
48+
* @since 4.0.0
49+
*
50+
* @param string $page page name.
51+
*
52+
* @return string
53+
*/
54+
public static function get_account_page_url( $page = '' ) {
55+
$account_page_url = tutor_utils()->tutor_dashboard_url( self::ACCOUNT_PAGE_SLUG );
56+
if ( empty( $page ) ) {
57+
return $account_page_url;
58+
}
59+
60+
return UrlHelper::add_query_params( $account_page_url, array( self::ACCOUNT_PAGE_QUERY_PARAM => $page ) );
61+
}
62+
63+
/**
64+
* Get account pages.
65+
*
66+
* @since 4.0.0
67+
*
68+
* @return array
69+
*/
70+
public static function get_account_pages() {
71+
$pages = array(
72+
'profile' => array(
73+
'title' => esc_html__( 'Profile', 'tutor' ),
74+
'icon' => Icon::PROFILE_CIRCLE,
75+
'icon_active' => Icon::PROFILE_CIRCLE_FILL,
76+
'url' => self::get_account_page_url( 'profile' ),
77+
'template' => tutor_get_template( 'dashboard.account.profile' ),
78+
),
79+
'reviews' => array(
80+
'title' => esc_html__( 'Reviews', 'tutor' ),
81+
'icon' => Icon::RATINGS,
82+
'icon_active' => Icon::RATINGS,
83+
'url' => self::get_account_page_url( 'reviews' ),
84+
'template' => tutor_get_template( 'dashboard.account.reviews' ),
85+
),
86+
'settings' => array(
87+
'title' => esc_html__( 'Settings', 'tutor' ),
88+
'icon' => Icon::SETTING,
89+
'icon_active' => Icon::SETTING,
90+
'url' => self::get_account_page_url( 'settings' ),
91+
'template' => tutor_get_template( 'dashboard.account.settings' ),
92+
),
93+
);
94+
95+
return apply_filters( 'tutor_dashboard_account_pages', $pages );
96+
}
97+
3498
/**
3599
* Load template after
36100
*

classes/Template.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,22 @@ public function tutor_dashboard( $template ) {
392392
if ( $auth_cap && ! current_user_can( $auth_cap ) ) {
393393
$template = tutor_get_template( 'permission-denied' );
394394
}
395+
396+
/**
397+
* Account pages of dashboard.
398+
*
399+
* @since 4.0.0
400+
*/
401+
if ( Dashboard::ACCOUNT_PAGE_SLUG === $dashboard_page ) {
402+
$subpage = Input::get( Dashboard::ACCOUNT_PAGE_QUERY_PARAM, 'profile' );
403+
$account_pages = Dashboard::get_account_pages();
404+
$page_data = $account_pages[ $subpage ] ?? array();
405+
$page_template = $page_data['template'] ?? '';
406+
407+
if ( file_exists( $page_template ) ) {
408+
$template = tutor_get_template( 'account' );
409+
}
410+
}
395411
} else {
396412
$template = tutor_get_template( 'login' );
397413
}

classes/Utils.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2923,7 +2923,17 @@ public function tutor_dashboard_pages() {
29232923
$student_nav_items = apply_filters( 'tutor_dashboard/nav_items', $this->default_menus() );
29242924
$instructor_nav_items = apply_filters( 'tutor_dashboard/instructor_nav_items', $this->instructor_menus() );
29252925

2926-
$all_menus = array_merge( $student_nav_items, $instructor_nav_items );
2926+
/**
2927+
* Miscellaneous menus pages
2928+
* Which are not visible to any nav.
2929+
*
2930+
* @since 4.0.0
2931+
*/
2932+
$misc_menus = array(
2933+
'account' => array( 'label' => __( 'Account', 'tutor' ) ),
2934+
);
2935+
2936+
$all_menus = array_merge( $student_nav_items, $instructor_nav_items, $misc_menus );
29272937

29282938
return apply_filters( 'tutor_dashboard/nav_items_all', $all_menus );
29292939
}

helpers/UrlHelper.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,5 +88,22 @@ public static function add_query_params( $url, array $query_params = array() ) :
8888
public static function remove_query_params( $url, array $query_params = array() ) : string {
8989
return remove_query_arg( $query_params, $url );
9090
}
91+
92+
/**
93+
* Get back URL.
94+
*
95+
* @since 4.0.0
96+
*
97+
* @param string $fallback fallback URL.
98+
*
99+
* @return string
100+
*/
101+
public static function back( $fallback = '' ) : string {
102+
$back_url = wp_get_referer();
103+
if ( empty( $back_url ) ) {
104+
$back_url = empty( $fallback ) ? self::current() : $fallback;
105+
}
106+
return $back_url;
107+
}
91108
}
92109

templates/account-header.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Base Template for Account
4+
*
5+
* @package Tutor\Templates
6+
* @author Themeum <support@themeum.com>
7+
* @link https://themeum.com
8+
* @since 4.0.0
9+
*/
10+
11+
use TUTOR\Icon;
12+
13+
defined( 'ABSPATH' ) || exit;
14+
15+
?>
16+
<div class="tutor-account-header">
17+
<div class="tutor-account-container">
18+
<div class="tutor-flex tutor-items-center tutor-justify-between">
19+
<a href="<?php echo esc_url( $back_url ); ?>" class="tutor-btn tutor-btn-ghost tutor-btn-x-small tutor-btn-icon">
20+
<?php tutor_utils()->render_svg_icon( Icon::LEFT ); ?>
21+
</a>
22+
<h4 class="tutor-account-header-title">
23+
<?php echo esc_html( $page_data['title'] ?? '' ); ?>
24+
</h4>
25+
<a href="<?php echo esc_url( $back_url ); ?>" class="tutor-btn tutor-btn-ghost tutor-btn-x-small tutor-btn-icon">
26+
<?php tutor_utils()->render_svg_icon( Icon::CROSS ); ?>
27+
</a>
28+
</div>
29+
</div>
30+
</div>

templates/account.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Base Template for Account
4+
*
5+
* @package Tutor\Templates
6+
* @author Themeum <support@themeum.com>
7+
* @link https://themeum.com
8+
* @since 4.0.0
9+
*/
10+
11+
use TUTOR\Dashboard;
12+
use Tutor\Helpers\UrlHelper;
13+
use TUTOR\Icon;
14+
use TUTOR\Input;
15+
16+
defined( 'ABSPATH' ) || exit;
17+
18+
wp_head();
19+
20+
$subpage = Input::get( Dashboard::ACCOUNT_PAGE_QUERY_PARAM, 'profile' );
21+
$account_pages = Dashboard::get_account_pages();
22+
$page_data = $account_pages[ $subpage ] ?? array();
23+
$page_template = $page_data['template'] ?? '';
24+
25+
$back_url = UrlHelper::back( tutor_utils()->tutor_dashboard_url() );
26+
?>
27+
<div class="tutor-account-page-wrapper">
28+
<?php require_once $page_template; ?>
29+
</div>
30+
<?php wp_footer(); ?>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* Profile Template for Account
4+
*
5+
* @package Tutor\Templates
6+
* @subpackage Dashboard
7+
* @author Themeum <support@themeum.com>
8+
* @link https://themeum.com
9+
* @since 4.0.0
10+
*/
11+
12+
defined( 'ABSPATH' ) || exit;
13+
?>
14+
15+
<div class="tutor-profile-wrapper">
16+
<?php require_once tutor_get_template( 'account-header' ); ?>
17+
18+
<div class="tutor-profile-container">
19+
<div class="tutor-flex tutor-flex-column tutor-gap-5 tutor-mt-9">
20+
</div>
21+
</div>
22+
</div>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* Reviews Template for Account
4+
*
5+
* @package Tutor\Templates
6+
* @subpackage Dashboard
7+
* @author Themeum <support@themeum.com>
8+
* @link https://themeum.com
9+
* @since 4.0.0
10+
*/
11+
12+
defined( 'ABSPATH' ) || exit;
13+

0 commit comments

Comments
 (0)