| Server IP : 158.247.231.215 / Your IP : 216.73.217.84 Web Server : Apache/2.4.41 (Ubuntu) System : Linux CTMS 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64 User : www-data ( 33) PHP Version : 8.0.30 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /mnt/blockstorage/ctms/wp-content/mu-plugins/ |
Upload File : |
<?php
/**
* Plugin Name: CTMS Teacher Dashboard Customizer
* Description: Customizes Tutor LMS dashboard sidebar for Teacher accounts per Nuguna VR manual section 12.
*/
if ( ! defined( 'ABSPATH' ) ) exit;
/**
* 1. Register custom page keys in the full nav_items_all so Tutor's
* Rewrite_Rules class generates /dashboard/my-students/ etc. routes.
*/
add_filter( 'tutor_dashboard/nav_items_all', 'ctms_register_teacher_pages', 5 );
function ctms_register_teacher_pages( $items ) {
$items['my-students'] = array(
'title' => __( 'My Students', 'tutor' ),
'icon' => 'tutor-icon-user-graduate',
);
$items['my-class'] = array(
'title' => __( 'My Class', 'tutor' ),
'icon' => 'tutor-icon-rocket',
);
$items['analytics'] = array(
'title' => __( 'Analytics', 'tutor' ),
'icon' => 'tutor-icon-chart-pie',
);
return $items;
}
/**
* 2a. Student sidebar – 4 items (non-instructors).
*/
add_filter( 'tutor_dashboard/nav_ui_items', 'ctms_student_sidebar_items', 999 );
function ctms_student_sidebar_items( $items ) {
if ( ! is_user_logged_in() || ! function_exists( 'tutor' ) ) {
return $items;
}
if ( current_user_can( tutor()->instructor_role ) ) {
return $items; // handled by teacher filter below
}
return array(
'index' => array( 'title' => __( 'Dashboard', 'tutor' ), 'icon' => 'tutor-icon-dashboard' ),
'my-profile' => array( 'title' => __( 'My Profile', 'tutor' ), 'icon' => 'tutor-icon-user-bold' ),
'my-class' => array( 'title' => __( 'My Class', 'tutor' ), 'icon' => 'tutor-icon-rocket' ),
'analytics' => array( 'title' => __( 'Analytics', 'tutor' ), 'icon' => 'tutor-icon-chart-pie' ),
'logout' => array( 'title' => __( 'Logout', 'tutor' ), 'icon' => 'tutor-icon-signout' ),
);
}
/**
* 2b. Replace the sidebar nav with exactly the 6 required items for instructors.
* Priority 999 so it runs after all other filters.
*/
add_filter( 'tutor_dashboard/nav_ui_items', 'ctms_teacher_sidebar_items', 999 );
function ctms_teacher_sidebar_items( $items ) {
if ( ! is_user_logged_in() || ! function_exists( 'tutor' ) ) {
return $items;
}
if ( ! current_user_can( tutor()->instructor_role ) ) {
return $items;
}
return array(
'index' => array(
'title' => __( 'Dashboard', 'tutor' ),
'icon' => 'tutor-icon-dashboard',
),
'my-profile' => array(
'title' => __( 'My Profile', 'tutor' ),
'icon' => 'tutor-icon-user-bold',
),
'my-students' => array(
'title' => __( 'My Students', 'tutor' ),
'icon' => 'tutor-icon-user-graduate',
),
'my-class' => array(
'title' => __( 'My Class', 'tutor' ),
'icon' => 'tutor-icon-rocket',
),
'analytics' => array(
'title' => __( 'Analytics', 'tutor' ),
'icon' => 'tutor-icon-chart-pie',
),
'logout' => array(
'title' => __( 'Logout', 'tutor' ),
'icon' => 'tutor-icon-signout',
),
);
}
/**
* 3. Register the Billing settings sub-page so Tutor generates its rewrite rule.
*/
add_filter( 'tutor_dashboard/nav_items/settings/nav_items', 'ctms_register_billing_settings_tab' );
function ctms_register_billing_settings_tab( $items ) {
if ( is_user_logged_in() && function_exists( 'tutor' ) && ! current_user_can( tutor()->instructor_role ) ) {
$items['billing'] = array(
'title' => __( 'Billing', 'tutor' ),
'url' => tutor_utils()->get_tutor_dashboard_page_permalink( 'settings/billing' ),
);
}
return $items;
}
/**
* 4. Flush rewrite rules once when this plugin is first loaded
* (only if the custom rules are not yet registered).
*/
add_action( 'init', 'ctms_maybe_flush_rewrite_rules', 99 );
function ctms_maybe_flush_rewrite_rules() {
if ( get_option( 'ctms_teacher_rules_flushed' ) !== '1' ) {
flush_rewrite_rules( false );
update_option( 'ctms_teacher_rules_flushed', '1' );
}
}