• Resolved jkester1986

    (@jkester1986)


    I am trying to do an action after a profile update happens. I’ve tried um_after_user_updated, um_user_edit_profile, um_user_after_updating_profile. Nothing seems to be firing. I have a simple function that’s just supposed to send an email. I have used other hooks and filters and sent emails in them before, so I’m not sure what I”m doing wrong in this case. Current code is:

    add_action( 'um_user_edit_profile', 'my_after_user_updated', 10, 3 );
    function my_after_user_updated( $user_id, $args, $userinfo ) {
        // your code here
      	mail("<my email>", "test", "another test", "From: [email protected]");
    }

    We are running on WP 5.5.1, Ultimate Member 2.1.19

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Support Aswin Giri

    (@aswingiri)

    Hello @jkester1986

    You can try this hook:
    do_action( 'um_user_after_updating_profile', $to_update, $user_id, $args );

    Thread Starter jkester1986

    (@jkester1986)

    As I mentioned in my original post, that is one of the three hooks that I’ve already tried

    • This reply was modified 2 years, 9 months ago by jkester1986.

    @jkester1986

    You must call function wp_mail( $to, $subject, $message, $headers = '', $attachments = array() ) instead of mail.

    Thread Starter jkester1986

    (@jkester1986)

    Thanks @missveronicatv! I’m not sure why that made a difference – I am using php’s mail function in other places – but now I’m getting the email like I expect.

    Plugin Support Ultimate Member Support

    (@ultimatemembersupport)

    Thanks for letting us know. I’m marking this as resolved now.

    Hi @jkester1986 . I’m losing something, I’m using your code with the wp_mail function instead and it’s not working for me.
    Could you explain or send me the final code that you are using ?
    I just need to send an email when someone updates the UM profile.

    Thanks

    @missveronicatv that works perfectly. Thanks so much.

    Do you know how to filter those emails? not for every form updated but for some of them, example:

    If form_id = 255 , send email.

    Thank you again Veronica

    @juaniglive

    You can try this code and replace the last function in the code snippet
    where emails will be sent for three UM Profile Update forms 255, 999, 1061:

    function custom_profile_is_updated_email( $to_update, $user_id, $args = array() ) {
    
        global $current_user;
    
        if( !in_array( $args['form_id'], array( '255', '999', '1061' ))) return;
    
        $time_format = get_option( 'date_format' ) . ' ' . get_option( 'time_format' );
        um_fetch_user( $user_id );
        
        $args['tags'] = array(  '{profile_url}', 
                                '{current_date}', 
                                '{updating_user}' );
    
        $args['tags_replace'] = array(  um_user_profile_url( $user_id ), 
                                        date_i18n( $time_format, current_time( 'timestamp' )), 
                                        $current_user->user_login );
    
        UM()->mail()->send( get_bloginfo( 'admin_email' ), 'profile_is_updated_email', $args );
    }

    It works perfectly.
    You can add that to the repo!
    Thanks!

    @juaniglive

    I have made an user friendly update of the code snippet and now you can add UM Profile Form ID’s comma separated in:

    UM Settings -> Email -> Profile is updated email -> Include these UM Profile Forms for sending emails

    Replace all old code with the new code snippet from:

    https://github.com/MissVeronica/UM-Admin-User-Profile-Update-Email

    Works like a charm Veronica, thanks!

    You know, the email template it’s using {submitted_registration} and it always posts data from the USER REGISTRATION which it’s the only one and the first time that the user is registered.

    But, what hook or how can I get the data or metadata submitted on that form? In my case, it’s a profile form, not a registration form.

    EDIT, FOUND THE ANSWER:
    Just Use: {usermeta:here_any_usermeta_key} on your email template and it’s done!

    • This reply was modified 2 years, 3 months ago by juaniglive.

    @juaniglive

    No, the {submitted_registration} placeholder is being updated with current values after a profile edit. The placeholder name is misleading.

    You can look at WP Users -> Info and you will get the current profile data.

    Both the placeholder and the ‘Info’ display are created by the same UM function.

    If you look at the usermeta table and the meta_key 'submitted' you have the old registration values.

    Doesn’t work for me so!
    I’m using a Profile Form that doesn’t contain any of the values that {submitted_registration} shows on the email.

    This is what I get in {submitted_registration} :

    Date Submitted: 29 Dec 2021 15:57
    Form: Default Registration - Form ID#: 269
    Username: juani
    E-mail Address: [email protected]
    divider: (empty)
    First Name: juani
    Last Name: test
    WhatsApp number: 1111
    Birth day: 3
    Birth Month: 11
    Year: (empty)

    As you see, it’s picking up the registration form entry, with the date December last year.

    The profile form used to trigger the email contains only two text fields:
    Flight_number and city_name. As they are meta_keys I’m using {usermeta:here_any_usermeta_key} to bring it to the email and I “fix” the problem.

    • This reply was modified 2 years, 3 months ago by juaniglive. Reason: preserve data
Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Can’t get hooks to run after profile updates’ is closed to new replies.