diff --git src/wp-includes/general-template.php src/wp-includes/general-template.php
index f9a529f..6ed5151 100644
|
|
function paginate_links( $args = '' ) { |
2659 | 2659 | // Merge additional query vars found in the original URL into 'add_args' array. |
2660 | 2660 | if ( isset( $url_parts[1] ) ) { |
2661 | 2661 | // Find the format argument. |
2662 | | $format_query = parse_url( str_replace( '%_%', $args['format'], $args['base'] ), PHP_URL_QUERY ); |
2663 | | wp_parse_str( $format_query, $format_arg ); |
| 2662 | $format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) ); |
| 2663 | $format_query = isset( $format[1] ) ? $format[1] : ''; |
| 2664 | wp_parse_str( $format_query, $format_args ); |
| 2665 | |
| 2666 | // Find the query args of the requested URL. |
| 2667 | wp_parse_str( $url_parts[1], $url_query_args ); |
2664 | 2668 | |
2665 | 2669 | // Remove the format argument from the array of query arguments, to avoid overwriting custom format. |
2666 | | wp_parse_str( remove_query_arg( array_keys( $format_arg ), $url_parts[1] ), $query_args ); |
2667 | | $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $query_args ) ); |
| 2670 | foreach ( $format_args as $format_arg => $format_arg_value ) { |
| 2671 | if ( isset( $url_query_args[ $format_arg ] ) ) { |
| 2672 | unset( $url_query_args[ $format_arg ] ); |
| 2673 | } |
| 2674 | } |
| 2675 | |
| 2676 | $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) ); |
2668 | 2677 | } |
2669 | 2678 | |
2670 | 2679 | // Who knows what else people pass in $args |
diff --git tests/phpunit/tests/general/paginateLinks.php tests/phpunit/tests/general/paginateLinks.php
index b6c1a32..ba0b77b 100644
|
|
EXPECTED; |
311 | 311 | |
312 | 312 | $this->assertContains( "<span class='page-numbers current'>3</span>", $links ); |
313 | 313 | } |
| 314 | |
| 315 | /** |
| 316 | * @ticket 31939 |
| 317 | */ |
| 318 | public function test_custom_base_query_arg_should_be_stripped_from_current_url_before_generating_pag_links() { |
| 319 | // Fake the current URL: example.com?foo |
| 320 | $request_uri = $_SERVER['REQUEST_URI']; |
| 321 | $_SERVER['REQUEST_URI'] = add_query_arg( 'foo', '', $request_uri ); |
| 322 | |
| 323 | $links = paginate_links( array( |
| 324 | 'base' => add_query_arg( 'foo', '%_%', home_url() ), |
| 325 | 'format' => '%#%', |
| 326 | 'total' => 5, |
| 327 | 'current' => 1, |
| 328 | 'type' => 'array', |
| 329 | ) ); |
| 330 | |
| 331 | $page_2_url = home_url() . '?foo=2'; |
| 332 | $this->assertContains( "<a class='page-numbers' href='$page_2_url'>2</a>", $links ); |
| 333 | } |
314 | 334 | } |