After many days, I managed to solve this.
Because I am using ACF, I should use the built-in action to do what you want after the data is saved.
Because this action will be called every time a post is created/saved, etc, I will probably need to add an if statement to check if it's the post type you're looking for.
All of the fields should be available via $_POST['fields']
as well if get_post_meta does not return what I'm looking for.
The modified code below uses the ACF action AFTER the post has been saved, so the meta should be available. I can do a var_dump on the $_POST['fields']
to see what POST data is available as well.
http://www.advancedcustomfields.com/resources/actions/acfsave_post/
add_action('acf/save_post', 'people_postdata', 20);
function people_postdata($post_id) {
global $wpdb;
$firstname = get_post_meta($post_id, 'first_name', true);
$lastname = get_post_meta($post_id, 'last_name', true);
$email = get_post_meta($post_id, 'email_address', true);
$password = get_post_meta($post_id, 'password', true);
$username = preg_replace('/[^A-Za-z0-9]/', '', strtolower(get_the_title($post_id)));
$userargs = array(
'first_name' => $firstname,
'last_name' => $lastname,
'user_login' => $username,
'user_email' => $email,
'user_pass' => $password,
'role' => 'basic'
);
// var_dump($userargs);
wp_insert_user($userargs);
}