Support

Account

Home Forums ACF PRO Create new user with acf_form Reply To: Create new user with acf_form

  • Hi @leuchterits

    I believe you can do it by using the acf/save_post hook. But, instead of creating a post, you need to create a user using the wp_create_user() function and delete the newly created post using the wp_delete_post() function. Maybe something like this:

    function my_acf_save_multiple_posts( $post_id ) {
        
        // get the user name field
        $first_name = get_field('first_name', $post_id);
        
        // get the user name field
        $last_name = get_field('last_name', $post_id);
        
        // create the user
        wp_create_user( $first_name . "_" . $last_name, 'random password here' );
        
        // delete the unused post
        wp_delete_post($post_id);
        
    }
    
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_multiple_posts', 20);

    I hope this makes sense 🙂