diff --git a/lib/outputrenderers.php b/lib/outputrenderers.php index 57a2b128cf4..a7c9f1f167f 100644 --- a/lib/outputrenderers.php +++ b/lib/outputrenderers.php @@ -4185,12 +4185,12 @@ EOD; } // Only provide user information if the user is the current user, or a user which the current user can view. - $canviewdetails = false; - if ($user->id == $USER->id || user_can_view_profile($user)) { - $canviewdetails = true; - } + // When checking user_can_view_profile(), either: + // If the page context is course, check the course context (from the page object) or; + // If page context is NOT course, then check across all courses. + $course = ($this->page->context->contextlevel == CONTEXT_COURSE) ? $this->page->course : null; - if ($canviewdetails) { + if (user_can_view_profile($user, $course)) { // Use the user's full name if the heading isn't set. if (!isset($heading)) { $heading = fullname($user);