public static function get_custom_profile_fields() {
        global $DB, $CFG;

        if (self::$customprofilefields === null) {
            // Get fields and store them indexed by shortname.
            require_once($CFG->dirroot . '/user/profile/lib.php');
            $fields = profile_get_custom_fields(true);
            self::$customprofilefields = array();
            foreach ($fields as $field) {
                self::$customprofilefields[$field->shortname] = $field;
            }
        }
        return self::$customprofilefields;
    }