I'm also trying to figure this one out. Here is what I have found:
Long Story Short:
It appears as though email display is now controlled by the site:viewuseridentity permission. However, giving this permission to students results in the students being able to see EVERYONE'S email addresses, even those who have chosen hide my email address.
Rather than being part of the normal user details that can and cannot be displayed, the email address is in a separate category of siteidentity which is controlled by the permission above. (Note: you can change which items are considered site identity as mentioned below) however, email is used as the default.) Regardless, removing email as the site identity does not make it suddenly appear.
Perhaps we are expected to use the built-in messaging system exclusively?
Anyhoo, if anyone figures a workaround, please do post it. Hopefully I am just missing something simple. Fingers crossed!
Thanks,
Christian
DETAILS
The relevant code is here:
Moodle: https://github.com/moodle/moodle/blob/6a69cda97dc8b10cffd805d62bfc6d56098c92d0/lib/myprofilelib.php
Specifically (starting at line 124):
// Contact details.
if (has_capability('moodle/user:viewhiddendetails', $courseorusercontext)) {
$hiddenfields = array();
} else {
$hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
}
if (has_capability('moodle/site:viewuseridentity', $courseorusercontext)) {
$identityfields = array_flip(explode(',', $CFG->showuseridentity));
} else {
$identityfields = array();
}
The site:viewuseridentity setting refers to the selected user identity found here: SITE_URL/admin/settings.php?section=userpolicies
Based on what I see here, the only way to allow email addresses to be viewed is to grant users the "site:viewuseridentity" setting. However, it appears that this would ignore the "Hide my email address" setting.
There is also this code in the same library (from line 154):
if (isset($identityfields['email']) and ($iscurrentuser
or $user->maildisplay == 1
or has_capability('moodle/course:useremail', $courseorusercontext)
or has_capability('moodle/site:viewuseridentity', $courseorusercontext)
or ($user->maildisplay == 2 and enrol_sharing_course($user, $USER)))) {
$node = new core_user\output\myprofile\node('contact', 'email', get_string('email'), null, null,
obfuscate_mailto($user->email, ''));
$tree->add_node($node);
}
As you can see, the code looks for the course:useremail capability - I tried changing this permission on our site for students, but there was no effect. I also found this tracker issue where this capability is supposed to be deprecated: https://tracker.moodle.org/browse/MDL-37479 . One poster even asked how students would be able to view each other's email addresses (and presumably that of the instructor if this was removed) .
There is a more recent tracker issue posted on this: https://tracker.moodle.org/browse/MDL-58061