• Resolved Nicolas

    (@nchaccal)


    I have my profile form connected with a thirdparty app (salesforce) via API.

    I use um_user_edit_profile to hook new fields when user edit his profile.

    But the thing is this only works when user edit profile, go again to his profile page and edit it again. So, you need to edit profile twice to see the changes in salesforce.

    Any idea what it might be?

    Thanks!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @nchaccal

    Have you tried adding a remove_cache in the hook and see if the issue still occurs?

    UM()->user()->remove_cache( $user_id );

    Regards,

    Thread Starter Nicolas

    (@nchaccal)

    Sorry for the noob question, but where do i need to put it? At the start of the code or at the end?

    This is more or less my code (which its work, but only if you edit profile twice). I use wp_remote_request with a put method:

    function edit_profile( $args ) {
    $body = [
        'first_name' => um_user(first_name),
        'last_name' => um_user('last_name'),
        'phone' => um_user('phone'),
        'email' => um_user('email'),
    ];
    
    $body = wp_json_encode( $body );
     
    $options = [
        'body'        => $body,
        'headers'     => [
            'Content-Type' => 'application/json',
        ],
        'method'    => 'PUT',
        'timeout'     => 60,
        'redirection' => 5,
        'blocking'    => true,
        'httpversion' => '1.0',
        'sslverify'   => false,
        'data_format' => 'body',
    ];
    
    $response = wp_remote_request( 'https://xxxxxxxxxxxx.xxxx.xxx', $options );	
    UM()->user()->remove_cache( $user_id );
    
    }
     
    add_action( 'um_after_user_updated', 'edit_profile', 10, 2 );

    Thanks in advance! ??

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @nchaccal

    Please try this one:

    function edit_profile( $args ) {
    
    // Remove cache
    UM()->user()->remove_cache( um_user('ID') );
    
    $body = [
        'first_name' => um_user('first_name'),
        'last_name' => um_user('last_name'),
        'phone' => um_user('phone'),
        'email' => um_user('email'),
    ];
    
    $body = wp_json_encode( $body );
     
    $options = [
        'body'        => $body,
        'headers'     => [
            'Content-Type' => 'application/json',
        ],
        'method'    => 'PUT',
        'timeout'     => 60,
        'redirection' => 5,
        'blocking'    => true,
        'httpversion' => '1.0',
        'sslverify'   => false,
        'data_format' => 'body',
    ];
    
    $response = wp_remote_request( 'https://xxxxxxxxxxxx.xxxx.xxx', $options );
    
    }
     
    add_action( 'um_after_user_updated', 'edit_profile', 10, 2 );
    

    Regards,

    Thread Starter Nicolas

    (@nchaccal)

    Hi!

    Thanks for the code. But unfortunately nothing changed.

    I tried with the original user edit of wordpress and works fine. The thing is when i try to make changes from the UM profile editor.

    Any other idea?

    Thanks again for your collaboration and sorry for bother you with this.

    Plugin Contributor Champ Camba

    (@champsupertramp)

    Hi @nchaccal

    Try changing the action hook priority from 10 to 1. Also remove the 2 from the parameter as you’re only using the first parameter in the function.

    e.g. add_action( 'um_after_user_updated', 'edit_profile', 1 );

    Regards,

    Thread Starter Nicolas

    (@nchaccal)

    Hi again!

    Sorry, I really don’t want to be a bother, but nothing has changed yet.

    I’ll keep trying to make it work.

    If you have another idea in mind, please let me know.

    BTW, i note that if, for example, i change the first_name for another one in the first time nothing happen, but, when i do it for a second time with a different first_name, it will change to the option that i put at the first try. It’s very strange. I dont know if there a queque or something.

    My debug console does not show anything related with the HTTP PUT Method.

    Thanks for your time. I really appreciate it.

    Thread Starter Nicolas

    (@nchaccal)

    EDIT:

    I solved it.

    I had to put this at first of my function (which i dont know well what it does lol):

    global $ultimatemember;
    um_fetch_user( um_user('ID') );

    Thanks for your help and your concern in my case ??

    • This reply was modified 4 years, 2 months ago by Nicolas.
    • This reply was modified 4 years, 2 months ago by Nicolas.
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘um_user_edit_profile hook work only when hook twice’ is closed to new replies.