/// Refreshing all current role assignments for the current user
- load_user_capability();
+ load_all_capabilities();
/// Double check just in case they are actually enrolled already and
/// thus got to this script by mistake. This might occur if enrolments
if (!empty($USER->realuser)) {
$USER = get_complete_user_data('id', $USER->realuser);
- load_user_capability(); // load all this user's normal capabilities
+ load_all_capabilities(); // load all this user's normal capabilities
if (isset($SESSION->oldcurrentgroup)) { // Restore previous "current group" cache.
$SESSION->currentgroup = $SESSION->oldcurrentgroup;
global $USER, $CFG;
+ if (empty($CFG->rolesactive)) {
+ return false;
+ }
+
if (empty($userid)) {
if (empty($USER->id)) { // We have no user to get capabilities for
debugging('User not logged in for load_user_capability!');
if (!empty($otheruserid)) {
return $usercap; // return the array
}
- // see array in session to see what it looks like
+}
+
+
+/*
+ * A convenience function to completely load all the capabilities
+ * for the current user. This is what gets called from login, for example.
+ */
+function load_all_capabilities() {
+ global $USER;
+
+ if (empty($USER->username)) {
+ return;
+ }
+ load_user_capability(); // Load basic capabilities assigned to this user
+
+ if ($USER->username == 'guest') {
+ load_guest_role(); // All non-guest users get this by default
+ } else {
+ load_defaultuser_role(); // All non-guest users get this by default
+ }
}
+
/*
* Check all the login enrolment information for the given user object
* by querying the enrolment plugins
/// If the user is the current user, then reload the capabilities too.
if (!empty($USER->id) && $USER->id == $userid) {
- load_user_capability();
+ load_all_capabilities();
}
/// Ask all the modules if anything needs to be done for this user
/// If the user is the current user, then reload the capabilities too.
if (!empty($USER->id) && $USER->id == $ra->userid) {
- load_user_capability();
+ load_all_capabilities();
}
$context = get_record('context', 'id', $ra->contextid);