简体   繁体   English

如何将密码字段添加到默认的 WordPress 注册?

[英]How to add password fields to a default WordPress registration?

I woulrd like to enable users to choose their own passord, but keep a verification email(without reseting password link)?我想让用户选择自己的密码,但要保留验证邮件(无需重置密码链接)?

I am adding an input field for the password in wp-login:我在 wp-login 中为密码添加了一个输入字段:

<input type="password" name="user_password" value="" placeholder="Password" id="user_password" class="input" />

Than, I have a custom plugin thats sets user's password:然后,我有一个设置用户密码的自定义插件:

function myplugin_registration_change_pass( $user_id ) 

{if ( isset( $_POST['user_password'] ) )
    wp_set_password( $_POST['user_password'], $user_id );}

For some reason I keep getting verification email asking the user to set a password.出于某种原因,我不断收到要求用户设置密码的验证电子邮件。 ANy ideas how I can solve this?有什么想法可以解决这个问题吗?

<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>

When you go to wp-login.php at some point you have these fields for user registration.当您在某个时候访问 wp-login.php 时,您将拥有这些用于用户注册的字段。 I added first, last name and password.I also created a small plugin that sets the password from the input field:我添加了名字,姓氏和密码。我还创建了一个小插件,用于从输入字段设置密码:

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')

With the line line I am saying that on user registration the function from the plugin should be performed.我是说在用户注册时应该执行插件中的功能。 In other words the password should be set.换句话说,应该设置密码。 I am not really sure if that is the right track.我不确定这是否是正确的轨道。

Try this code试试这个代码

  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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将自定义字段添加到注册表单? WordPress的 - How can i add custom fields to registration form ? wordpress 如何在Wordpress多站点中向注册页面添加新字段以进行新用户注册? - how can i add new fields to registration page for new user registration in wordpress multisite? 将其他Billing注册字段与WooCommerce中的默认Wordpress字段同步 - Sync additional Billing registration fields with default Wordpress fields in WooCommerce 如何添加默认情况下受密码保护的Wordpress帖子类型 - How to add a Wordpress post type that is password protected by default 将自定义 WooCommerce 注册字段添加到管理 WordPress 用户联系人字段 - Add custom WooCommerce registration fields to admin WordPress user contact fields 如何修改默认的 WordPress 注册表单? - How to modify default WordPress registration form? 如何在joomla 2.5默认值中以注册表单添加新字段(com_users) - How to add new fields in registration form in joomla 2.5 default (com_users) WordPress多站点在注册时添加自定义字段,然后在配置文件页面中显示 - Wordpress Multisite Add custom fields on registration then show in Profile Page 如何在Facebook注册插件中添加隐藏字段? - how to add hidden fields in Facebook Registration Plugin? 如何将自定义字段添加到 WooCommerce 注册表单 - How to add custom fields to WooCommerce registration form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM