Skip to content
● Grav 2.2 is out: 2x faster cold starts and 96% less memory on big sites. Read the announcement →

How do I change a user's email address in a plugin?

Solved by Karmalakas View solution

Started by Anna 6 years ago · 2 replies · 562 views
6 years ago

I have a form where a logged in user can have a confirmation email sent to them. I'm showing an email input field with the email address from their profile prefilled. However, if they change it, I'd like to update their user profile mail address as well.

I have tried:

PHP
if ($form->data['email'] != $user['email']) {
    $user->email = $form->data['email'];
}

This does change the email address, but I think it doesn't write it to the user's yaml file, because after logging out and back in again, the old one is back. So how can I permanently save that?

6 years ago Solution

Try $user->save()
Can't test right now and don't have the form set up, but I hope this should work- I see save() method in User object

last edited 01/31/21 by Karmalakas
6 years ago

Excellent memory, it is as simple as that! Thanks 🥰

Suggested topics

Topic Participants Replies Views Activity
Plugins · by complanar, 2 weeks ago
6 354 1 week ago
Plugins · by BenLaKnet, 2 weeks ago
1 174 2 weeks ago
Plugins · by complanar, 1 month ago
2 453 4 weeks ago
Plugins · by Vladimir Novak, 2 months ago
3 740 2 months ago
Plugins · by Mathieu Lecouturier, 2 months ago
3 580 2 months ago