Forum

Thread tagged as: Problem, Addons

Can I change a Member's profile information with PHP?

Is there a way to update a Member's profile information he/she gave in the registration without them having to send a form?
A lot of the members in this case gave some "funny" registration code in the registration process. This code was not validated in the registration process in the past. When the members logged in, a valid code had to be given and only then was it checked against a list.
So now a lot of members have invalid codes associated with their accounts. They can log in alright, as the code is checked against the list, not against their profile.
I would like to clean up the "funny" codes in the profiles with the valid ones given during logging in without the member having to do anything.
PS: In future registrations the code is validated beforehand. So the problem will not occur with new members.

Nils Mielke

Nils Mielke 3 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Something along the lines of:

$API  = new PerchAPI(1.0, 'perch_members');
$Members = new PerchMembers_Members($API);
$members = $Members->all();
foreach($members as $Member) {
    $Properties = new stdClass();
    $Properties->data = array(
         'registration_code' => 'foo', // etc
    );
    $Member->update_profile($Properties);
}

But that would change the registration codes for all members, right?
I need to update only the code of the member that logged in. How can I do that?
I tried:

$API  = new PerchAPI(1.0, 'perch_members');
$Members = new PerchMembers_Members($API);
$members = $Members->all();
foreach($members as $Member) {
    if($Member->details->memberEmail == perch_member_get('email')) {
        $Properties = new stdClass();
        $Properties->data = array(
             'registration_code' => 'foo', // etc
        );
        $Member->update_profile($Properties);
    }
}

But that does not work.

Sorry, I am terrible at this.
Planning on getting some PHP training in order to not having to bother you all the time. ;)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, I didn't see that part of your question.

$API  = new PerchAPI(1.0, 'perch_members');
$Members = new PerchMembers_Members($API);
$Session = PerchMembers_Session::fetch();
$Member = $Members->find($Session->get('memberID'));
$Properties = new stdClass();
$Properties->data = array(
     'registration_code' => 'foo', // etc
);
$Member->update_profile($Properties);

You're awesome, Drew! :) Got a good hint, how to self-teach that kind of stuff?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I have an unfair advantage in that I wrote it.

I guess I am going to learn about Objects and Classes, then—and keeping picking your brain when necessary.

Sorry to drag up an old post, but I have a problem with this;

Whilst the update seems to work fine - it doesn't seem to update the session correctly (which means even though the data is correct in perch2_members, it's wrong in perch2_members_sessions, meaning I have to log out and back in, which is not ideal...)

So I wondered if there's an easy way to rebuild the session?

Thanks!

No worries if there's not a quick way - it occurred to me based on my configuration that I can silently log a user out and back in very easily, so for now I'm doing that to update the session.

Thank.

I seem to recall something along the lines of that you need to update your information before anything else happens. So right at the top of your code.