WordPress.org

Make WordPress Core


Ignore:
Timestamp:
04/02/06 00:31:26 (12 years ago)
Author:
ryan
Message:

AJAXify user addition. Props mdawaffe. fixes #2624

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/users.php

    r3541 r3677  
    8080 
    8181    if ( !current_user_can('edit_users') ) 
    82         $error['edit_users'] = __('You can’t delete users.'); 
     82        $error = new WP_Error('edit_users', __('You can’t delete users.')); 
    8383 
    8484    $userids = $_POST['users']; 
     
    134134    check_admin_referer(); 
    135135 
    136     $errors = add_user(); 
    137  
    138     if(count($errors) == 0) { 
     136    $user_id = add_user(); 
     137    if ( is_wp_error( $user_id ) ) 
     138        $errors = $user_id; 
     139    else { 
    139140        header('Location: users.php?update=add'); 
    140141        die(); 
     
    142143 
    143144default: 
     145 
     146    $list_js = true; 
     147    $users_js = true; 
    144148 
    145149    include ('admin-header.php'); 
     
    188192        } 
    189193    endif;  
    190     if ( isset($errors) ) : ?> 
     194    if ( is_wp_error( $errors ) ) : ?> 
    191195    <div class="error"> 
    192196        <ul> 
    193197        <?php 
    194         foreach($errors as $error) echo "<li>$error</li>"; 
     198        foreach( $errors->get_error_codes() as $code) 
     199            foreach( $errors->get_error_messages($code) as $message ) 
     200                 echo "<li>$message</li>"; 
    195201        ?> 
    196202        </ul> 
     
    210216 
    211217    <tr> 
    212     <th colspan="8" align="left"> 
    213   <h3><?php echo $wp_roles->role_names[$role]; ?></h3> 
    214   </th></tr> 
    215  
     218        <th colspan="8" align="left"><h3><?php echo $wp_roles->role_names[$role]; ?></h3></th> 
     219    </tr> 
    216220    <tr> 
    217     <th><?php _e('ID') ?></th> 
    218     <th><?php _e('Username') ?></th> 
    219     <th><?php _e('Name') ?></th> 
    220     <th><?php _e('E-mail') ?></th> 
    221     <th><?php _e('Website') ?></th> 
    222     <th><?php _e('Posts') ?></th> 
    223     <th>&nbsp;</th> 
     221        <th><?php _e('ID') ?></th> 
     222        <th><?php _e('Username') ?></th> 
     223        <th><?php _e('Name') ?></th> 
     224        <th><?php _e('E-mail') ?></th> 
     225        <th><?php _e('Website') ?></th> 
     226        <th><?php _e('Posts') ?></th> 
     227        <th>&nbsp;</th> 
    224228    </tr> 
    225     <?php 
     229    <tbody id="role-<?php echo $role; ?>"><?php 
    226230    $style = ''; 
    227231    foreach ($roleclass as $user_object) { 
    228         $email = $user_object->user_email; 
    229         $url = $user_object->user_url; 
    230         $short_url = str_replace('http://', '', $url); 
    231         $short_url = str_replace('www.', '', $short_url); 
    232         if ('/' == substr($short_url, -1)) 
    233             $short_url = substr($short_url, 0, -1); 
    234         if (strlen($short_url) > 35) 
    235         $short_url =  substr($short_url, 0, 32).'...'; 
    236         $style = ('class="alternate"' == $style) ? '' : 'class="alternate"'; 
    237         $numposts = get_usernumposts($user_object->ID); 
    238         if (0 < $numposts) $numposts = "<a href='edit.php?author=$user_object->ID' title='" . __('View posts') . "'>$numposts</a>"; 
    239         echo " 
    240 <tr $style> 
    241     <td><input type='checkbox' name='users[]' id='user_{$user_object->ID}' value='{$user_object->ID}' /> <label for='user_{$user_object->ID}'>{$user_object->ID}</label></td> 
    242     <td><label for='user_{$user_object->ID}'><strong>$user_object->user_login</strong></label></td> 
    243     <td><label for='user_{$user_object->ID}'>$user_object->first_name $user_object->last_name</label></td> 
    244     <td><a href='mailto:$email' title='" . sprintf(__('e-mail: %s'), $email) . "'>$email</a></td> 
    245     <td><a href='$url' title='website: $url'>$short_url</a></td>"; 
    246     echo "<td align='right'>$numposts</td>"; 
    247     echo '<td>'; 
    248     if (current_user_can('edit_users')) 
    249         echo "<a href='user-edit.php?user_id=$user_object->ID' class='edit'>".__('Edit')."</a>"; 
    250     echo '</td>'; 
    251     echo '</tr>'; 
     232        $style = (' class="alternate"' == $style) ? '' : ' class="alternate"'; 
     233        echo "\n\t" . user_row( $user_object, $style ); 
    252234    } 
    253235 
    254236    ?> 
    255237 
    256  
     238    </tbody> 
    257239<?php 
    258240    } 
     
    262244 
    263245    <h2><?php _e('Update Users'); ?></h2> 
    264 <?php 
    265 $role_select = '<select name="new_role">'; 
    266 foreach($wp_roles->role_names as $role => $name) { 
    267     $role_select .= "<option value=\"{$role}\">{$name}</option>"; 
    268 } 
    269 $role_select .= '</select>'; 
    270 ?>   
    271246  <ul style="list-style:none;"> 
    272247    <li><input type="radio" name="action" id="action0" value="delete" /> <label for="action0"><?php _e('Delete checked users.'); ?></label></li> 
    273     <li><input type="radio" name="action" id="action1" value="promote" /> <?php echo '<label for="action1">'.__('Set the Role of checked users to:')."</label> $role_select"; ?></li> 
     248    <li> 
     249        <input type="radio" name="action" id="action1" value="promote" /> <label for="action1"><?php _e('Set the Role of checked users to:'); ?></label> 
     250        <select name="new_role"><?php wp_dropdown_roles(); ?></select> 
     251    </li> 
    274252  </ul> 
    275253    <p class="submit"><input type="submit" value="<?php _e('Update &raquo;'); ?>" /></p> 
     
    314292    </tr> 
    315293<?php endif; ?> 
     294    <tr> 
     295      <th scope="row"><?php _e('Role'); ?></th> 
     296      <td><select name="role" id="role"><?php wp_dropdown_roles( get_settings('default_role') ); ?></select></td> 
     297    </tr> 
    316298  </table> 
    317299  <p class="submit"> 
    318     <input name="adduser" type="submit" id="adduser" value="<?php _e('Add User &raquo;') ?>" /> 
     300    <input name="adduser" type="submit" id="addusersub" value="<?php _e('Add User &raquo;') ?>" /> 
    319301  </p> 
    320302  </form> 
     303<div id="ajax-response"></div> 
    321304</div> 
    322305    <?php 
Note: See TracChangeset for help on using the changeset viewer.