/** * function to add custom profile fields to user on register * * @param $event * @param $object_type * @param $object * @return unknown_type */ function profile_manager_create_user_event($event, $object_type, $object) { $custom_profile_fields = array(); // retrieve all field that were on the register page foreach ($_POST as $key => $value) { if (strpos($key, "custom_profile_fields_") === 0) { $key = substr($key, 22); $custom_profile_fields[$key] = get_input("custom_profile_fields_" . $key); } } if (count($custom_profile_fields) > 0) { $categorized_fields = profile_manager_get_categorized_fields(null, true, true); $configured_fields = $categorized_fields['fields']; // set ignore access $ia = elgg_get_ignore_access(); elgg_set_ignore_access(true); foreach ($custom_profile_fields as $shortname => $value) { // determine if $value should be an array if (!is_array($value) && !empty($configured_fields)) { // only do something if it not is already an array foreach ($configured_fields as $configured_field) { if ($configured_field->metadata_name == $shortname) { if ($configured_field->metadata_type == "tags" || $configured_field->output_as_tags == "yes") { $value = string_to_tag_array($value); // no need to continue this foreach break; } } } } // use create_metadata to listen to default access if (is_array($value)) { $i = 0; foreach ($value as $interval) { $i++; if ($i == 1) { $multiple = false; } else { $multiple = true; } create_metadata($object->guid, $shortname, $interval, 'text', $object->guid, get_default_access($object), $multiple); } } else { create_metadata($object->guid, $shortname, $value, 'text', $object->guid, get_default_access($object)); } } // restore ignore access elgg_set_ignore_access($ia); } if (isset($_FILES["profile_icon"])) { add_profile_icon($object); } }
/** * function to add custom profile fields to user on register * * @param $event * @param $object_type * @param $object * @return unknown_type */ function profile_manager_create_user($event, $object_type, $object) { // add metadata $custom_profile_fields = array(); foreach ($_POST as $key => $value) { if (strpos($key, "custom_profile_fields_") == 0) { $key = substr($key, 22); $custom_profile_fields[$key] = $value; } } if (count($custom_profile_fields) > 0) { foreach ($custom_profile_fields as $key => $field) { // use create_metadata to listen to ACCESS_DEFAULT create_metadata($object->guid, $key, $field, "", $object->guid, ACCESS_DEFAULT); } } if ($profile_icon = $_FILES["profile_icon"]) { add_profile_icon($object); } }