Ticket #3159: 3159.diff

File 3159.diff, 4.4 KB (added by mdawaffe, 6 years ago)
  • wp-includes/general-template.php

     
    849849        echo wp_specialchars( stripslashes($s), 1 ); 
    850850} 
    851851 
     852function paginate_links( $arg = '' ) { 
     853        if ( is_array($arg) ) 
     854                $a = &$arg; 
     855        else 
     856                parse_str($arg, $a); 
     857 
     858        // Defaults 
     859        $base = '%_%'; // http://example.com/all_posts.php%_% : %_% is replaced by format (below) 
     860        $format = '?page=%#%'; // ?page=%#% : %#% is replaced by the page number 
     861        $total = 1; 
     862        $current = 0; 
     863        $show_all = false; 
     864        $prev_next = true; 
     865        $prev_text = __('« Previous'); 
     866        $next_text = __('Next »'); 
     867        $end_size = 1; // How many numbers on either end including the end 
     868        $mid_size = 2; // How many numbers to either side of current not including current 
     869        $type = 'plain'; 
     870        $add_args = false; // array of query args to aadd 
     871 
     872        extract($a); 
     873 
     874        // Who knows what else people pass in $args 
     875        $total    = (int) $total; 
     876        $current  = (int) $current; 
     877        $end_size = 0  < (int) $end_size ? (int) $end_size : 1; // Out of bounds?  Make it the default. 
     878        $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2; 
     879        $add_args = is_array($add_args) ? $add_args : false; 
     880        $r = ''; 
     881        $page_links = array(); 
     882        $n = 0; 
     883        $dots = false; 
     884 
     885        if ( $prev_next && $current && 1 < $current ) : 
     886                $link = str_replace('%_%', 2 == $current ? '' : str_replace('%#%', $current - 1, $format), $base); 
     887                if ( $add_args ) 
     888                        $link = add_query_arg( $add_args, $link ); 
     889                $page_links[] = "<a class='prev page-numbers' href='" . wp_specialchars( $link, 1 ) . "'>$prev_text</a>"; 
     890        endif; 
     891        for ( $n = 1; $n <= $total; $n++ ) : 
     892                if ( $n == $current ) : 
     893                        $page_links[] = "<span class='page-numbers current'>$n</span>"; 
     894                        $dots = true; 
     895                else : 
     896                        if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : 
     897                                $link = str_replace('%_%', 1 == $n ? '' : str_replace('%#%', $n, $format), $base); 
     898                                if ( $add_args ) 
     899                                        $link = add_query_arg( $add_args, $link ); 
     900                                $page_links[] = "<a class='page-numbers' href='" . wp_specialchars( $link, 1 ) . "'>$n</a>"; 
     901                                $dots = true; 
     902                        elseif ( $dots && !$show_all ) : 
     903                                $page_links[] = "<span class='page-numbers dots'>...</span>"; 
     904                                $dots = false; 
     905                        endif; 
     906                endif; 
     907        endfor; 
     908        if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) : 
     909                $link = str_replace('%_%', str_replace('%#%', $current + 1, $format), $base); 
     910                if ( $add_args ) 
     911                        $link = add_query_arg( $add_args, $link ); 
     912                $page_links[] = "<a class='next page-numbers' href='" . wp_specialchars( $link, 1 ) . "'>$next_text</a>"; 
     913        endif; 
     914        switch ( $type ) : 
     915                case 'array' : 
     916                        return $page_links; 
     917                        break; 
     918                case 'list' : 
     919                        $r .= "<ul class='page-numbers'>\n\t<li>"; 
     920                        $r .= join("</li>\n\t<li>", $page_links); 
     921                        $r .= "</li>\n</ul>\n"; 
     922                        break; 
     923                default : 
     924                        $r = join("\n", $page_links); 
     925                        break; 
     926        endswitch; 
     927        return $r; 
     928} 
     929 
    852930?> 
  • wp-admin/users.php

     
    8484 
    8585        function do_paging() { 
    8686                if ( $this->total_users_for_query > $this->users_per_page ) { // have to page the results 
    87                         $prev_page = ( $this->page > 1) ? true : false; 
    88                         $next_page = ( ($this->page * $this->users_per_page) < $this->total_users_for_query ) ? true : false; 
    89                         $this->paging_text = ''; 
    90                         if ( $prev_page ) 
    91                                 $this->paging_text .= '<p class="alignleft"><a href="' . add_query_arg(array('usersearch' => $this->search_term, 'userspage' => $this->page - 1), 'users.php?') . '">&laquo; Previous Page</a></p>'; 
    92                         if ( $next_page ) 
    93                                 $this->paging_text .= '<p class="alignright"><a href="' . add_query_arg(array('usersearch' => $this->search_term, 'userspage' => $this->page + 1), 'users.php?') . '">Next Page &raquo;</a></p>'; 
    94                         if ( $prev_page || $next_page ) 
    95                                 $this->paging_text .= '<br style="clear:both" />'; 
     87                        $this->paging_text = paginate_links( array( 
     88                                'total' => ceil($this->total_users_for_query / $this->users_per_page), 
     89                                'current' => $this->page, 
     90                                'prev_text' => '&laquo; Previous Page', 
     91                                'next_text' => 'Next Page &raquo;', 
     92                                'base' => 'users.php?%_%', 
     93                                'format' => 'userspage=%#%', 
     94                                'add_args' => array( 'usersearch' => urlencode($this->search_term) ) 
     95                        ) ); 
    9696                } 
    9797        } 
    9898