Make WordPress Core

Opened 5 years ago

Closed 5 years ago

#38421 closed defect (bug) (fixed)

Remove impossible check for `-1 == $total` from paginate_links()

Reported by: jdgrimes Owned by: SergeyBiryukov
Milestone: 4.7 Priority: normal
Severity: normal Version: 2.1
Component: Formatting Keywords:
Focuses: Cc:


paginate_links() contains this line:

        if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) :

The part where it checks if -1 == $total confused me, as it seemed to indicate that the function accepted an undefined total. However, it is impossible for $total to be less than 2 at this point in the function, because of this code farther up:

        $total = (int) $args['total'];
        if ( $total < 2 ) {

The -1 check has been there since the function was introduced in [4275], and at that time the $total could indeed be a negative number. However, almost immediately afterward, in https://core.trac.wordpress.org/changeset/4276#file5, the extra validation was added.

I think that possibly early on in the construction of the paginate_links() function the possibility of undefined totals/maximums was entertained, but then dismissed. (Or possibly the $total was modified inside the function, or maybe passing it in as -1 was intended to indicate something else? Who knows?) Anyway, that is our history lesson for today.

In short, this is a useless and confusing bit of code that we can just remove.

Change History (2)

#1 @SergeyBiryukov
5 years ago

  • Milestone changed from Awaiting Review to 4.7

#2 @SergeyBiryukov
5 years ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 38857:

Remove an obsolete 1 == $total check in paginate_links().

$total cannot be a negative number since [4276].

Props jdgrimes.
Fixes #38421.

Note: See TracTickets for help on using tickets.