diff --git a/user/profile.php b/user/profile.php
index <HASH>..<HASH> 100644
--- a/user/profile.php
+++ b/user/profile.php
@@ -57,7 +57,7 @@ $context = $usercontext = get_context_instance(CONTEXT_USER, $userid, MUST_EXIST
 
 if (!$currentuser &&
     !empty($CFG->forceloginforprofiles) && 
-    !has_capability('moodle/user:viewdetails', $context) && 
+    !has_capability('moodle/user:viewdetails', $context) &&
     !has_coursecontact_role($userid)) {
     // Course managers can be browsed at site level. If not forceloginforprofiles, allow access (bug #4366)
     $struser = get_string('user');
@@ -96,7 +96,11 @@ if (isguestuser()) {     // Guests can never edit their profile
     }
 }
 
-
+if (has_capability('moodle/user:viewhiddendetails', $context)) {
+    $hiddenfields = array();
+} else {
+    $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields));
+}
 
 // Start setting up the page
 $strpublicprofile = get_string('publicprofile');
NOBUG Added missing hiddenfields var from user/profile.php