用户-删除“Send Password”复选框

时间:2014-04-23 作者:toby1kenobi

在WordPress admin中管理用户时,是否有建议删除“发送密码”复选框的方法?或者是一种改变用户的方式,而不需要以明文形式邮寄密码?

谢谢

托比

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

以下是一些如何处理neutralization 上的发送密码部分/wp-admin/user-new.php 页码:

send pass

想法1:

我们可以覆盖wp_new_user_notification() 函数,因为它pluggable:

请尝试以下示例:

if ( ! function_exists( \'wp_new_user_notification\' ) ):

function wp_new_user_notification($user_id, $plaintext_pass = \'\') {
        $user = get_userdata( $user_id );

        // The blogname option is escaped with esc_html on the way into the database in sanitize_option
        // we want to reverse this for the plain text arena of emails.
        $blogname = wp_specialchars_decode(get_option(\'blogname\'), ENT_QUOTES);

        $message  = sprintf(__(\'New user registration on your site %s:\'), $blogname) . "\\r\\n\\r\\n";
        $message .= sprintf(__(\'Username: %s\'), $user->user_login) . "\\r\\n\\r\\n";
        $message .= sprintf(__(\'E-mail: %s\'), $user->user_email) . "\\r\\n";

        @wp_mail(get_option(\'admin_email\'), sprintf(__(\'[%s] New User Registration\'), $blogname), $message);

        if ( empty($plaintext_pass) )
                return;

        // Let\'s remove this user notification part:  

        /* 
        $message  = sprintf(__(\'Username: %s\'), $user->user_login) . "\\r\\n";
        $message .= sprintf(__(\'Password: %s\'), $plaintext_pass) . "\\r\\n";
        $message .= wp_login_url() . "\\r\\n";

        wp_mail($user->user_email, sprintf(__(\'[%s] Your username and password\'), $blogname), $message);
        */
endif;
如果您不想通知用户,无论“发送密码”设置如何。

在这里,我们刚刚删除了向用户发送通知邮件的代码。

想法2:

让我们通过劫持show_password_fields 过滤器:

add_action( \'load-user-new.php\', function(){
   add_filter( \'show_password_fields\', function( $show ){
?>
        <tr class="form-field form-required">
                <th scope="row"><label for="pass1"><?php _e(\'Password\'); ?> <span class="description"><?php /* translators: password input field */_e(\'(required)\'); ?></span></label></th>
                <td>
                        <input class="hidden" value=" " /><!-- #24364 workaround -->
                        <input name="pass1" type="password" id="pass1" autocomplete="off" />
                </td>
        </tr>
        <tr class="form-field form-required">
                <th scope="row"><label for="pass2"><?php _e(\'Repeat Password\'); ?> <span class="description"><?php /* translators: password input field */_e(\'(required)\'); ?></span></label></th>
                <td>
                <input name="pass2" type="password" id="pass2" autocomplete="off" />
                <br />
                <div id="pass-strength-result"><?php _e(\'Strength indicator\'); ?></div>
                <p class="description indicator-hint"><?php _e(\'Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers, and symbols like ! " ? $ % ^ &amp; ).\'); ?></p>
                </td>
        </tr>
<?php
        return FALSE;
    });
});
想法3:我们可以尝试用CSS隐藏它,例如:

add_action( \'load-user-new.php\', function(){
    add_action( \'admin_head\', function(){
        ?><style>#createuser .form-table tr:nth-of-type(9){ display:none; }</style><?php
    });
});
如果没有任何额外的用户字段,否则我们可能必须调整tr:nth-of-type(9) 部分

想法4:使用javascript删除或禁用它。

想法5:

您还可以尝试取消设置$_POST[\'send_password\'] 在进入wp_new_user_notification 功能:

wp_new_user_notification( $user_id, 
                          isset( $_POST[\'send_password\'] ) ? wp_unslash( $pass1 )  : \'\' );
想法6:

使用output buffering/wp-admin/user-new.php 分页并替换不需要的HTML块;-)

结束