Ticket #5299: 5299.diff

File 5299.diff, 17.0 KB (added by mdawaffe, 5 years ago)
  • wp-includes/js/wp-lists.js

     
    1313                } 
    1414                return r; 
    1515        }, 
    16         parseAjaxResponse: function( x, r ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission 
     16        parseAjaxResponse: function( x, r, e ) { // 1 = good, 0 = strange (bad data?), -1 = you lack permission 
    1717                var re = $('#' + r).html(''); 
    1818                if ( x && typeof x == 'object' && x.getElementsByTagName('wp_ajax') ) { 
    19                         if ( $('wp_error', x).each( function() { re.append('<p>' + this.firstChild.nodeValue + '</p>'); } ).size() ) { 
    20                                 return !re.wrap( '<div class="error"></div>' ); 
     19                        var errs = $('wp_error', x); 
     20                        if ( errs.size() ) { 
     21                                var err = ''; 
     22                                errs.each( function() { 
     23                                        var code = $(this).attr('code'); 
     24                                        if ( formField = $('wp_error_data[@code="' + code + '"] form-field', x).text() ) 
     25                                                code = formField; 
     26                                        wpAjax.invalidateForm( $('#' + e + ' :input[@name="' + code + '"]' ).parents('.form-field:first') ); 
     27                                        err += '<p>' + this.firstChild.nodeValue + '</p>'; 
     28                                } ); 
     29                                return !re.html( '<div class="error">' + err + '</div>' ); 
    2130                        } 
    2231                        return true; 
    2332                } 
     
    2635                if ( -1 == x ) { return !re.html('<div class="error"><p>You do not have permission to do that.</p></div>'); } 
    2736                else if ( 0 === x ) { return !re.html('<div class="error"><p>AJAX is teh b0rked.</p></div>'); } 
    2837                return true; 
     38        }, 
     39        invalidateForm: function( jQ ) { 
     40                jQ.addClass( 'invalid' ).change( function() { $(this).removeClass( 'invalid' ); } ); 
    2941        } 
    3042}; 
    3143 
     
    91103                s.nonce = wpList.nonce(e,s); 
    92104 
    93105                var es = $('#' + s.element + ' :input').not('[@name=_ajax_nonce], [@name=_wpnonce], [@name=action]'); 
     106                var required = $('#' + s.element + ' .required:has(:input[@value=""]), #' + s.element + ' .required:input[@value=""]'); 
     107                if ( required.size() ) { 
     108                        wpAjax.invalidateForm( required ); 
     109                        return false; 
     110                } 
     111 
    94112                s.data = $.param( $.extend( { _ajax_nonce: s.nonce, action: s.action }, wpAjax.unserialize( cls[4] || '' ) ) ); 
    95113                var formData = $.isFunction(es.fieldSerialize) ? es.fieldSerialize() : es.serialize(); 
    96114                if ( formData ) { s.data += '&' + formData; } 
     
    102120                if ( !s.data.match(/_ajax_nonce=[a-f0-9]+/) ) { return true; } 
    103121 
    104122                s.success = function(r) { 
    105                         if ( !wpAjax.parseAjaxResponse(r, s.response) ) { return false; } 
     123                        if ( !wpAjax.parseAjaxResponse(r, s.response, s.element) ) { return false; } 
    106124 
    107125                        $(s.what + ' response_data', r).each( function() { 
    108126                                var t = $(this); 
     
    164182                } 
    165183 
    166184                s.success = function(r) { 
    167                         if ( !wpAjax.parseAjaxResponse(r, s.response) ) { 
     185                        if ( !wpAjax.parseAjaxResponse(r, s.response, s.element) ) { 
    168186                                clearTimeout(hideTO); 
    169187                                func = function() { $('#' + s.element).css( 'background-color', '#FF3333' ).show(); list.wpList.recolor(); }; 
    170188                                func(); setTimeout(func, 705); // In case it's still fading 
     
    218236                var dimTO = setTimeout( function() { $('#' + s.element).css( 'background-color', '' ); }, 705 ); 
    219237 
    220238                s.success = function(r) { 
    221                         if ( !wpAjax.parseAjaxResponse(r, s.response) ) { 
     239                        if ( !wpAjax.parseAjaxResponse(r, s.response, s.element) ) { 
    222240                                clearTimeout(dimTO); 
    223241                                func = function() { $('#' + s.element).css( 'background-color', '#FF3333' )[isClass?'removeClass':'addClass'](s.dimClass); }; 
    224242                                func(); setTimeout(func, 705); 
  • wp-includes/classes.php

     
    710710                } 
    711711 
    712712                $response = ''; 
    713                 if ( is_wp_error($data) ) 
    714                         foreach ( $data->get_error_codes() as $code ) 
     713                if ( is_wp_error($data) ) { 
     714                        foreach ( $data->get_error_codes() as $code ) {  
    715715                                $response .= "<wp_error code='$code'><![CDATA[" . $data->get_error_message($code) . "]]></wp_error>"; 
    716                 else 
     716                                if ( !$error_data = $data->get_error_data($code) ) 
     717                                        continue; 
     718                                $class = ''; 
     719                                if ( is_object($error_data) ) { 
     720                                        $class = ' class="' . get_class($error_data) . '"'; 
     721                                        $error_data = get_object_vars($error_data); 
     722                                } 
     723 
     724                                $response .= "<wp_error_data code='$code'$class>"; 
     725 
     726                                if ( is_scalar($error_data) ) { 
     727                                        $response .= "<![CDATA[$v]]>"; 
     728                                } elseif ( is_array($error_data) ) { 
     729                                        foreach ( $error_data as $k => $v ) 
     730                                                $response .= "<$k><![CDATA[$v]]></$k>"; 
     731                                } 
     732 
     733                                $response .= "</wp_error_data>"; 
     734                        } 
     735                } else { 
    717736                        $response = "<response_data><![CDATA[$data]]></response_data>"; 
     737                } 
    718738 
    719739                $s = ''; 
    720740                if ( (array) $supplemental ) 
  • wp-includes/script-loader.php

     
    6161                        'delText' => __('Are you sure you want to delete this %thing%?') 
    6262                ) ); 
    6363 
    64                 $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('jquery'), '20071023' ); 
     64                $this->add( 'wp-lists', '/wp-includes/js/wp-lists.js', array('jquery'), '20071101' ); 
    6565                $this->localize( 'wp-lists', 'wpListL10n', array( 
    6666                        'url' => get_option( 'siteurl' ) . '/wp-admin/admin-ajax.php' 
    6767                ) ); 
     
    110110                                        'toggleKey' => __(', or press the enter key to %toggle% it'), 
    111111                                ) ); 
    112112                        } 
    113                         $this->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20070823' ); 
     113                        $this->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' ); 
    114114                        $this->localize( 'ajaxcat', 'catL10n', array( 
    115115                                'add' => attribute_escape(__('Add')), 
    116116                                'how' => __('Separate multiple categories with commas.') 
  • wp-admin/users.php

     
    454454        if ( get_option('users_can_register') ) 
    455455                echo '<p>' . sprintf(__('Users can <a href="%1$s">register themselves</a> or you can manually create users here.'), get_option('siteurl').'/wp-register.php') . '</p>'; 
    456456        else 
    457         echo '<p>' . sprintf(__('Users cannot currently <a href="%1$s">register themselves</a>, but you can manually create users here.'), get_option('siteurl').'/wp-admin/options-general.php#users_can_register') . '</p>'; 
     457                echo '<p>' . sprintf(__('Users cannot currently <a href="%1$s">register themselves</a>, but you can manually create users here.'), get_option('siteurl').'/wp-admin/options-general.php#users_can_register') . '</p>'; 
    458458?> 
    459459<form action="#add-new-user" method="post" name="adduser" id="adduser" class="add:user-list:"> 
    460460<?php wp_nonce_field('add-user') ?> 
    461461<table class="editform" width="100%" cellspacing="2" cellpadding="5"> 
    462         <tr> 
     462        <tr class="form-field required"> 
    463463                <th scope="row" width="33%"><?php _e('Username (required)') ?><input name="action" type="hidden" id="action" value="adduser" /></th> 
    464464                <td width="66%"><input name="user_login" type="text" id="user_login" value="<?php echo $new_user_login; ?>" /></td> 
    465465        </tr> 
    466         <tr> 
     466        <tr class="form-field"> 
    467467                <th scope="row"><?php _e('First Name') ?> </th> 
    468468                <td><input name="first_name" type="text" id="first_name" value="<?php echo $new_user_firstname; ?>" /></td> 
    469469        </tr> 
    470         <tr> 
     470        <tr class="form-field"> 
    471471                <th scope="row"><?php _e('Last Name') ?> </th> 
    472472                <td><input name="last_name" type="text" id="last_name" value="<?php echo $new_user_lastname; ?>" /></td> 
    473473        </tr> 
    474         <tr> 
     474        <tr class="form-field required"> 
    475475                <th scope="row"><?php _e('E-mail (required)') ?></th> 
    476476                <td><input name="email" type="text" id="email" value="<?php echo $new_user_email; ?>" /></td> 
    477477        </tr> 
    478         <tr> 
     478        <tr class="form-field"> 
    479479                <th scope="row"><?php _e('Website') ?></th> 
    480480                <td><input name="url" type="text" id="url" value="<?php echo $new_user_uri; ?>" /></td> 
    481481        </tr> 
    482482 
    483483<?php if ( apply_filters('show_password_fields', true) ) : ?> 
    484         <tr> 
     484        <tr class="form-field required"> 
    485485                <th scope="row"><?php _e('Password (twice)') ?> </th> 
    486486                <td><input name="pass1" type="password" id="pass1" /> 
    487487                <br /> 
     
    489489        </tr> 
    490490<?php endif; ?> 
    491491 
    492         <tr> 
     492        <tr class="form-field"> 
    493493                <th scope="row"><?php _e('Role'); ?></th> 
    494494                <td><select name="role" id="role"> 
    495495                        <?php 
  • wp-admin/admin-ajax.php

     
    147147        $x = new WP_Ajax_Response(); 
    148148        foreach ( $names as $cat_name ) { 
    149149                $cat_name = trim($cat_name); 
    150                 if ( !$category_nicename = sanitize_title($cat_name) ) 
    151                         die('0'); 
    152                 if ( !$cat_id = category_exists( $cat_name ) ) 
    153                         $cat_id = wp_create_category( $cat_name ); 
     150                $category_nicename = sanitize_title($cat_name) 
     151                        continue; 
     152                $cat_id = wp_create_category( $cat_name ); 
    154153                $cat_name = wp_specialchars(stripslashes($cat_name)); 
    155154                $x->add( array( 
    156155                        'what' => 'category', 
     
    189188        check_ajax_referer( 'add-category' ); 
    190189        if ( !current_user_can( 'manage_categories' ) ) 
    191190                die('-1'); 
     191 
     192        if ( '' === trim($_POST['cat_name']) ) { 
     193                $x = new WP_Ajax_Response( array( 
     194                        'what' => 'cat', 
     195                        'id' => new WP_Error( 'cat_name', __('You did not enter a category name.') ) 
     196                ) ); 
     197                $x->send(); 
     198        } 
     199 
    192200        if ( !$cat = wp_insert_category( $_POST ) ) 
    193201                die('0'); 
    194202        if ( !$cat = get_category( $cat ) ) 
     
    216224        if ( !current_user_can( 'manage_categories' ) ) 
    217225                die('-1'); 
    218226 
     227        if ( '' === trim($_POST['name']) ) { 
     228                $x = new WP_Ajax_Response( array( 
     229                        'what' => 'link-cat', 
     230                        'id' => new WP_Error( 'name', __('You did not enter a category name.') ) 
     231                ) ); 
     232                $x->send(); 
     233        } 
     234 
    219235        $r = wp_insert_term($_POST['name'], 'link_category', $_POST ); 
    220236        if ( is_wp_error( $r ) ) { 
    221237                $x = new WP_AJAX_Response( array( 
     
    270286        if ( isset($_POST['addmeta']) ) { 
    271287                if ( !current_user_can( 'edit_post', $pid ) ) 
    272288                        die('-1'); 
     289                if ( '#NONE#' == $_POST['metakeyselect'] && empty($_POST['metakeyinput']) ) 
     290                        die('1'); 
    273291                if ( $pid < 0 ) { 
    274292                        $now = current_time('timestamp', 1); 
    275293                        if ( $pid = wp_insert_post( array( 
     
    334352        if ( !$user_id = add_user() ) 
    335353                die('0'); 
    336354        elseif ( is_wp_error( $user_id ) ) { 
    337                 foreach( $user_id->get_error_messages() as $message ) 
    338                         echo "<p>$message<p>"; 
    339                 exit; 
     355                $x = new WP_Ajax_Response( array( 
     356                        'what' => 'user', 
     357                        'id' => $user_id 
     358                ) ); 
     359                $x->send(); 
    340360        } 
    341361        $user_object = new WP_User( $user_id ); 
    342362 
  • wp-admin/wp-admin.css

     
    184184        border: 1px solid #686868; 
    185185} 
    186186 
     187.invalid { 
     188        background-color: #FF9999 !important; 
     189} 
     190 
    187191label { 
    188192        cursor: pointer; 
    189193} 
  • wp-admin/includes/user.php

     
    8282        /* checking the password has been typed twice */ 
    8383        do_action_ref_array( 'check_passwords', array ( $user->user_login, & $pass1, & $pass2 )); 
    8484 
    85         if (!$update ) { 
    86                 if ( $pass1 == '' || $pass2 == '' ) 
    87                         $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' )); 
     85        if ( $update ) { 
     86                if ( empty($pass1) && !empty($pass2) ) 
     87                        $errors->add( 'pass', __( '<strong>ERROR</strong>: You entered your new password only once.' ), array( 'form-field' => 'pass1' ) ); 
     88                elseif ( !empty($pass1) && empty($pass2) ) 
     89                        $errors->add( 'pass', __( '<strong>ERROR</strong>: You entered your new password only once.' ), array( 'form-field' => 'pass2' ) ); 
    8890        } else { 
    89                 if ((empty ( $pass1 ) && !empty ( $pass2 ) ) || (empty ( $pass2 ) && !empty ( $pass1 ) ) ) 
    90                         $errors->add( 'pass', __( '<strong>ERROR</strong>: You entered your new password only once.' )); 
     91                if ( empty($pass1) ) 
     92                        $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password.' ), array( 'form-field' => 'pass1' ) ); 
     93                elseif ( empty($pass2) ) 
     94                        $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter your password twice.' ), array( 'form-field' => 'pass2' ) ); 
    9195        } 
    9296 
    9397        /* Check for "\" in password */ 
    9498        if( strpos( " ".$pass1, "\\" ) ) 
    95                 $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' )); 
     99                $errors->add( 'pass', __( '<strong>ERROR</strong>: Passwords may not contain the character "\\".' ), array( 'form-field' => 'pass1' ) ); 
    96100 
    97101        /* checking the password has been typed twice the same */ 
    98102        if ( $pass1 != $pass2 ) 
    99                 $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter the same password in the two password fields.' )); 
     103                $errors->add( 'pass', __( '<strong>ERROR</strong>: Please enter the same password in the two password fields.' ), array( 'form-field' => 'pass1' ) ); 
    100104 
    101105        if (!empty ( $pass1 )) 
    102106                $user->user_pass = $pass1; 
     
    109113 
    110114        /* checking e-mail address */ 
    111115        if ( empty ( $user->user_email ) ) { 
    112                 $errors->add( 'user_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' )); 
     116                $errors->add( 'user_email', __( '<strong>ERROR</strong>: Please enter an e-mail address.' ), array( 'form-field' => 'email' ) ); 
    113117        } else 
    114118                if (!is_email( $user->user_email ) ) { 
    115                         $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address isn't correct." )); 
     119                        $errors->add( 'user_email', __( "<strong>ERROR</strong>: The e-mail address isn't correct." ), array( 'form-field' => 'email' ) ); 
    116120                } 
    117121 
    118122        if ( $errors->get_error_codes() ) 
  • wp-admin/js/cat.js

     
    11jQuery( function($) { 
     2        var myConfirm = function() { return '' !== $('#newcat').val(); }; 
    23        $('#jaxcat').prepend('<span id="ajaxcat"><input type="text" name="newcat" id="newcat" size="16" autocomplete="off"/><input type="button" name="Button" class="add:categorychecklist:jaxcat" id="catadd" value="' + catL10n.add + '"/><input type="hidden"/><input type="hidden"/><span id="howto">' + catL10n.how + '</span></span><span id="cat-ajax-response"></span>') 
    3         var a = $('#categorychecklist').wpList( { alt: '', response: 'cat-ajax-response' } ); 
     4        $('#categorychecklist').wpList( { alt: '', response: 'cat-ajax-response', confirm: myConfirm } ); 
    45} ); 
  • wp-admin/edit-link-category-form.php

     
    2424<input type="hidden" name="cat_ID" value="<?php echo $category->term_id ?>" /> 
    2525<?php wp_nonce_field($nonce_action); ?> 
    2626        <table class="editform" width="100%" cellspacing="2" cellpadding="5"> 
    27                 <tr> 
     27                <tr class="form-field required"> 
    2828                        <th width="33%" scope="row" valign="top"><label for="name"><?php _e('Category name:') ?></label></th> 
    2929                        <td width="67%"><input name="name" id="name" type="text" value="<?php echo $category->name; ?>" size="40" /></td> 
    3030                </tr> 
    31                 <tr> 
     31                <tr class="form-field"> 
    3232                        <th scope="row" valign="top"><label for="slug"><?php _e('Category slug:') ?></label></th> 
    3333                        <td><input name="slug" id="slug" type="text" value="<?php echo $category->slug; ?>" size="40" /></td> 
    3434                </tr> 
    35                 <tr> 
     35                <tr class="form-field"> 
    3636                        <th scope="row" valign="top"><label for="description"><?php _e('Description: (optional)') ?></label></th> 
    3737                        <td><textarea name="description" id="description" rows="5" cols="50" style="width: 97%;"><?php echo $category->description; ?></textarea></td> 
    3838                </tr> 
  • wp-admin/edit-category-form.php

     
    2424<input type="hidden" name="cat_ID" value="<?php echo $category->term_id ?>" /> 
    2525<?php wp_nonce_field($nonce_action); ?> 
    2626        <table class="editform" width="100%" cellspacing="2" cellpadding="5"> 
    27                 <tr> 
     27                <tr class="form-field required"> 
    2828                        <th width="33%" scope="row" valign="top"><label for="cat_name"><?php _e('Category name:') ?></label></th> 
    2929                        <td width="67%"><input name="cat_name" id="cat_name" type="text" value="<?php echo attribute_escape($category->name); ?>" size="40" /></td> 
    3030                </tr> 
    31                 <tr> 
     31                <tr class="form-field"> 
    3232                        <th scope="row" valign="top"><label for="category_nicename"><?php _e('Category slug:') ?></label></th> 
    3333                        <td><input name="category_nicename" id="category_nicename" type="text" value="<?php echo attribute_escape($category->slug); ?>" size="40" /></td> 
    3434                </tr> 
    35                 <tr> 
     35                <tr class="form-field"> 
    3636                        <th scope="row" valign="top"><label for="category_parent"><?php _e('Category parent:') ?></label></th> 
    3737                        <td> 
    3838                                <?php wp_dropdown_categories('hide_empty=0&name=category_parent&orderby=name&selected=' . $category->parent . '&hierarchical=1&show_option_none=' . __('None')); ?> 
    3939                        </td> 
    4040                </tr> 
    41                 <tr> 
     41                <tr class="form-field"> 
    4242                        <th scope="row" valign="top"><label for="category_description"><?php _e('Description: (optional)') ?></label></th> 
    4343                        <td><textarea name="category_description" id="category_description" rows="5" cols="50" style="width: 97%;"><?php echo wp_specialchars($category->description); ?></textarea></td> 
    4444                </tr>