Skip Navigation

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

Relevant Documentation:
https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

This support ticket is created 6 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 3 replies, has 2 voices.

Last updated by aaronM-9 6 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#627540

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.

- Aaron

#627546

PS - The title of that post should have read "Custom SQL Code" not customer! Sorry for the typo.

#627660

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Aaron

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.

add_action( 'cred_save_data', 'tssupp_test_hook', 10, 2 );
function tssupp_test_hook( $post_id, $form_data ){

	error_log( "id is: " . $post_id );
	error_log(print_r($form_data, true));
}

If you haven't already, turn on the debug log by editing your wp-config.php file and change the line with WP_DEBUG like so:

define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);

That will create a debug log called debug.log in your wp-content directory which you can examine in any text editor.

#627993

Thanks for the help. It may take me a little bit longer to iron out the details, but I think this tells me what I need to know.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.