登录时不接受在注册中选择的用户密码

时间:2016-09-25 作者:Samer Massad

用户注册的效果很好,只是当用户尝试登录时,他选择的密码不被接受,从后端生成一个新密码并尝试使用生成的密码登录。我错过了什么?

$email = $_POST["email"];
$password = $_POST["password1"];
$firstName = $_POST["fname"];
$lastName = $_POST["lname"];
$company = $_POST["company"];
$website = $_POST["website"];
$address = $_POST["address"];
$street = $_POST["street"];
$city = $_POST["city"];
$state = $_POST["state"];
$zip = $_POST["zip"];
$country = $_POST["country"];
$home = $_POST["home"];
$office = $_POST["office"];
$mobile = $_POST["mobile"];


if( null == username_exists( $email ) ) {

  $user_id = wp_create_user( $email, $password, $email );

  wp_update_user(
    array(
      \'ID\'          =>    $user_id,
      \'nickname\'    =>    $email_address,
      \'first_name\'  =>    $firstName,
      \'last_name\'   =>    $lastName,
      \'user_url\'    =>    $website
    )
  );

  update_user_meta( $user_id, \'company\', $company );
  update_user_meta( $user_id, \'address\', $address );
  update_user_meta( $user_id, \'street\', $street );
  update_user_meta( $user_id, \'city\', $city );
  update_user_meta( $user_id, \'province\', $state );
  update_user_meta( $user_id, \'postalcode\', $zip);
  update_user_meta( $user_id, \'country\', $country );
  update_user_meta( $user_id, \'home\', $home );
  update_user_meta( $user_id, \'office\', $office );
  update_user_meta( $user_id, \'mobile\', $mobile );

  $user = new WP_User( $user_id );

  $user->set_role( \'subscriber\' );

} else {
    echo \'user exists\';
}
更换$password 在里面wp_create_user() 具有\'testpassword\' 或将新行添加到wp_update_user() 大堆\'user_pass\' => \'testpassword\' 两者都不起作用。

2 个回复
最合适的回答,由SO网友:Samer Massad 整理而成

对于路过并有相同问题的人:

对我来说,我使用的是“New User Approve”插件,在深入搜索插件代码后,生成一个新的随机密码,并对其进行哈希运算,然后覆盖管理员批准新用户时设置的任何密码。可能有两种解决方案:

编辑插件代码,查找其他插件或向functions.php 这会向新用户添加管理员批准

SO网友:The J

不要将纯文本作为密码传递,请使用this 功能:

wp_set_password( $password, $user_id );
请记住,它应该只在用户创建时运行(所以只运行一次),否则密码可能会不断更改。

相关推荐

为什么我可以登录wp-login.php而不能登录wp-admin.php?

我最近更改了配置。我的FTP中Wordpress中的php文件,因为URL错误(我用define(\'WP_SITEURL\', \'http://www.myyyysite.com\'); define(\'WP_HOME\', \'http://www.myyyysite.com\');.现在我仍然无法登录www.myyyysite.com/wp-admin.php 但是www.myyyysite.com/wp-login.php 作品有什么问题吗only works 对于the wp-login.p