Elgg  Version 6.2
change_email.php
Go to the documentation of this file.
1 <?php
6 $guid = (int) get_input('user_guid');
7 $email = (string) get_input('email');
8 
9 if (empty($guid) || empty($email)) {
10  return elgg_error_response(elgg_echo('error:missing_data'));
11 }
12 
14  return elgg_error_response(elgg_echo('registration:emailnotvalid'));
15 }
16 
18  return get_user($guid);
19 });
20 if (!$user instanceof \ElggUser) {
21  return elgg_error_response(elgg_echo('error:missing_data'));
22 }
23 
24 if ($user->email === $email) {
25  // no change
26  return elgg_ok_response();
27 }
28 
31 });
32 
33 if ($existing_user instanceof \ElggUser && $user->guid !== $existing_user->guid) {
34  return elgg_error_response(elgg_echo('registration:dupeemail'));
35 }
36 
37 $user->email = $email;
38 $user->save();
39 
40 return elgg_ok_response('', elgg_echo('email:save:success'));
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
Definition: elgglib.php:306
elgg_echo(string $message_key, array $args=[], string $language= '')
Elgg language module Functions to manage language and translations.
Definition: languages.php:17
if(!$user instanceof\ElggUser) if($user->email===$email) $existing_user
$email
Definition: change_email.php:7
if(empty($guid)||empty($email)) if(!elgg_is_valid_email($email)) $user
get_input(string $variable, $default=null, bool $filter_result=true)
Parameter input functions.
Definition: input.php:20
elgg_ok_response($content= '', string|array $message= '',?string $forward_url=null, int $status_code=ELGG_HTTP_OK)
Prepares a successful response to be returned by a page or an action handler.
elgg_error_response(string|array $message= '', string $forward_url=REFERRER, int $status_code=ELGG_HTTP_BAD_REQUEST)
Prepare an error response to be returned by a page or an action handler.
const ELGG_SHOW_DISABLED_ENTITIES
Definition: constants.php:123
$guid
Admin action to change the email address of an user.
Definition: change_email.php:6
get_user(int $guid)
Elgg users Functions to manage multiple or single users in an Elgg install.
Definition: users.php:16
elgg_get_user_by_email(string $email)
Get a user from an email address.
Definition: users.php:79
elgg_is_valid_email(string $address)
Validates an email address.
Definition: input.php:89