Title: Hook and function request
Last modified: August 15, 2022

---

# Hook and function request

 *  Resolved [cdeuo2](https://wordpress.org/support/users/cdeuo2/)
 * (@cdeuo2)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/hook-and-function-request/)
 * 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](https://wordpress.org/support/users/shresthauzwal/)
 * (@shresthauzwal)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/hook-and-function-request/#post-15919577)
 * Hi [@cdeuo2](https://wordpress.org/support/users/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](https://wordpress.org/support/users/cdeuo2/)
 * (@cdeuo2)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/hook-and-function-request/#post-15924637)
 * Thank you for your help.
 *  Plugin Support [Amrit Kumar Shrestha](https://wordpress.org/support/users/shresthauzwal/)
 * (@shresthauzwal)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/hook-and-function-request/#post-15926804)
 * Hi [@cdeuo2](https://wordpress.org/support/users/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://wordpress.org/support/plugin/user-registration/reviews/#new-post](https://wordpress.org/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](https://wordpress.org/support/users/cdeuo2/)
 * (@cdeuo2)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/hook-and-function-request/#post-15943515)
 * 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](https://wordpress.org/support/users/cdeuo2/).
    -  This reply was modified 3 years, 9 months ago by [cdeuo2](https://wordpress.org/support/users/cdeuo2/).
 *  Plugin Support [Amrit Kumar Shrestha](https://wordpress.org/support/users/shresthauzwal/)
 * (@shresthauzwal)
 * [3 years, 9 months ago](https://wordpress.org/support/topic/hook-and-function-request/#post-15944562)
 * Hi [@cdeuo2](https://wordpress.org/support/users/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.

 * ![](https://ps.w.org/user-registration/assets/icon-256x256.gif?rev=3284028)
 * [User Registration & Membership - Free & Paid Memberships, Subscriptions, Content Restriction, User Profile, Custom User Registration & Login Builder](https://wordpress.org/plugins/user-registration/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/user-registration/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/user-registration/)
 * [Active Topics](https://wordpress.org/support/plugin/user-registration/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/user-registration/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/user-registration/reviews/)

 * 5 replies
 * 2 participants
 * Last reply from: [Amrit Kumar Shrestha](https://wordpress.org/support/users/shresthauzwal/)
 * Last activity: [3 years, 9 months ago](https://wordpress.org/support/topic/hook-and-function-request/#post-15944562)
 * Status: resolved