WordPress.org

Make WordPress Core

Opened 12 months ago

Last modified 3 weeks ago

#46346 new defect (bug)

WP_List_Table calculates total_pages as a float

Reported by: lev0 Owned by:
Milestone: Awaiting Review Priority: normal
Severity: minor Version:
Component: Administration Keywords: has-patch
Focuses: Cc:

Description

Should be an int, not calculated using rounding, preventing off-by-one errors.

Attachments (1)

wp-list-table-integer-total-pages.patch (705 bytes) - added by lev0 12 months ago.

Download all attachments as: .zip

Change History (4)

#1 @lev0
4 months ago

  • Focuses coding-standards added
  • Version set to trunk

Hello?

#2 @knutsp
4 months ago

  • Focuses coding-standards removed
  • Keywords has-patch added
  • Version trunk deleted

#3 @lev0
3 weeks ago

How about this updated, less "magic" version?

  • wp-admin/includes/class-wp-list-table.php

    a b  
    284284               );
    285285
    286286               if ( ! $args['total_pages'] && $args['per_page'] > 0 ) {
    287                        $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
     287                       $remainder = $args['total_items'] % $args['per_page'];
     288                       if ( $remainder ) {
     289                               $args['total_pages'] = 1 + ( $args['total_items'] - $remainder ) / $args['per_page'];
     290                       } else {
     291                               $args['total_pages'] = $args['total_items'] / $args['per_page'];
     292                       }
    288293               }
    289294
    290295               // Redirect if page number is invalid and headers are not already sent.
Note: See TracTickets for help on using tickets.