Skip Navigation

[Resolved] user_register hook with different user post

This support ticket is created 4 years, 4 months 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9:00 – 13:00
14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 - - 14:00 – 18:00

Supporter timezone: Africa/Casablanca (GMT+01:00)

This topic contains 1 reply, has 2 voices.

Last updated by Jamal 4 years, 4 months ago.

Assisted by: Jamal.

Author
Posts
#1805097

Dear Sir/Madam,

I know how to use the WP user_register hook and also the Toolset my_save_data_action(). I will have two user forms for new user to register.

1. Register only
2. Register and then apply the application.

As user_register hook is automatically be triggered and a new user be created, here is the change to my user_register hook

function auto_application($user_id){
    if (!$user_id>0)
        return;

    $new_post = array(
        'ID' => '',
        'post_author' => $user_id, 
        'post_status' => 'publish',
        'post_type' => 'application',
        'meta_input' => array(
            'wpcf-competition-id' => $_POST['application-type'],
        )
    );

    $post_id = wp_insert_post($new_post, 1);

    wp_update_post( array(
        'ID' => $post_id,
        'post_name' => $post_id,
    ));
}        
add_action( 'user_register', 'auto_apply_competition', 10, 1 );

As there are two forms will do the registration, how can I check which user form I called from and I can do different action?

Best regards,

Kelvin

#1805793

Hello Kelvin and thank you for contacting the Toolset support.

What if you used the "cred_save_data" hook from Toolset, instead of "". Read more about it here https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data

The hook is used for both, post forms and user forms, and the $post_id is either the created/edited post_id or user_id.

Let me know if you must use "user_register" and I'll find a way to help.