Skip to content

Commit a3850ff

Browse files
committed
refactor: move default_menus and instructor_menus and refactor tutor_dashboard_pages to accept a context parameter for menu retrieval.
1 parent 5bfbbe0 commit a3850ff

1 file changed

Lines changed: 115 additions & 115 deletions

File tree

classes/Utils.php

Lines changed: 115 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,22 +2921,127 @@ public function is_tutor_order( $order_id ) {
29212921
}
29222922
}
29232923

2924+
/**
2925+
* Separation of all menu items for providing ease of usage
2926+
*
2927+
* @since 2.0.0
2928+
*
2929+
* @since 4.0.0 Menu item updated based on student view
2930+
*
2931+
* @return array array of menu items.
2932+
*/
2933+
public function default_menus(): array {
2934+
$items = array(
2935+
'index' => array(
2936+
'title' => __( 'Home', 'tutor' ),
2937+
'icon' => Icon::HOME,
2938+
),
2939+
'courses' => array(
2940+
'title' => __( 'Courses', 'tutor' ),
2941+
'icon' => Icon::COURSES,
2942+
),
2943+
'retrieve-password' => array(
2944+
'title' => __( 'Retrieve Password', 'tutor' ),
2945+
'show_ui' => false,
2946+
'login_require' => false,
2947+
),
2948+
'account' => array(
2949+
'label' => __( 'Account', 'tutor' ),
2950+
'show_ui' => false,
2951+
),
2952+
);
2953+
2954+
if ( $this->should_show_dicussion_menu() ) {
2955+
$items['discussions'] = array(
2956+
'title' => __( 'Discussions', 'tutor' ),
2957+
'icon' => Icon::QA,
2958+
);
2959+
}
2960+
2961+
return apply_filters( 'tutor_student_dashboard_nav', $items );
2962+
}
2963+
2964+
/**
2965+
* Separation of all menu items for providing ease of usage
2966+
*
2967+
* @since 2.0.0
2968+
*
2969+
* @return array array of menu items.
2970+
*/
2971+
public function instructor_menus(): array {
2972+
$menus = array(
2973+
'index' => array(
2974+
'title' => __( 'Home', 'tutor' ),
2975+
'icon' => Icon::HOME,
2976+
),
2977+
'my-courses' => array(
2978+
'title' => __( 'Courses', 'tutor' ),
2979+
'auth_cap' => tutor()->instructor_role,
2980+
'icon' => Icon::COURSES,
2981+
),
2982+
// Hidden menu.
2983+
'create-course' => array(
2984+
'title' => __( 'Create Course', 'tutor' ),
2985+
'show_ui' => false,
2986+
'auth_cap' => tutor()->instructor_role,
2987+
),
2988+
'create-bundle' => array(
2989+
'title' => __( 'Create Bundle', 'tutor' ),
2990+
'show_ui' => false,
2991+
'auth_cap' => tutor()->instructor_role,
2992+
),
2993+
);
2994+
2995+
$menus = apply_filters( 'tutor_after_instructor_menu_my_courses', $menus );
2996+
2997+
$other_menus = array(
2998+
'announcements' => array(
2999+
'title' => __( 'Announcements', 'tutor' ),
3000+
'auth_cap' => tutor()->instructor_role,
3001+
'icon' => Icon::ANNOUNCEMENT,
3002+
),
3003+
'quiz-attempts' => array(
3004+
'title' => __( 'Quiz Attempts', 'tutor' ),
3005+
'auth_cap' => tutor()->instructor_role,
3006+
'icon' => Icon::QUIZ,
3007+
),
3008+
);
3009+
3010+
if ( $this->should_show_dicussion_menu() ) {
3011+
$other_menus['discussions'] = array(
3012+
'title' => __( 'Discussions', 'tutor' ),
3013+
'auth_cap' => tutor()->instructor_role,
3014+
'icon' => Icon::QA,
3015+
);
3016+
}
3017+
3018+
$all_menus = apply_filters( 'tutor_instructor_dashboard_nav', array_merge( $menus, $other_menus ) );
3019+
3020+
return $all_menus;
3021+
}
3022+
29243023
/**
29253024
* Tutor Dashboard Pages, supporting for the URL rewriting
29263025
*
29273026
* @since 1.0.0
29283027
*
2929-
* @since 4.0.0 View mode added.
3028+
* @since 4.0.0 param $context added.
29303029
*
2931-
* @return mixed
3030+
* @param string $context context.
3031+
* `view` to get pages according to role.
3032+
* `rewrite_rules` to get all page for rewrite rules.
3033+
*
3034+
* @return array
29323035
*/
2933-
public function tutor_dashboard_pages() {
3036+
public function tutor_dashboard_pages( $context = 'view' ) {
3037+
3038+
$nav_items = apply_filters( 'tutor_dashboard/nav_items', $this->default_menus() );
3039+
$instructor_nav_items = apply_filters( 'tutor_dashboard/instructor_nav_items', $this->instructor_menus() );
29343040

2935-
$nav_items = array();
2936-
if ( User::is_instructor_view() ) {
2937-
$nav_items = apply_filters( 'tutor_dashboard/instructor_nav_items', $this->instructor_menus() );
3041+
if ( 'rewrite_rules' === $context ) {
3042+
$nav_items = array_merge( $nav_items, $instructor_nav_items );
29383043
} else {
2939-
$nav_items = apply_filters( 'tutor_dashboard/nav_items', $this->default_menus() );
3044+
$nav_items = User::is_instructor_view() ? $instructor_nav_items : $nav_items;
29403045
}
29413046

29423047
return apply_filters( 'tutor_dashboard/nav_items_all', $nav_items );
@@ -2950,21 +3055,8 @@ public function tutor_dashboard_pages() {
29503055
* @return array
29513056
*/
29523057
public function tutor_dashboard_permalinks() {
2953-
$dashboard_pages = $this->tutor_dashboard_pages();
2954-
2955-
$dashboard_permalinks = apply_filters(
2956-
'tutor_dashboard/permalinks',
2957-
array(
2958-
'retrieve-password' => array(
2959-
'title' => __( 'Retrieve Password', 'tutor' ),
2960-
'login_require' => false,
2961-
),
2962-
)
2963-
);
2964-
2965-
$dashboard_pages = array_merge( $dashboard_pages, $dashboard_permalinks );
2966-
2967-
return $dashboard_pages;
3058+
$dashboard_permalinks = apply_filters( 'tutor_dashboard/permalinks', $this->tutor_dashboard_pages( 'rewrite_rules' ) );
3059+
return $dashboard_permalinks;
29683060
}
29693061

29703062
/**
@@ -8555,7 +8647,7 @@ public function is_tutor_frontend_dashboard( $subpage = null ) {
85558647
if ( $wp_query->is_page ) {
85568648
$dashboard_page = $this->array_get( 'tutor_dashboard_page', $wp_query->query_vars );
85578649

8558-
if ($subpage) {
8650+
if ( $subpage ) {
85598651
$subpage_parts = explode( '/', $subpage, 2 );
85608652
if ( isset( $subpage_parts[1] ) ) {
85618653
$dashboard_subpage = $this->array_get( 'tutor_dashboard_sub_page', $wp_query->query_vars );
@@ -9516,64 +9608,6 @@ public function not_found_text(): string {
95169608
}
95179609
}
95189610

9519-
/**
9520-
* Separation of all menu items for providing ease of usage
9521-
*
9522-
* @since 2.0.0
9523-
*
9524-
* @return array array of menu items.
9525-
*/
9526-
public function instructor_menus(): array {
9527-
$menus = array(
9528-
'index' => array(
9529-
'title' => __( 'Home', 'tutor' ),
9530-
'icon' => Icon::HOME,
9531-
),
9532-
'my-courses' => array(
9533-
'title' => __( 'Courses', 'tutor' ),
9534-
'auth_cap' => tutor()->instructor_role,
9535-
'icon' => Icon::COURSES,
9536-
),
9537-
// Hidden menu.
9538-
'create-course' => array(
9539-
'title' => __( 'Create Course', 'tutor' ),
9540-
'show_ui' => false,
9541-
'auth_cap' => tutor()->instructor_role,
9542-
),
9543-
'create-bundle' => array(
9544-
'title' => __( 'Create Bundle', 'tutor' ),
9545-
'show_ui' => false,
9546-
'auth_cap' => tutor()->instructor_role,
9547-
),
9548-
);
9549-
9550-
$menus = apply_filters( 'tutor_after_instructor_menu_my_courses', $menus );
9551-
9552-
$other_menus = array(
9553-
'announcements' => array(
9554-
'title' => __( 'Announcements', 'tutor' ),
9555-
'auth_cap' => tutor()->instructor_role,
9556-
'icon' => Icon::ANNOUNCEMENT,
9557-
),
9558-
'quiz-attempts' => array(
9559-
'title' => __( 'Quiz Attempts', 'tutor' ),
9560-
'auth_cap' => tutor()->instructor_role,
9561-
'icon' => Icon::QUIZ,
9562-
),
9563-
);
9564-
9565-
if ( $this->should_show_dicussion_menu() ) {
9566-
$other_menus['discussions'] = array(
9567-
'title' => __( 'Discussions', 'tutor' ),
9568-
'auth_cap' => tutor()->instructor_role,
9569-
'icon' => Icon::QA,
9570-
);
9571-
}
9572-
9573-
$all_menus = apply_filters( 'tutor_instructor_dashboard_nav', array_merge( $menus, $other_menus ) );
9574-
9575-
return $all_menus;
9576-
}
95779611

95789612
/**
95799613
* Should show the disscussion menu on the student
@@ -9590,40 +9624,6 @@ public function should_show_dicussion_menu(): bool {
95909624
return $is_q_and_a_enabled || $is_lesson_comment_enabled;
95919625
}
95929626

9593-
/**
9594-
* Separation of all menu items for providing ease of usage
9595-
*
9596-
* @since 2.0.0
9597-
*
9598-
* @since 4.0.0 Menu item updated based on student view
9599-
*
9600-
* @return array array of menu items.
9601-
*/
9602-
public function default_menus(): array {
9603-
$items = array(
9604-
'index' => array(
9605-
'title' => __( 'Home', 'tutor' ),
9606-
'icon' => Icon::HOME,
9607-
),
9608-
'courses' => array(
9609-
'title' => __( 'Courses', 'tutor' ),
9610-
'icon' => Icon::COURSES,
9611-
),
9612-
'account' => array(
9613-
'label' => __( 'Account', 'tutor' ),
9614-
'show_ui' => false,
9615-
),
9616-
);
9617-
9618-
if ( $this->should_show_dicussion_menu() ) {
9619-
$items['discussions'] = array(
9620-
'title' => __( 'Discussions', 'tutor' ),
9621-
'icon' => Icon::QA,
9622-
);
9623-
}
9624-
9625-
return apply_filters( 'tutor_student_dashboard_nav', $items );
9626-
}
96279627

96289628
/**
96299629
* Default config for tutor text editor

0 commit comments

Comments
 (0)