Opened 9 years ago
Closed 9 years ago
#38421 closed defect (bug) (fixed)
Remove impossible check for `-1 == $total` from paginate_links()
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.7 | Priority: | normal |
| Severity: | normal | Version: | 2.1 |
| Component: | Formatting | Keywords: | |
| Focuses: | Cc: |
Description
paginate_links() contains this line:
<?php 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:
<?php $total = (int) $args['total']; if ( $total < 2 ) { return; }
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.
In 38857: