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!
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.
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!