0

Is there a recommended method for removing the 'Send password' checkbox when managing users in WordPress admin? Or alternatively a way of alterting users to changes that doesn't involve mailing the password in plain text?

Thanks,

Toby

1 Answer 1

2

Here are few ideas how to deal with the neutralization of the Send Password part on the /wp-admin/user-new.php page:

send pass

Idea 1:

We can overwrite the wp_new_user_notification() function, because it's pluggable:

Try for example:

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;

if you don't want to notify the user, regardless of the Send Password settings.

Here we just removed the code that sends a notification mail to the user.

Idea 2:

Let's try to remove the Send Password settings by hijacking the show_password_fields filter:

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;
    });
});

Idea 3:

We can try to hide it with CSS, for example:

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
    });
});

if you don't have any extra user fields, otherwise we might have to adjust the tr:nth-of-type(9) part.

Idea 4:

Use javascript to remove or disable it.

Idea 5:

You can also try to unset the $_POST['send_password'] part on submit, before it goes into the wp_new_user_notification function:

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

Idea 6:

This one is theoretical and just for fun:

Use output buffering on the /wp-admin/user-new.php page and replace the unwanted HTML blocks ;-)

2
  • This was really helpful, I've gone with a combination of 1 and 4 - thanks! Apr 25, 2014 at 15:20
  • 1
    Also tr.pw-weak + tr {display: none;} if you just need to hide it.
    – Howdy_McGee
    Feb 6, 2019 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.