$user_id not returned in user_register()

Home Forums Everest Forms $user_id not returned in user_register()

This topic contains 3 replies, has 2 voices, and was last updated by  hallbir 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #14085

    hallbir
    Participant

    Hi
    I try hooking an action on user_register hook, but I cannot retrieve the $user_id which should be delivered by the hook.
    I have come to suspect that maybe User Registration plugin is interfering. Could that be? I use this plugin for registration form.

    This is my code, just for testing:
    `add_action( ‘user_register’, ‘myplugin_registration_save’, 10, 1 );

    function myplugin_registration_save( $user_ID ) {

    add_user_meta(17,’nøkkel’,$user_ID,true);

    }

    The user_meta is updated if I hard-code a value, but with the $user_id variable, no value is stored in db.

    #14260

    rumesh38
    Moderator

    Hi there,

    The hook action is not correct. You can use do_action( 'user_registration_after_register_user_action', self::$valid_form_data, $form_id, $user_id ); this hook to get user_id. This hook is called after the user have been registered.

    Your code must be like this :

    add_action( ‘user_registration_after_register_user_action’, ‘myplugin_registration_save’, 10, 1 );
    function myplugin_registration_save( $form_data, $form_id, $user_ID ) {
        add_user_meta(17,’nøkkel’,$user_ID,true);
    }

    Thanks & Regards,
    WPEverest Support Team.

    #14280

    hallbir
    Participant

    Thank you! But unfortunately, this doesn’t seem to work at all? Is the name of the hook correct?

    #14336

    hallbir
    Participant

    Sorry, my first code is correct apart from using $user_ID instead of $user_id.
    I tried all this, but obviously, something must have been wrong, as it works now.
    Not with user_registration_after_register_user_action, but with user_register.

    Thanks anyway!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.