$usercap = array(); // for other user's capabilities
foreach ($capabilities as $capability) {
- $context = get_context_instance_by_id($capability->id);
+ if (!$context = get_context_instance_by_id($capability->id)) {
+ continue; // incorrect stale context
+ }
if (!empty($otheruserid)) { // we are pulling out other user's capabilities, do not write to session
/// check allowed context levels
if (!in_array($contextlevel, $allowed_contexts)) {
- // fatal error, code must be fixed - probably typo or switched parameters
+ // fatal error, code must be fixed - probably typo or switched parameters
error('Error: get_context_instance() called with incorrect context level "'.s($contextlevel).'"');
}