WordPress.org

Make WordPress Core

Ticket #2793: users_paging_search_bugfixes_2.0.4.diff

File users_paging_search_bugfixes_2.0.4.diff, 4.3 KB (added by markjaquith, 12 years ago)

The original patch for Branches/2.0, with changed offset for 2.0.4, just for people who are still on 2.0.4 and could benefit from it

  • wp-admin/users.php

     
    143143default:
    144144       
    145145        include ('admin-header.php');
    146        
    147         $userids = $wpdb->get_col("SELECT ID FROM $wpdb->users;");
    148        
    149         foreach($userids as $userid) {
     146
     147        //
     148        // Paging and Search by Mark Jaquith, June 6th, 2006
     149        //
     150
     151        $users_per_page = 50;
     152
     153        $page = (int) $_GET['userspage'];
     154        if ( !$page )
     155                $page = 1;
     156
     157        $starton = ($page - 1) * $users_per_page;
     158
     159        $limit = 'LIMIT ' . $starton . ',' .  $users_per_page;
     160
     161        $search_term = $_GET['usersearch'];
     162        if ( $search_term ) {
     163                $search = array();
     164                $search_sql = 'AND (';
     165                foreach ( array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') as $col )
     166                        $searches[] = $col . " LIKE '%$search_term%'";
     167                $search_sql .= implode(' OR ', $searches);
     168                $search_sql .= ')';
     169        }
     170
     171        if ( !$search_term && $page == 1 && $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users") > $users_per_page )
     172                $too_many_users = sprintf(__('Because this blog has more than %s users, they cannot all be shown on one page.  Use the paging or search functionality in order to find the user you want to edit.'), $users_per_page);
     173
     174        $from_where = "FROM $wpdb->users WHERE 1=1 $search_sql";
     175        $userids = $wpdb->get_col('SELECT ID ' . $from_where . $limit);
     176
     177        if ( $userids ) {
     178                $total_users_for_this_query = $wpdb->get_var('SELECT COUNT(ID) ' . $from_where); // no limit
     179        } else {
     180                $errors[] = __('No matching users were found!');
     181        }
     182
     183        // Now for the paging
     184        if ( $total_users_for_this_query > $users_per_page ) { // have to page the results
     185                $prev_page = ( $page > 1) ? true : false;
     186                $next_page = ( ($page * $users_per_page) < $total_users_for_this_query ) ? true : false;
     187                $paging_text = '';
     188                if ( $prev_page )
     189                        $paging_text .= '<p class="alignleft"><a href="' . add_query_arg('userspage', $page - 1) . '">&laquo; Previous Page</a></p>';
     190                if ( $next_page )
     191                        $paging_text .= '<p class="alignright"><a href="' . add_query_arg('userspage', $page + 1) . '">Next Page &raquo;</a></p>';
     192                if ( $prev_page || $next_page )
     193                        $paging_text .= '<br style="clear:both" />';
     194        }
     195
     196        // DONE WITH PAGING AND SEARCH
     197
     198        foreach( (array) $userids as $userid) {
    150199                $tmp_user = new WP_User($userid);
    151200                $roles = $tmp_user->roles;
    152201                $role = array_shift($roles);
     
    199248        endif;
    200249        ?>
    201250       
     251
     252<div class="wrap">
     253        <h2><?php _e('Search For Users'); ?></h2>
     254<form action="" method="get" name="search" id="search">
     255        <p><input type="text" name="usersearch" id="usersearch" value="<?php echo wp_specialchars($_GET['usersearch']); ?>" /> <input type="submit" value="Search &raquo;" /></p>
     256</form>
     257</div>
     258
     259<?php if ( $too_many_users ) : ?>
     260<div id="message" class="updated">
     261        <p><?php echo $too_many_users; ?></p>
     262</div>
     263<?php endif; ?>
     264
     265<?php if ( $userids ) : ?>
     266
    202267<form action="" method="post" name="updateusers" id="updateusers">
    203268<?php wp_nonce_field('bulk-users') ?>
     269
    204270<div class="wrap">
    205         <h2><?php _e('User List by Role'); ?></h2>
    206   <table cellpadding="3" cellspacing="3" width="100%">
     271        <?php if ( $search_term ) : ?>
     272                <h2><?php printf(__('Users Matching "%s" by Role'), $search_term); ?></h2>
     273                <h3><?php printf(__('Results %s - %s of %s shown below'), $starton + 1, min($starton + $users_per_page, $total_users_for_this_query), $total_users_for_this_query); ?></h3>
     274                <div class="user-paging-text"><?php echo $paging_text; ?></div>
     275        <?php else : ?>
     276                <h2><?php _e('User List by Role'); ?></h2>
     277                <?php if ( $paging_text ) : ?>
     278                        <div class="user-paging-text"><?php echo $paging_text; ?></p></div>
     279                <?php endif; ?>
     280        <?php endif; ?>
     281<table cellpadding="3" cellspacing="3" width="100%">
    207282        <?php
    208         foreach($roleclasses as $role => $roleclass) {
     283        foreach( (array) $roleclasses as $role => $roleclass) {
    209284                ksort($roleclass);
    210285                ?>
    211286
     
    260335?>
    261336  </table>
    262337
     338<div class="user-paging-text"><?php echo $paging_text; ?></div>
    263339
    264340        <h2><?php _e('Update Users'); ?></h2>
    265341<?php
     
    277353</div>
    278354</form>
    279355
     356<?php endif; // if users were returned ?>
     357
    280358<div class="wrap">
    281359<h2><?php _e('Add New User') ?></h2>
    282360<?php echo '<p>'.sprintf(__('Users can <a href="%1$s">register themselves</a> or you can manually create users here.'), get_settings('siteurl').'/wp-register.php').'</p>'; ?>