[wp-trac] [WordPress Trac] #38421: Remove impossible check for `-1 == $total` from paginate_links()

WordPress Trac noreply at wordpress.org
Thu Oct 20 20:46:43 UTC 2016


#38421: Remove impossible check for `-1 == $total` from paginate_links()
--------------------------+-----------------------------
 Reporter:  jdgrimes      |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Formatting    |    Version:  2.1
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 `paginate_links()` contains this line:

 {{{#!php
 <?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
 <?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.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/38421>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list