admin管理员组文章数量:1279207
I'm using the below function which is working for my phone and address fields. I can't seem to change the email though... any idea what I'm doing wrong?
function um_modifications_callback() {
// Ensure we have the data we need to continue
if( ! isset( $_POST ) || empty( $_POST ) || ! is_user_logged_in() ) {
// If we don't - return custom error message and exit
header( 'HTTP/1.1 400 Empty POST Values' );
echo 'Could Not Verify POST Values.';
exit;
}
$user_id = get_current_user_id(); // Get our current user ID
$um_val = sanitize_text_field( $_POST['first_name'] ); // Sanitize our user meta value
$um_user_email = sanitize_text_field( $_POST['user_email'] ); // Sanitize our user email field
$phone = $_POST['phone'];
$address = $_POST['address'];
$email = $_POST['user_email'];
update_field('phone', $phone, 'user_'.$user_id);
update_field('address', $address, 'user_'.$user_id);
update_user_meta( $user_id, 'first_name', $um_val ); // Update our user meta
wp_update_user( array(
'ID' => $user_id,
'user_email' => $email,
) );
exit;
}
I'm using the below function which is working for my phone and address fields. I can't seem to change the email though... any idea what I'm doing wrong?
function um_modifications_callback() {
// Ensure we have the data we need to continue
if( ! isset( $_POST ) || empty( $_POST ) || ! is_user_logged_in() ) {
// If we don't - return custom error message and exit
header( 'HTTP/1.1 400 Empty POST Values' );
echo 'Could Not Verify POST Values.';
exit;
}
$user_id = get_current_user_id(); // Get our current user ID
$um_val = sanitize_text_field( $_POST['first_name'] ); // Sanitize our user meta value
$um_user_email = sanitize_text_field( $_POST['user_email'] ); // Sanitize our user email field
$phone = $_POST['phone'];
$address = $_POST['address'];
$email = $_POST['user_email'];
update_field('phone', $phone, 'user_'.$user_id);
update_field('address', $address, 'user_'.$user_id);
update_user_meta( $user_id, 'first_name', $um_val ); // Update our user meta
wp_update_user( array(
'ID' => $user_id,
'user_email' => $email,
) );
exit;
}
Share
Improve this question
asked Sep 27, 2021 at 3:03
user205498user205498
31 bronze badge
1 Answer
Reset to default 0You can diagnose error while updating user email.
$user_data = wp_update_user( array( 'ID' => $user_id, 'user_email' => $email ) );
if ( is_wp_error( $user_data ) ) {
// There was an error; possibly this user doesn't exist.
echo 'Error.';
} else {
// Success!
echo 'User profile updated.';
}
Might it can help you.
本文标签: How do I update user email from frontend input field
版权声明:本文标题:How do I update user email from frontend input field? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741300298a2371052.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论