From d5acdd82c879854bc2d75643b49f00143768964b Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Wed, 14 May 2014 22:29:14 +0000 Subject: [PATCH] Eliminate use of `extract()` in `paginate_links()`. Adds unit tests. Moves `tests/general/template.php` (which only had one method) to `tests/general/paginateLinks.php`. See #22400. Built from https://develop.svn.wordpress.org/trunk@28397 git-svn-id: http://core.svn.wordpress.org/trunk@28225 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/general-template.php | 56 ++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 25 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index 20855ae2c5..8d960fffcb 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -2447,26 +2447,32 @@ function paginate_links( $args = '' ) { ); $args = wp_parse_args( $args, $defaults ); - extract($args, EXTR_SKIP); // Who knows what else people pass in $args - $total = (int) $total; - if ( $total < 2 ) + $total = (int) $args['total']; + if ( $total < 2 ) { return; - $current = (int) $current; - $end_size = 0 < (int) $end_size ? (int) $end_size : 1; // Out of bounds? Make it the default. - $mid_size = 0 <= (int) $mid_size ? (int) $mid_size : 2; - $add_args = is_array($add_args) ? $add_args : false; + } + $current = (int) $args['current']; + $end_size = (int) $args['end_size']; // Out of bounds? Make it the default. + if ( $end_size < 1 ) { + $end_size = 1; + } + $mid_size = (int) $args['mid_size']; + if ( $mid_size < 0 ) { + $mid_size = 2; + } + $add_args = is_array( $args['add_args'] ) ? $args['add_args'] : false; $r = ''; $page_links = array(); $dots = false; - if ( $prev_next && $current && 1 < $current ) : - $link = str_replace('%_%', 2 == $current ? '' : $format, $base); - $link = str_replace('%#%', $current - 1, $link); + if ( $args['prev_next'] && $current && 1 < $current ) : + $link = str_replace( '%_%', 2 == $current ? '' : $args['format'], $args['base'] ); + $link = str_replace( '%#%', $current - 1, $link ); if ( $add_args ) $link = add_query_arg( $add_args, $link ); - $link .= $add_fragment; + $link .= $args['add_fragment']; /** * Filter the paginated links for the given archive pages. @@ -2475,40 +2481,40 @@ function paginate_links( $args = '' ) { * * @param string $link The paginated link URL. */ - $page_links[] = ''; + $page_links[] = ''; endif; for ( $n = 1; $n <= $total; $n++ ) : if ( $n == $current ) : - $page_links[] = "" . $before_page_number . number_format_i18n( $n ) . $after_page_number . ""; + $page_links[] = "" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . ""; $dots = true; else : - if ( $show_all || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : - $link = str_replace('%_%', 1 == $n ? '' : $format, $base); - $link = str_replace('%#%', $n, $link); + if ( $args['show_all'] || ( $n <= $end_size || ( $current && $n >= $current - $mid_size && $n <= $current + $mid_size ) || $n > $total - $end_size ) ) : + $link = str_replace( '%_%', 1 == $n ? '' : $args['format'], $args['base'] ); + $link = str_replace( '%#%', $n, $link ); if ( $add_args ) $link = add_query_arg( $add_args, $link ); - $link .= $add_fragment; + $link .= $args['add_fragment']; /** This filter is documented in wp-includes/general-template.php */ - $page_links[] = "" . $before_page_number . number_format_i18n( $n ) . $after_page_number . ""; + $page_links[] = "" . $args['before_page_number'] . number_format_i18n( $n ) . $args['after_page_number'] . ""; $dots = true; - elseif ( $dots && !$show_all ) : + elseif ( $dots && ! $args['show_all'] ) : $page_links[] = '' . __( '…' ) . ''; $dots = false; endif; endif; endfor; - if ( $prev_next && $current && ( $current < $total || -1 == $total ) ) : - $link = str_replace('%_%', $format, $base); - $link = str_replace('%#%', $current + 1, $link); + if ( $args['prev_next'] && $current && ( $current < $total || -1 == $total ) ) : + $link = str_replace( '%_%', $args['format'], $args['base'] ); + $link = str_replace( '%#%', $current + 1, $link ); if ( $add_args ) $link = add_query_arg( $add_args, $link ); - $link .= $add_fragment; + $link .= $args['add_fragment']; /** This filter is documented in wp-includes/general-template.php */ - $page_links[] = ''; + $page_links[] = ''; endif; - switch ( $type ) { + switch ( $args['type'] ) { case 'array' : return $page_links;