我想让用户选择自己的密码,但保留一封验证邮件(不重新设置密码链接)?
我在wp-login中添加了密码的输入字段:
<input type="password" name="user_password" value="" placeholder="Password" id="user_password" class="input" />
比,我有一个自定义插件,用于设置用户的密码:
function myplugin_registration_change_pass( $user_id )
{if ( isset( $_POST['user_password'] ) )
wp_set_password( $_POST['user_password'], $user_id );}
出于某种原因,我不断收到验证电子邮件,要求用户设置密码。 我有什么想法可以解决这个问题吗?
答案 0 :(得分:3)
<form name="registerform" id="registerform" action="<?php echo esc_url( site_url( 'wp-login.php?action=register', 'login_post' ) ); ?>" method="post" novalidate="novalidate">
<p>
<label for="user_login"><?php _e('*First Name') ?><br />
<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="25" /></label>
</p>
<p>
<label for="user_login"><?php _e('*Last Name') ?><br />
<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="25" /></label>
</p>
<p>
<label for="user_login"><?php _e('*Username') ?><br />
<input type="text" name="user_login" id="user_login" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="25" /></label>
</p>
<p>
<label for="user_email"><?php _e('*Email address') ?><br />
<input type="email" name="user_email" id="user_email" class="input" value="<?php echo esc_attr( wp_unslash( $user_email ) ); ?>" size="25" /></label>
</p>
<p>
<label for="user_login"><?php _e('*Choose a password') ?><br />
<input type="text" name="user_password" id="user_password" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="25" /></label>
</p>
<p>
<label for="user_login"><?php _e('*Confirm password') ?><br />
<input type="text" name="user_password" id="user_password" class="input" value="<?php echo esc_attr(wp_unslash($user_login)); ?>" size="25" /></label>
</p>
<p>
<input type="checkbox" name="vehicle" value="Bike" onclick="return false" checked >I agree to the terms and conditions<br>
</p>
当你在某个时候去wp-login.php时,你有这些字段供用户注册。我添加了名字和密码。我还创建了一个小插件,用于设置输入字段的密码:
function myplugin_set_pass( $user_id )
{if ( isset( $_POST['user_password'] ) )
wp_set_password( $_POST['user_password'], $user_id );}
add_action('user_register','myplugin_set_pass')
对于线条我说,在用户注册时,应该执行插件中的功能。换句话说,应该设置密码。我不确定这是否是正确的轨道。
答案 1 :(得分:0)
试试此代码
function frontend_register(){
$gfemail = $_POST['user_email'];
$firstname = $_POST['user_firstname'];
$lastname = $_POST['user_lastname'];
$password = $_POST['user_password'];
if (email_exists( $gfemail ) === false) {
$password = esc_attr( $password );
$email = sanitize_email( $gfemail );
$first_name = sanitize_text_field( $firstname );
$last_name = sanitize_text_field( $lastname );
$userdata = array(
'user_login' => $email,
'user_email' => $email,
'user_pass' => $password,
'role' => 'subscriber',
'first_name' => $first_name,
'last_name' => $last_name,
);
$new_user = wp_insert_user ( $userdata );
if(!is_wp_error($new_user)){
$headers = 'Content-type: text/html;charset=utf-8' . "\r\n";
$headers .= 'From: Your SiteName <test@test.com>' . "\r\n";
$verifyCode = sha1($new_user.$email);
update_user_meta( $new_user, 'email_confirmation_done', 'No');
update_user_meta( $new_user, 'email_confirmation_code', $verifyCode);
$subject = 'Please verify your account' . "\r\n";
$mkUrl = sprintf('<a href="%s?verifycode=%s&user_login=%s">click here</a>', $wpgsloginpage, $verifyCode, $email);
$message = sprintf('<p>Dear %s,</p><br> ', $first_name);
$message .= sprintf('<hr>');
$message .= sprintf('<p><strong>Please verify your account by clicking on this link %s </strong></p>', $mkUrl);
$message .= sprintf('<hr>');
$message .= sprintf('<br><p style="font-size:12.8px">Thank you for registering<br><br>');
wp_mail($email, $subject, $message, $headers);
die("success");
}
}else{
die("failure");
}
}
if ( ! function_exists( 'wp_new_user_notification' ) ) :
function wp_new_user_notification( $user_id, $deprecated = null, $notify = '' ) {
return;
}
endif;