I am trying to:
Create a "Change My Email" form.
Link to a page where the issue can be seen:
hidden link
I expected to see:
If new email and new email again fields don't match, should be "Emails don't match".
Instead, I got:
"Passwords don't match".
I don't know where that message is coming from. How do I control that?
My CRED form:
[creduserform]
[cred_field field='form_messages' class='alert alert-warning']
<div style="width:90%;margin-bottom:2rem;font-size:1.2rem;color:#666;">
<strong>Username: <span style="color:#06a">[wpv-user field="user_login"]</span></strong>
<br />
</div>
<div style="width:90%;margin-bottom:2rem;font-size:1.2rem;color:#666;">
<strong>Your current email address is: <span style="color:#06a">[wpv-current-user info='email']</span></strong>
</div>
<div id="newEmailAddr" style="width:50%;margin-bottom:2rem;">
<label>Enter New Primary Email Address *</label>
[cred_generic_field type='email' field='new_user_email_temp' id='new_user_email_temp']
{
"required":1,
"validate_format":1,
"default":""
}
[/cred_generic_field]
<span style="font-size:1rem;color:#666;">* Main email used for this account.</span>
</div>
<div id="newEmailAddrConfirm" style="width:50%;margin-bottom:2rem;">
<label>Confirm New Primary Email Address</label>
[cred_generic_field type='email' field='new_user_email_temp_confirm' id='new_user_email_temp_confirm']
{
"required":1,
"validate_format":1,
"default":""
}
[/cred_generic_field]
</div>
<div class="form-group" style="display:none; width:16%;margin-bottom:3rem;">
<label>Member Profile ID</label>
[cred_field field='member-profile-id' force_type='field' class='form-control' output='']
</div>
[cred_field field='form_submit' output='' value='Submit' class='btn btn-primary btn-lg']
[/creduserform]
NOTE that this website is more than 5 years old and I started with a very early version of types/views that did not support User forms. So, I had to create my own way. I created a CPT to act like a profile. Then, in the WP User, I created a custom field that references the post_id of the member's profile CPT. So, when a member updates their email, I need to update it in both places. Yes, I know it's a kludge, but it's been working fine that way for 5+ years, and it would be a LOT of work to change it in every View and Content Template. So, forgive me.
Also, remember to access this staging site:
flywheel
cnsvi333_%_$*9
My PHP code:
// Change My Email address (for current user, from Edit My Profile screens)
add_action('cred_save_data', 'change_my_email_addr',20,2);
function change_my_email_addr($post_id,$form_data) {
$current_user = wp_get_current_user(); // we beed the login (username) to use wp_insert_user()
$user_id = $current_user->ID; // and the ID
if ($form_data['id'] == 32684) { // is this the change my email form?
$new_email = esc_attr( $_POST['new_user_email_temp'] ); // user_email
$usermeta_member_profile_id = $_POST['wpcf-member-profile-id'];
$post_id = $usermeta_member_profile_id;
// echo ('<br/> USER ID = ' . $user_id . ', NEW EMAIL = ' . $new_email . ', MBR-PROF-ID = ' . $usermeta_member_profile_id . '<br/>');
// die;
// store it to the CNSV member profile
update_post_meta($post_id, 'wpcf-email', $new_email);
// update it in the WP user
add_filter( 'send_email_change_email', '__return_false' ); // first, disable email notice of change
if (email_exists( $new_email )) {
// Email exists, do not update value.
echo ('<br/><br/><br/> ERROR: THAT EMAIL ALREADY EXISTS! <br/>');
} else {
$args = array(
'ID' => $user_id,
'user_email' => $new_email
);
wp_update_user( $args );
}
}
}