MDL-50130 users: Filter profile fields data in external functions
authorJuan Leyva <juanleyvadelgado@gmail.com>
Thu, 14 May 2015 15:42:54 +0000 (17:42 +0200)
committerEloy Lafuente (stronk7) <stronk7@moodle.org>
Tue, 30 Jun 2015 17:52:19 +0000 (19:52 +0200)
user/lib.php

index c89784f..31e20f6 100644 (file)
@@ -335,8 +335,17 @@ function user_get_user_details($user, $course = null, array $userfields = array(
             $newfield = 'profile_field_'.$field->datatype;
             $formfield = new $newfield($field->id, $user->id);
             if ($formfield->is_visible() and !$formfield->is_empty()) {
+
+                // We only use display_data in fields that require text formatting.
+                if ($field->datatype == 'text' or $field->datatype == 'textarea') {
+                    $fieldvalue = $formfield->display_data();
+                } else {
+                    // Cases: datetime, checkbox and menu.
+                    $fieldvalue = $formfield->data;
+                }
+
                 $userdetails['customfields'][] =
-                    array('name' => $formfield->field->name, 'value' => $formfield->data,
+                    array('name' => $formfield->field->name, 'value' => $fieldvalue,
                         'type' => $field->datatype, 'shortname' => $formfield->field->shortname);
             }
         }