• Resolved stevefwdedu

    (@stevefwdedu)


    When I hook into the profile_update action and edit a field in wp-admin, the function runs twice. On the first trigger $userdata doesn’t have the updated information. When I deactivate lifterlms it goes back to only triggering once. When I activate lifterlms it only triggers once on the first field edit and $userdata is proper. Then on the second field edit it goes back to triggering twice.

    This is annoying because I’m trying to use that data to synchronize with an external system and on the second trigger the API call doesn’t seem to be going through. Ok maybe I can skip the API call on the first trigger to make sure it runs on the second trigger, but if that second trigger ever stops happening then our systems are going to get out of sync. Is this second trigger intended behavior?

    function custom_function( $user_id, $old_user_data, $userdata ) {
    $email = $userdata['user_email'];
    $first_name = $userdata['first_name'];
    $last_name = $userdata['last_name'];

    error_log( print_r( $email, true ) );
    error_log( print_r( $first_name, true ) );
    error_log( print_r( $last_name, true ) );
    }
    add_action( 'profile_update', 'custom_function', 10, 3 );
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter stevefwdedu

    (@stevefwdedu)

    I was too tunnel-visioned in that post. The API call does work on the second trigger generally. There’s a separate barrier specifically for updating emails that is related to the API. I’m still curious what the reasoning for the second trigger is. I can imagine that creating issues.

    Plugin Author Brian Hogg

    (@brianhogg)

    Hi @stevefwdedu !

    We don’t intentionally trigger another profile_update action, but it’s possible some meta data updates might be triggering that action.

    While help with custom code is beyond the support we can provide, comparing the old user data (WP_User object) and the new data for the fields you’re concerned about can let you know whether you should trigger a sync or not. Unfortunately with the profile_update hook you can’t see the old user meta data like first_name and last_name. As such using the update_user_meta filter might be a better bet for the first/last name as it gives you the $meta_value and the $prev_value, along with profile_update for email.

    Hope that helps! I’ll mark this topic as resolved, but feel free to reach out in a new thread if you have other questions about LifterLMS that we can help with.

    Thread Starter stevefwdedu

    (@stevefwdedu)

    I could only find reference to update_user_meta function, but I did find update_{$meta_type}_metadata. $prev_value was empty in that, but because it triggers before the update I was able to get the value from the db and compare to the posted value. Super useful. Simplified everything and eliminated any need for profile_update. Thanks!

    Plugin Author Brian Hogg

    (@brianhogg)

    Glad that did the trick ??

    If you’re enjoying LifterLMS, would you mind rating it 5-stars to help spread the word? https://www.ads-software.com/support/plugin/lifterlms/reviews/#new-post

    Cheers!

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.