• Resolved cdeuo2

    (@cdeuo2)


    Hello,

    I’m working on a site that interacts with 2 DBs: the WordPress one and a second DB hosted on the same server. The second DB also contains a table that will have information that would show up on a profile (names, email, and a few other information necessary for the website). This information is usually asked during registration because it is required, which means we created a few extra fields to capture that.

    Now I’m adding some code to functions.php to grab this info from the registration form and store it in the second DB.

    So my questions are:
    1. Do you provide a hook I can use to fire the code right after the new users clicks ‘submit’ and the registration form is validated?
    2. Do you provide a function I can use to grab the form entries right after it’s submitted and validated? I’d rather do that at registration time since we’d rather not automatically log the user in, which means I wouldn’t have access to the user meta after registration.

    Thanks for your help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Amrit Kumar Shrestha

    (@shresthauzwal)

    Hi @cdeuo2,

    Please use the following hooks to get the data before and after registration.

    After Registration Hook.

    add_action( 'user_registration_after_register_user_action', 'ur_do_something_after_user_registered', 10, 3 );
    function ur_do_something_after_user_registered( $valid_form_data, $form_id, $user_id ) {
        // Do Your tasks here after the user is registered on your site.
    }

    Before Registration Hook.

    add_filter( 'user_registration_before_register_user_action', 'ur_do_something_before_user_registered', 10, 2 );
    function ur_do_something_before_user_registered( $valid_form_data, $form_id ) {
        // Do Your tasks here after the form data is validated and before registering the user or sending data to the database.
    }

    I hope this helps.

    Regards!

    Thread Starter cdeuo2

    (@cdeuo2)

    Thank you for your help.

    Plugin Support Amrit Kumar Shrestha

    (@shresthauzwal)

    Hi @cdeuo2,

    Glad to know that the provided solution helps. ​If you have a moment to spare, we would really appreciate your review of our plugin. Please click on this link https://ww.wp.xz.cn/support/plugin/user-registration/reviews/#new-post and share your thoughts about our team and our plugin. We would love to hear from you.

    Thanks!

    Thread Starter cdeuo2

    (@cdeuo2)

    Hi,

    I’m having a bit more trouble with this hook; it won’t let me print information for testing purposes.

    Here’s what my code looks like:

    function ur_new_user($valid_form_data, $form_id, $user_id) {
       error_log(print_r($form_id, true)) ;
       // parse through $valid_form_data
    }
    
    add_action('user_registration_after_register_user_action', 'ur_new_user', 10, 3);

    The goal here is to print information so I can make sure I handle the data correctly before interacting with the second DB.

    What I’ve noticed:
    1. The code runs fine inside the function if I just call it normally and supply it with dummy arguments (i.e. no use of ‘add_action’). The error logs are printed accordingly.
    2. The code however does not seem to run (i.e. does not dump the data) when run with the hook (using with add_action).
    3. User still gets created with this hook.
    4. However the confirmation message at the bottom on successful user creation is no longer displayed when I use the hook.

    I’ve tried this on two differently hosted websites and this issue has been consistent. Hope you can help.

    Thanks!

    • This reply was modified 3 years, 9 months ago by cdeuo2.
    • This reply was modified 3 years, 9 months ago by cdeuo2.
    Plugin Support Amrit Kumar Shrestha

    (@shresthauzwal)

    Hi @cdeuo2,

    You are using the after registration hook so that you are getting the information of the registered user. Simply it helps you to collect the data after a successful registration. According to your requirement, we suggest you use the before registration hook user_registration_before_register_user_action

    Regards!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Hook and function request’ is closed to new replies.