Overall Problem: ACF fields in front end registration not saving to user profile
Having some trouble with front end registration and ACF. I've got ACF fields attached to a custom user role, but I'm unable to save them through front end registration
First, my form.
function custom_registration_form_fields() {
ob_start(); ?>
<h3 class="custom_header"><?php _e('Register New Account'); ?></h3>
<?php custom_show_error_messages(); ?>
<form id="custom_registration_form" class="custom_form" action="" method="POST">
<fieldset>
<p>
<label for="custom_user_Login"><?php _e('Username'); ?></label>
<input name="custom_user_login" id="custom_user_login" class="required" type="text"/>
</p>
<p>
<label for="custom_user_email"><?php _e('Email'); ?></label>
<input name="custom_user_email" id="custom_user_email" class="required" type="email"/>
</p>
<p>
<label for="custom_user_first"><?php _e('First Name'); ?></label>
<input name="custom_user_first" id="custom_user_first" type="text"/>
</p>
<p>
<label for="custom_user_last"><?php _e('Last Name'); ?></label>
<input name="custom_user_last" id="custom_user_last" type="text"/>
</p>
<p>
<label for="password"><?php _e('Password'); ?></label>
<input name="custom_user_pass" id="password" class="required" type="password"/>
</p>
<p>
<label for="password_again"><?php _e('Password Again'); ?></label>
<input name="custom_user_pass_confirm" id="password_again" class="required" type="password"/>
</p>
<?php custom_acf_registration_fields();?>
<p>
<input type="hidden" name="custom_register_nonce" value="<?php echo wp_create_nonce('custom-register-nonce'); ?>"/>
<input type="submit" value="<?php _e('Register Your Account'); ?>"/>
</p>
</fieldset>
</form>
<?php
return ob_get_clean();
}
And here's the function adding my ACF form fields.
function custom_acf_registration_fields()
{
if(function_exists('acf_form'))
{
if ( is_user_logged_in() === true )
{
global $current_user;
$user_id = 'user_'.$current_user->ID;
}
else
$user_id = 'user_new';
$args = array(
'post_id' => $user_id,
'field_groups' => array(141),
'form' => false
);
acf_form( $args );
}
}
add_action('register_form', 'custom_acf_registration_fields');
And then I've attached this to the header.
function add_acf_form_head(){
global $post;
if ( !empty($post) && has_shortcode( $post->post_content, 'register_form' ) ) {
acf_form_head();
}
}
add_action( 'get_header', 'add_acf_form_head' );
And lastly, I have my save ACF values.
function save_additional_user_meta( $user_id ) {
if ( isset( $_POST['fields']['field_5e4acd8bb31a0'] ) ) {
update_user_meta($user_id, 'country', $_POST['fields']['field_5e4acd8bb31a0']);
}
if ( isset( $_POST['fields']['field_5e4ace947d640'] ) ) {
update_user_meta($user_id, 'tagline', $_POST['fields']['field_5e4ace947d640']);
}
if ( isset( $_POST['fields']['field_5e4ace3db31a1'] ) ) {
update_user_meta($user_id, 'profile_image', $_POST['fields']['field_5e4ace3db31a1']);
}
}
add_action( 'user_register', 'save_additional_user_meta', 10, 1 );
Unfortunately, this is not saving my ACF fields to the user profile, and I'm not sure why. It's also not saving the user with the custom user role I made, despite setting it in the admin config.