WordPress.org

Make WordPress Core

Ticket #24633: 24633.patch

File 24633.patch, 4.6 KB (added by mordauk, 5 years ago)
  • wp-admin/admin-ajax.php

     
    5757        'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment',
    5858        'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor',
    5959        'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs',
     60        'generate_password',
    6061);
    6162
    6263// Register core Ajax calls.
  • wp-admin/includes/user.php

     
    157157
    158158        if ( $update ) {
    159159                $user_id = wp_update_user( $user );
     160
     161                // Encourage the user to reset their password
     162                if( ! empty( $_POST['reset_password'] ) ) {
     163                        update_user_option( $user_id, 'default_password_nag', true, true );
     164                }
     165
     166                // Send the new, plaintext password to the user
     167                if( ! empty( $_POST['send_password'] ) ) {
     168                        $blogname = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );
     169                        $message  = sprintf( __( 'Username: %s' ), $user->user_login ) . "\r\n";
     170                        $message .= sprintf( __( 'Password: %s' ), $pass1 ) . "\r\n";
     171                        $message .= wp_login_url() . "\r\n";
     172
     173                        wp_mail( $user->user_email, sprintf( __( '[%s] Your username and password' ), $blogname ), $message );
     174                }
     175
    160176        } else {
    161177                $user_id = wp_insert_user( $user );
    162178                wp_new_user_notification( $user_id, isset( $_POST['send_password'] ) ? wp_unslash( $pass1 ) : '' );
  • wp-admin/includes/ajax-actions.php

     
    21232123        }
    21242124        wp_send_json_success( $return );
    21252125}
     2126
     2127function wp_ajax_generate_password() {
     2128        die( wp_generate_password() );
     2129}
     2130 No newline at end of file
  • wp-admin/js/user-profile.js

     
    3535                $('#pass1').val('').keyup( check_pass_strength );
    3636                $('#pass2').val('').keyup( check_pass_strength );
    3737                $('#pass-strength-result').show();
     38                $('#generate-password').on('click', function() {
     39                        $.post( ajaxurl, { action: 'generate_password' }, function( response ) {
     40                                $('#pass1,#pass2').val( response ).trigger('keyup');
     41                        });
     42                });
    3843                $('.color-palette').click( function() {
    3944                        $(this).siblings('input[name="admin_color"]').prop('checked', true);
    4045                });
  • wp-admin/user-edit.php

     
    384384<tr>
    385385        <th scope="row"><label for="pass2"><?php _e('Repeat New Password'); ?></label></th>
    386386        <td>
    387         <input name="pass2" type="password" id="pass2" size="16" value="" autocomplete="off" /> <span class="description" for="pass2"><?php _e("Type your new password again."); ?></span>
    388         <br />
    389         <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
    390         <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>
     387                <input name="pass2" type="password" id="pass2" size="16" value="" autocomplete="off" /> <span class="description" for="pass2"><?php _e("Type your new password again."); ?></span>
     388                <br />
     389                <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
     390                <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>
     391                <br/>
     392                <input type="button" name="generate-password" id="generate-password" value="<?php _e( 'Generate Password' ); ?>" class="button hide-if-no-js" />
    391393        </td>
    392394</tr>
     395<tr class="hide-if-no-js">
     396        <th scope="row"><label for="send_password"><?php _e( 'Send Password?' ) ?></label></th>
     397        <td>
     398                <label for="send_password">
     399                        <input type="checkbox" name="send_password" id="send_password" /> <?php _e( 'Send this password to the user by email.'); ?>
     400                </label>
     401                <br/>
     402                <label for="reset_password">
     403                        <input type="checkbox" name="reset_password" id="reset_password" /> <?php _e( 'Encourage the user to change their password, once logged in.' ); ?>
     404                </label>
     405        </td>
     406</tr>
    393407<?php endif; ?>
    394408</table>