• Resolved Brayne

    (@brayne)


    I’ve tested over and over to make sure this is what’s happening…. I need to verify with someone familiar with wp_update_user…

    I have a user signing up. The new role defaults to “subscriber”. When they pay for a paypal membership, the notify URL is working great. Their role is updated to a “member”.

    When paypal notifies my site I’m using this for the update…

    wp_update_user( array (‘ID’ => $user_id, ‘role’ => $new_role) ) ;

    NOW, this IS working EXCEPT, it’s wiping out this user’s meta info. AND… It’s not wiping out all of it, just most of it… what the heck??

    When I comment out this wp_update_user code, the PP notify still does it’s job and the user’s meta is still in tact.

    What is the best way to handle this? My thought is get the all of the user’s meta into an array, then do the role update, then upack the array and “re” update the user’s meta?? Seems a bit much but I’m stumped.

Viewing 1 replies (of 1 total)
  • Thread Starter Brayne

    (@brayne)

    If any comes across this scenario, I’ve got the fix.

    A user fills out a registration form and becomes the default role, mine is set at subscriber. After they’ve registered for the site and consequently become a subscriber, I am directing them to pay for a membership, (In My case using paypal). I’m updating their status to “Paid Member” in user_meta AND elevating their role to a custom role I’ve created called “Member”

    You must set their role using set_role in the WP_User class. If you change their role via wp_update_user, you will lose any “CUSTOM” user_meta information you may have collected in a CUSTOM registration form.

    I needed to update this new user’s role so I used the following…

    $new_role = ‘Whatever’;
    $user = new WP_User($user_id);
    $user->set_role($new_role);

    This updated my newly paid Member’s role without disturbing any of my CUSTOM user_meta information I have collected.

Viewing 1 replies (of 1 total)

The topic ‘Does wp_update_user delete user_meta?’ is closed to new replies.