email); $link = "{$site->url}uservalidationbyemail/confirm?u=$user_guid&c=$code"; // Send validation email $subject = elgg_echo('email:validate:subject', array($user->name, $site->name)); $body = elgg_echo('email:validate:body', array($user->name, $site->name, $link, $site->name, $site->url)); $result = notify_user($user->guid, $site->guid, $subject, $body, NULL, 'email'); if ($result && !$admin_requested) { system_message(elgg_echo('uservalidationbyemail:registerok')); } return $result; } return FALSE; } /** * Validate a user * * @param int $user_guid * @param string $code * @return bool */ function uservalidationbyemail_validate_email($user_guid, $code) { $user = get_entity($user_guid); if ($code == uservalidationbyemail_generate_code($user_guid, $user->email)) { return elgg_set_user_validation_status($user_guid, true, 'email'); } return false; } /** * Return a where clause to get entities * * "Unvalidated" means metadata of validated is not set or not truthy. * We can't use elgg_get_entities_from_metadata() because you can't say * "where the entity has metadata set OR it's not equal to 1". * * @return array */ function uservalidationbyemail_get_unvalidated_users_sql_where() { global $CONFIG; $validated_id = get_metastring_id('validated'); if ($validated_id === false) { $validated_id = add_metastring('validated'); } $one_id = get_metastring_id('1'); if ($one_id === false) { $one_id = add_metastring('1'); } // thanks to daveb@freenode for the SQL tips! $wheres = array(); $wheres[] = "e.enabled='no'"; $wheres[] = "NOT EXISTS ( SELECT 1 FROM {$CONFIG->dbprefix}metadata md WHERE md.entity_guid = e.guid AND md.name_id = $validated_id AND md.value_id = $one_id)"; return $wheres; }