| 1 |
<?php |
| 2 |
// Exit if accessed directly |
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
/** |
| 5 |
* Public Class |
| 6 |
* |
| 7 |
* Handles generic Public functionality. |
| 8 |
* |
| 9 |
* @package WPSchoolPress |
| 10 |
* @since 2.0.0 |
| 11 |
*/ |
| 12 |
class Wpsp_Public |
| 13 |
{ |
| 14 |
public function __construct() |
| 15 |
{ |
| 16 |
} |
| 17 |
/* |
| 18 |
* Redirect user to dashboard |
| 19 |
* @package WPSchoolPress |
| 20 |
* @since 2.0.0 |
| 21 |
*/ |
| 22 |
function wpsp_login_redirect($redirect_to, $request, $user) |
| 23 |
{ |
| 24 |
global $user; |
| 25 |
if (isset($user->roles) && is_array($user->roles)) |
| 26 |
{ |
| 27 |
if (in_array('administrator', $user->roles)) //check for admins |
| 28 |
{ |
| 29 |
return $redirect_to; // redirect them to the default place |
| 30 |
} |
| 31 |
else |
| 32 |
{ |
| 33 |
return site_url('/wp-admin/admin.php?page=sch-dashboard'); |
| 34 |
} |
| 35 |
} |
| 36 |
return $redirect_to; |
| 37 |
} |
| 38 |
/* |
| 39 |
* redirect to specific page |
| 40 |
* @package WPSchoolPress |
| 41 |
* @since 2.0.0 |
| 42 |
*/ |
| 43 |
function wpsp_page_template($page_template) |
| 44 |
{ |
| 45 |
if (is_page('sch-dashboard')) |
| 46 |
{ |
| 47 |
$page_template = dirname(__FILE__) . '/pages/wpsp-dashboard.php'; |
| 48 |
} |
| 49 |
if (is_page('sch-student')) |
| 50 |
{ |
| 51 |
$page_template = dirname(__FILE__) . '/pages/wpsp-student.php'; |
| 52 |
} |
| 53 |
if (is_page('sch-transport')) |
| 54 |
{ |
| 55 |
$page_template = dirname(__FILE__) . '/pages/wpsp-transport.php'; |
| 56 |
} |
| 57 |
if (is_page('sch-parent')) |
| 58 |
{ |
| 59 |
$page_template = dirname(__FILE__) . '/pages/wpsp-parent.php'; |
| 60 |
} |
| 61 |
if (is_page('sch-class')) |
| 62 |
{ |
| 63 |
$page_template = dirname(__FILE__) . '/pages/wpsp-class.php'; |
| 64 |
} |
| 65 |
if (is_page('sch-teacher')) |
| 66 |
{ |
| 67 |
$page_template = dirname(__FILE__) . '/pages/wpsp-teacher.php'; |
| 68 |
} |
| 69 |
if (is_page('sch-messages')) |
| 70 |
{ |
| 71 |
$page_template = dirname(__FILE__) . '/pages/wpsp-messages.php'; |
| 72 |
} |
| 73 |
if (is_page('sch-profile')) |
| 74 |
{ |
| 75 |
$page_template = dirname(__FILE__) . '/pages/wpsp-profile.php'; |
| 76 |
} |
| 77 |
if (is_page('sch-exams')) |
| 78 |
{ |
| 79 |
$page_template = dirname(__FILE__) . '/pages/wpsp-exams.php'; |
| 80 |
} |
| 81 |
if (is_page('sch-marks')) |
| 82 |
{ |
| 83 |
$page_template = dirname(__FILE__) . '/pages/wpsp-marks.php'; |
| 84 |
} |
| 85 |
if (is_page('sch-attendance')) |
| 86 |
{ |
| 87 |
$page_template = dirname(__FILE__) . '/pages/wpsp-attendance.php'; |
| 88 |
} |
| 89 |
if (is_page('sch-timetable')) |
| 90 |
{ |
| 91 |
$page_template = dirname(__FILE__) . '/pages/wpsp-timetable.php'; |
| 92 |
} |
| 93 |
if (is_page('sch-reminder')) |
| 94 |
{ |
| 95 |
$page_template = dirname(__FILE__) . '/pages/wpsp-reminder.php'; |
| 96 |
} |
| 97 |
if (is_page('sch-events')) |
| 98 |
{ |
| 99 |
$page_template = dirname(__FILE__) . '/pages/wpsp-events.php'; |
| 100 |
} |
| 101 |
if (is_page('sch-subject')) |
| 102 |
{ |
| 103 |
$page_template = dirname(__FILE__) . '/pages/wpsp-subject.php'; |
| 104 |
} |
| 105 |
if (is_page('sch-settings')) |
| 106 |
{ |
| 107 |
$page_template = dirname(__FILE__) . '/pages/wpsp-settings.php'; |
| 108 |
} |
| 109 |
if (is_page('sch-calendar')) |
| 110 |
{ |
| 111 |
$page_template = dirname(__FILE__) . '/pages/wpsp-calendar.php'; |
| 112 |
} |
| 113 |
if (is_page('sch-teacherattendance')) |
| 114 |
{ |
| 115 |
$page_template = dirname(__FILE__) . '/pages/wpsp-teacher-attendance.php'; |
| 116 |
} |
| 117 |
if (is_page('sch-profile')) |
| 118 |
{ |
| 119 |
$page_template = dirname(__FILE__) . '/pages/wpsp-profile.php'; |
| 120 |
} |
| 121 |
if (is_page('sch-notify')) |
| 122 |
{ |
| 123 |
$page_template = dirname(__FILE__) . '/pages/wpsp-notify.php'; |
| 124 |
} |
| 125 |
if (is_page('sch-payment')) |
| 126 |
{ |
| 127 |
$page_template = dirname(__FILE__) . '/pages/wpsp-paymentdetail.php'; |
| 128 |
} |
| 129 |
if (is_page('sch-importhistory')) |
| 130 |
{ |
| 131 |
$page_template = dirname(__FILE__) . '/pages/wpsp-importhistory.php'; |
| 132 |
} |
| 133 |
if (is_page('sch-leavecalendar')) |
| 134 |
{ |
| 135 |
$page_template = dirname(__FILE__) . '/pages/wpsp-leavecalendar.php'; |
| 136 |
} |
| 137 |
if (is_page('sch-changepassword')) |
| 138 |
{ |
| 139 |
$page_template = dirname(__FILE__) . '/pages/wpsp-changepassword.php'; |
| 140 |
} |
| 141 |
if (is_page('sch-editprofile')) |
| 142 |
{ |
| 143 |
$page_template = dirname(__FILE__) . '/pages/wpsp-editprofile.php'; |
| 144 |
} |
| 145 |
return $page_template; |
| 146 |
} |
| 147 |
function add_hooks() |
| 148 |
{ |
| 149 |
// redirect user to dashboard page |
| 150 |
add_filter('login_redirect', array( |
| 151 |
$this, |
| 152 |
'wpsp_login_redirect' |
| 153 |
) , 10, 3); |
| 154 |
// set page template as |
| 155 |
add_filter('page_template', array( |
| 156 |
$this, |
| 157 |
'wpsp_page_template' |
| 158 |
)); |
| 159 |
} |
| 160 |
} |
| 161 |
|