Make WordPress Core

Ticket #32589: 32589.4.diff

File 32589.4.diff, 11.6 KB (added by MikeHansenMe, 10 years ago)

Add UI to add new user

  • src/wp-admin/css/forms.css

     
    401401        color: #777;
    402402}
    403403
     404button.wp-hide-pw > .dashicons {
     405        position: relative;
     406        top: 3px;
     407}
     408
    404409label,
    405410#your-profile label + a {
    406411        vertical-align: middle;
     
    434439#pass-strength-result {
    435440        background-color: #eee;
    436441        border: 1px solid #ddd;
    437         float: left;
    438         margin: 13px 5px 5px 1px;
     442        margin: -2px 5px 5px 1px;
    439443        padding: 3px 5px;
    440444        text-align: center;
    441         width: 200px;
    442         display: none;
     445        width: 25em;
     446        box-sizing: border-box;
     447        opacity: 0;
    443448}
    444449
    445450#pass-strength-result.short {
     451        opacity: 1;
    446452        background-color: #ffa0a0;
    447453        border-color: #f04040;
    448454}
    449455
    450456#pass-strength-result.bad {
     457        opacity: 1;
    451458        background-color: #ffb78c;
    452459        border-color: #ff853c;
    453460}
    454461
    455462#pass-strength-result.good {
     463        opacity: 1;
    456464        background-color: #ffec8b;
    457465        border-color: #fc0;
    458466}
    459467
    460468#pass-strength-result.strong {
     469        opacity: 1;
    461470        background-color: #c3ff88;
    462471        border-color: #8dff1c;
    463472}
    464473
     474#pass1.short {
     475        border-color: #f04040;
     476}
     477
     478#pass1.bad {
     479        border-color: #ff853c;
     480}
     481
     482#pass1.good {
     483        border-color: #fc0;
     484}
     485
     486#pass1.strong {
     487        border-color: #8dff1c;
     488}
     489
     490.pw-weak{
     491        display:none;
     492}
     493
    465494.indicator-hint {
    466495        padding-top: 8px;
    467496}
  • src/wp-admin/js/user-profile.js

     
    11/* global ajaxurl, pwsL10n */
    22(function($){
     3        $(function(){
     4                var pw_new = $('.user-pass1-wrap'),
     5                        pw_line = pw_new.find('.wp-pwd'),
     6                        pw_field = $('#pass1'),
     7                        pw_field2 = $('#pass2'),
     8                        pw_togglebtn = pw_new.find('.wp-hide-pw'),
     9                        pw_generatebtn = pw_new.find('button.wp-generate-pw'),
     10                        pw_2 = $('.user-pass2-wrap'),
     11                        parentform = pw_new.closest('form'),
     12                        pw_strength = $('#pass-strength-result'),
     13                        pw_submitbtn_edit = $('#submit'),
     14                        pw_submitbtn_new = $( '#createusersub' ),
     15                        pw_checkbox = $('.pw-checkbox'),
     16                        pw_weak = $('.pw-weak')
     17                ;
    318
     19                pw_2.hide();
     20                pw_line.hide();
     21                pw_togglebtn.show();
     22                pw_generatebtn.show();
     23
     24                parentform.on('submit', function(){
     25                        pw_field2.val( pw_field.val() );
     26                        pw_field.attr('type', 'password');
     27                });
     28
     29
     30                pw_field.on('input propertychange', function(){
     31                        setTimeout( function(){
     32                                var cssClass = pw_strength.attr('class');
     33                                console.log( cssClass );
     34                                pw_field.removeClass( 'short bad good strong' );
     35                                if ( 'undefined' !== typeof cssClass ) {
     36                                        pw_field.addClass( cssClass );
     37                                        if ( cssClass == 'short' || cssClass == 'bad' ) {
     38                                                if ( ! pw_checkbox.attr( 'checked' ) ) {
     39                                                        pw_submitbtn_new.attr( 'disabled','disabled' );
     40                                                        pw_submitbtn_edit.attr( 'disabled','disabled' );
     41                                                }
     42                                                pw_weak.show();
     43                                        } else {
     44                                                pw_submitbtn_new.removeAttr( 'disabled' );
     45                                                pw_submitbtn_edit.removeAttr( 'disabled' );
     46                                                pw_weak.hide();
     47                                        }
     48                                }
     49                        }, 1 );
     50                } );
     51
     52                pw_checkbox.change( function() {
     53                        if ( pw_checkbox.attr( 'checked' ) ) {
     54                                pw_submitbtn_new.removeAttr( 'disabled' );
     55                                pw_submitbtn_edit.removeAttr( 'disabled' );
     56                        } else {
     57                                pw_submitbtn_new.attr( 'disabled','disabled' );
     58                                pw_submitbtn_edit.attr( 'disabled','disabled' );
     59                        }
     60                } );
     61
     62                /**
     63                 * Fix a LastPass mismatch issue, LastPass only changes pass2.
     64                 *
     65                 * This fixes the issue by copying any changes from the hidden
     66                 * pass2 field to the pass1 field.
     67                 */
     68                pw_field2.on( 'input propertychange', function() {
     69                        pw_field.val( pw_field2.val() );
     70                        pw_field.trigger( 'propertychange' );
     71                } );
     72
     73                pw_new.on( 'click', 'button.wp-generate-pw', function() {
     74                        pw_generatebtn.hide();
     75                        pw_line.show();
     76                        pw_field.val( pw_field.data( 'pw' ) ).attr( 'type', 'text' );
     77                        pw_field.trigger( 'propertychange' );
     78                        pw_field.focus();
     79                        pw_field[0].setSelectionRange(100, 100);
     80                });
     81
     82                pw_togglebtn.on( 'click', function() {
     83                        var show = pw_togglebtn.attr( 'data-toggle' );
     84                        if ( show == 1 ) {
     85                                pw_field.attr( 'type', 'text' );
     86                                pw_togglebtn.attr( 'data-toggle', 0 )
     87                                        .find( '.text' )
     88                                                .text( 'hide' )
     89                                ;
     90                        } else {
     91                                pw_field.attr( 'type', 'password' );
     92                                pw_togglebtn.attr( 'data-toggle', 1 )
     93                                        .find( '.text' )
     94                                                .text( 'show' )
     95                                ;
     96                        }
     97                        pw_field.focus();
     98                        pw_field[0].setSelectionRange(100, 100);
     99                });
     100        });
     101
    4102        function check_pass_strength() {
    5103                var pass1 = $('#pass1').val(), pass2 = $('#pass2').val(), strength;
    6104
  • src/wp-admin/user-edit.php

     
    462462        <th><label for="pass1"><?php _e( 'New Password' ); ?></label></th>
    463463        <td>
    464464                <input class="hidden" value=" " /><!-- #24364 workaround -->
    465                 <input type="password" name="pass1" id="pass1" class="regular-text" size="16" value="" autocomplete="off" />
    466                 <p class="description"><?php _e( 'If you would like to change the password type a new one. Otherwise leave this blank.' ); ?></p>
     465                <button type="button" class="button button-secondary wp-generate-pw hide-if-no-js"><?php _e( 'Generate new password' ); ?></button>
     466                <div class="wp-pwd hide-if-js">
     467                        <input type="password" name="pass1" id="pass1" class="regular-text" value="" autocomplete="off" data-pw="<?php echo esc_attr( wp_generate_password( 24 ) ); ?>" />
     468                        <button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0">
     469                                <span class="dashicons dashicons-visibility"></span>
     470                                <span class="text">hide</span>
     471                        </button>
     472                        <div style="display:none" id="pass-strength-result"></div>
     473                </div>
    467474        </td>
    468475</tr>
    469 <tr class="user-pass2-wrap">
     476<tr class="user-pass2-wrap hide-if-js">
    470477        <th scope="row"><label for="pass2"><?php _e( 'Repeat New Password' ); ?></label></th>
    471478        <td>
    472         <input name="pass2" type="password" id="pass2" class="regular-text" size="16" value="" autocomplete="off" />
     479        <input name="pass2" type="password" id="pass2" class="regular-text" value="" autocomplete="off" />
    473480        <p class="description"><?php _e( 'Type your new password again.' ); ?></p>
    474         <br />
    475         <div id="pass-strength-result"><?php _e( 'Strength indicator' ); ?></div>
    476         <p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p>
    477481        </td>
    478482</tr>
     483<tr class="pw-weak">
     484        <th><label for="pw-weak"><?php _e( 'Confirm Password' ); ?></label></th>
     485        <td>
     486        <input type="checkbox" name="pw-weak" class="pw-checkbox" />
     487        <?php _e( 'Confirm use of weak password.' ); ?>
     488        </td>
     489</tr>
    479490<?php endif; ?>
    480491
    481492<?php
    482 // This is a temporary hook for WordPress 4.3 development. Do not use it or document it.
    483 do_action( '__temp_password_field', $profileuser );
    484 ?>
    485 
    486 <?php
    487493if ( IS_PROFILE_PAGE && count( $sessions->get_all() ) === 1 ) : ?>
    488494        <tr class="user-sessions-wrap hide-if-no-js">
    489495                <th>&nbsp;</th>
  • src/wp-admin/user-new.php

     
    190190);
    191191
    192192wp_enqueue_script('wp-ajax-response');
    193 wp_enqueue_script('user-profile');
     193wp_enqueue_script( 'user-profile' );
    194194
    195195/**
    196196 * Filter whether to enable user auto-complete for non-super admins in Multisite.
     
    390390 * @param bool $show Whether to show the password fields. Default true.
    391391 */
    392392if ( apply_filters( 'show_password_fields', true ) ) : ?>
    393         <tr class="form-field form-required">
    394                 <th scope="row"><label for="pass1"><?php _e('Password'); ?> <span class="description"><?php /* translators: password input field */_e('(required)'); ?></span></label></th>
     393        <tr class="form-field form-required user-pass1-wrap">
     394                <th scope="row">
     395                        <label for="pass1">
     396                                <?php _e( 'Password' ); ?>
     397                                <span class="description"><?php /* translators: password input field */_e( '(required)' ); ?></span>
     398                        </label>
     399                </th>
    395400                <td>
    396401                        <input class="hidden" value=" " /><!-- #24364 workaround -->
    397                         <input name="pass1" type="password" id="pass1" autocomplete="off" />
     402                        <button type="button" class="button button-secondary wp-generate-pw hide-if-no-js"><?php _e( 'Show password' ); ?></button>
     403                        <div class="wp-pwd hide-if-js">
     404                                <?php $initial_password = wp_generate_password( 24 ); ?>
     405                                <input type="password" name="pass1" id="pass1" class="regular-text" value="<?php echo esc_attr( $initial_password ); ?>" autocomplete="off" data-pw="<?php echo esc_attr( $initial_password ); ?>" />
     406                                <button type="button" class="button button-secondary wp-hide-pw hide-if-no-js" data-toggle="0">
     407                                        <span class="dashicons dashicons-visibility"></span>
     408                                        <span class="text">hide</span>
     409                                </button>
     410                                <div style="display:none" id="pass-strength-result"></div>
     411                        </div>
    398412                </td>
    399413        </tr>
    400         <tr class="form-field form-required">
    401                 <th scope="row"><label for="pass2"><?php _e('Repeat Password'); ?> <span class="description"><?php /* translators: password input field */_e('(required)'); ?></span></label></th>
     414        <tr class="form-field form-required user-pass2-wrap hide-if-js">
     415                <th scope="row"><label for="pass2"><?php _e( 'Repeat Password' ); ?> <span class="description"><?php /* translators: password input field */_e('(required)'); ?></span></label></th>
    402416                <td>
    403417                <input name="pass2" type="password" id="pass2" autocomplete="off" />
    404                 <br />
    405                 <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div>
    406                 <p class="description indicator-hint"><?php echo wp_get_password_hint(); ?></p>
    407418                </td>
    408419        </tr>
     420        <tr class="pw-weak">
     421                <th><label for="pw-weak"><?php _e( 'Confirm Password' ); ?></label></th>
     422                <td>
     423                        <input type="checkbox" name="pw-weak" class="pw-checkbox" />
     424                        <?php _e( 'Confirm use of weak password.' ); ?>
     425                </td>
     426        </tr>
    409427        <tr>
    410                 <th scope="row"><?php _e('Send Password?') ?></th>
    411                 <td><label for="send_password"><input type="checkbox" name="send_password" id="send_password" value="1" <?php checked( $new_user_send_password ); ?> /> <?php _e('Send this password to the new user by email.'); ?></label></td>
    412         </tr>
     428                <th scope="row"><?php _e( 'Send Reset Link?' ) ?></th>
     429                <td><label for="send_password"><input type="checkbox" name="send_password" id="send_password" value="1" <?php checked( $new_user_send_password ); ?> /> <?php _e( 'Send a password reset link to the new user by email.' ); ?></label>
     430        </td>
    413431<?php endif; ?>
    414432<?php } // !is_multisite ?>
    415433        <tr class="form-field">
  • src/wp-includes/default-constants.php

     
    8080        if ( !defined('SHORTINIT') )
    8181                define('SHORTINIT', false);
    8282
     83        // Constants for features added to WP that should short-circuit their plugin implementations
     84        define( 'WP_FEATURE_BETTER_PASSWORDS', true );
     85
    8386        // Constants for expressing human-readable intervals
    8487        // in their respective number of seconds.
    8588        define( 'MINUTE_IN_SECONDS', 60 );
  • src/wp-includes/script-loader.php

     
    365365
    366366        $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array( 'jquery', 'zxcvbn-async' ), false, 1 );
    367367        did_action( 'init' ) && $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
    368                 'empty' => __('Strength indicator'),
     368                'empty' => __('&nbsp;'),
    369369                'short' => __('Very weak'),
    370370                'bad' => __('Weak'),
    371371                /* translators: password strength */