[Resolved] Run Custom SQL Code After Creation of New User
This thread is resolved. Here is a description of the problem and solution.
Problem:
Can the cred_save_data hook be used with CRED User forms as well as CRED post forms? The documentation describes the attributes as if they were only for post forms.
Solution:
Yes. When used with a User form the $post_id attribute is actually the user ID.
Can you tell me if a CRED Hook is the best way to run custom SQL code immediately following the creation of a new user account (presumably after submitting a user registration form)? If so, do you use the cred_save_data hook? If this is the case, is the post ID argument used for the user ID and how do you specify the user ID if you do not know what it is until the user account has been generated? If you can't use this hook on user accounts (i.e. it can only be used for posts), how do I accomplish what I want to do?
Basically, I would like my website to prep some data whenever a new user signs up, so I'd like to run an INSERT query whenever a new user signs up.
Thanks for any help, and I apologize if somehow I missed this while reading through your Hooks documentation.
Yes, the documentation is not too helpful here, as the cred_save_data hook, or the cred_submit_complete hook which you could also use, are the same for both post and user forms, and the post_id argument would be just that, the post id of the newly created post, for post forms, or the user id of the newly created user for user forms.
Note that you are not providing the user id (via post_id), the hook makes that available to you.
To see what you are dealing with, I would print the arguments to your debug log so that you can inspect them, e.g.