如何只为第一次设置密码的用户定制wp-login.php?

时间:2015-10-02 作者:Victoria

作为管理员,如果我创建了一个新用户,我可以选择通过电子邮件向我的新用户发送一个链接,他们可以单击该链接进入wp登录。php,首次邀请他们设置密码。(Wordpress过去常常通过电子邮件发送密码,但我知道他们为什么更改了!)

用户到达wp登录,该登录在一个隐藏字段中记录用户名,并显示一个他们可以自定义的建议密码。

我的一些更容易困惑的用户对此感到困惑。他们发现生成的密码不可理解,并且不理解他们可以单击框中的建议密码并将其更改为可以记住的密码。我想添加一些帮助文本,也许此时也会自动选择建议的密码。

我不确定哪个钩子能让我做那些only 显示给正在设置密码的用户,而不显示给正在登录的任何其他人。

我该怎么做?

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

您可以在重置密码屏幕上添加额外的帮助消息框:

help text

具有以下功能:

 /**
  * Display an extra help message box on the \'reset password\' screen
  * 
  * @link http://wordpress.stackexchange.com/a/204429/26350
  */
 add_action( \'validate_password_reset\', function( $errors )
 {
    add_action( \'login_message\', function( $message )
    {
        // Modify this help message box to your needs:
        $mybox = sprintf( 
            \'<br/><p class="message reset-pass">%s</p>\',
            __( \'Some help text here!\' )
        );

        return $message . $mybox; 
    } );
 } );
在这里,我们使用login_message 滤器它应该只显示在重置密码屏幕上,因为我们将其挂接到validate_password_reset 行动

SO网友:squarecandy

最后我用了这个。这绝对是一个黑客。。。如果其他人知道如何更好地修改wp-admin/js/user-profile.js 没有黑客核心,请让我知道。我不想注销整个脚本,因为我喜欢里面的所有密码强度检查等。

// add some js to the login page
function squarecandy_login_stylesheet() {
    wp_enqueue_script( \'custom-login-js\', get_stylesheet_directory_uri() . \'/js/login.js\' );
}
add_action( \'login_enqueue_scripts\', \'squarecandy_login_stylesheet\' );
登录名。js公司

jQuery(document).ready(function($){
  // wait half a second so WP can fill the suggestion first
  setTimeout( function(){
    // Switch to the non-visible entry mode
    $(\'.wp-hide-pw\').click();
    // clear the password fields, put the cursor in the field
    $(\'#pass1, #pass1-text\').val(\'\').focus();
  }, 500 );
});

相关推荐

How to change password

我有一个博客。我的电脑几个月前死机了,我的用户名是admin 我试图恢复我的密码,但由于密码丢失,创建一个新的密码,他们发送了一个巨大的长地址密码,不允许我复制,我只是不知道该怎么办。我最近再次支付了网站托管费用,无法使用我的仪表板。