IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    WordPress 4.3 新用户注册邮件密码为both admin的解决方法

    Mike发表于 2015-09-07 16:55:00
    love 0

    这是我的一个客户案例。

    首先我们来看一下官方文档的说明:

    As of WP 4.3, a plain text password is no longer passed to the function. If you have a plugged version of this function and are assuming that the second function argument is $plaintext_pass, the password displayed in your email to the user will be "admin" or "both".

    大概的意思是:在WP 4.3版本中,纯文本密码将不会传递给函数,在您的电子邮件中密码将被显示成“admin”或“both”。

    其实在WP 4.3用户注册机制已经发生改变,用户现在需要点击邮箱中发来的链接,自己设置密码。

    把插件修改成类似以下代码吧,官方文档的不好使,会提示验证链接不对。

    1. <?php   
    2. /*  
    3.   Plugin Name:New User Notification  
    4.   Description:重新定义新用户注册邮件  
    5.   Version: 1.1(15.09.04)  
    6.  */  
    7.   
    8. if ( !function_exists('wp_new_user_notification') ) {   
    9.   
    10.     function wp_new_user_notification( $user_id, $notify = '' ) {   
    11.     
    12.                 global $wpdb;   
    13.         $user = new WP_User( $user_id );   
    14.   
    15.         $user_login = stripslashes( $user->user_login );   
    16.         $user_email = stripslashes( $user->user_email );   
    17.   
    18.         if ( 'admin' === $notify || emptyempty( $notify ) ) {   
    19.             return;   
    20.         }   
    21.   
    22.         // Generate a key.   
    23.         $key = wp_generate_password( 20, false );   
    24.            
    25.         do_action( 'retrieve_password_key', $user->user_login, $key );   
    26.   
    27.         // Now insert the key, hashed, into the DB.   
    28.         if ( emptyempty( $wp_hasher ) ) {   
    29.             require_once ABSPATH . WPINC . '/class-phpass.php';   
    30.             $wp_hasher = new PasswordHash( 8, true );   
    31.         }   
    32.            
    33.         $hashed = time() . ':' . $wp_hasher->HashPassword( $key );   
    34.         $wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) );   
    35.   
    36.         $message .= "您已注册成为工匠律师用户!下面是您的账户信息:\r\n\r\n";   
    37.   
    38.         $message .= sprintf(('Username: %s'), $user->user_login) . "\r\n\r\n";   
    39.         $message .= ('To set your password, visit the following address:') . "\r\n\r\n";   
    40.         $message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user->user_login), 'login');   
    41.   
    42.         wp_mail(   
    43.             $user_email,   
    44.             sprintf( __('[%s] Your username and password info'), get_option('blogname') ),   
    45.             $message  
    46.         );   
    47.     }   
    48. }  



沪ICP备19023445号-2号
友情链接