Changeset 31433 for branches/4.1
- Timestamp:
- 02/12/2015 02:19:44 AM (10 years ago)
- Location:
- branches/4.1
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.1
- Property svn:mergeinfo changed
/trunk merged: 31203,31432
- Property svn:mergeinfo changed
-
branches/4.1/src/wp-includes/general-template.php
r30864 r31433 2588 2588 global $wp_query, $wp_rewrite; 2589 2589 2590 $total = ( isset( $wp_query->max_num_pages ) ) ? $wp_query->max_num_pages : 1; 2591 $current = ( get_query_var( 'paged' ) ) ? intval( get_query_var( 'paged' ) ) : 1; 2590 // Setting up default values based on the current URL. 2592 2591 $pagenum_link = html_entity_decode( get_pagenum_link() ); 2593 $query_args = array();2594 2592 $url_parts = explode( '?', $pagenum_link ); 2595 2593 2596 if ( isset( $url_parts[1] ) ) {2597 wp_parse_str( $url_parts[1], $query_args );2598 $query_args = urlencode_deep( $query_args );2599 } 2600 2601 $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );2602 $pagenum_link = trailingslashit( $pagenum_link ) . '%_%'; 2603 2594 // Get max pages and current page out of the current query, if available. 2595 $total = isset( $wp_query->max_num_pages ) ? $wp_query->max_num_pages : 1; 2596 $current = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1; 2597 2598 // Append the format placeholder to the base URL. 2599 $pagenum_link = trailingslashit( $url_parts[0] ) . '%_%'; 2600 2601 // URL base depends on permalink settings. 2604 2602 $format = $wp_rewrite->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : ''; 2605 2603 $format .= $wp_rewrite->using_permalinks() ? user_trailingslashit( $wp_rewrite->pagination_base . '/%#%', 'paged' ) : '?paged=%#%'; … … 2617 2615 'mid_size' => 2, 2618 2616 'type' => 'plain', 2619 'add_args' => $query_args, // array of query args to add2617 'add_args' => array(), // array of query args to add 2620 2618 'add_fragment' => '', 2621 2619 'before_page_number' => '', … … 2625 2623 $args = wp_parse_args( $args, $defaults ); 2626 2624 2625 if ( ! is_array( $args['add_args'] ) ) { 2626 $args['add_args'] = array(); 2627 } 2628 2629 // Merge additional query vars found in the original URL into 'add_args' array. 2630 if ( isset( $url_parts[1] ) ) { 2631 // Find the format argument. 2632 $format_query = parse_url( str_replace( '%_%', $args['format'], $args['base'] ), PHP_URL_QUERY ); 2633 wp_parse_str( $format_query, $format_arg ); 2634 2635 // Remove the format argument from the array of query arguments, to avoid overwriting custom format. 2636 wp_parse_str( remove_query_arg( array_keys( $format_arg ), $url_parts[1] ), $query_args ); 2637 $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $query_args ) ); 2638 } 2639 2627 2640 // Who knows what else people pass in $args 2628 2641 $total = (int) $args['total']; … … 2639 2652 $mid_size = 2; 2640 2653 } 2641 $add_args = is_array( $args['add_args'] ) ? $args['add_args'] : false;2654 $add_args = $args['add_args']; 2642 2655 $r = ''; 2643 2656 $page_links = array(); -
branches/4.1/tests/phpunit/tests/general/paginateLinks.php
r30133 r31433 230 230 } 231 231 } 232 233 /** 234 * @ticket 30831 235 */ 236 function test_paginate_links_with_custom_query_args() { 237 add_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) ); 238 $links = paginate_links( array( 239 'current' => 2, 240 'total' => 5, 241 'end_size' => 1, 242 'mid_size' => 1, 243 'type' => 'array', 244 'add_args' => array( 245 'baz' => 'qux', 246 ), 247 ) ); 248 remove_filter( 'get_pagenum_link', array( $this, 'add_query_arg' ) ); 249 250 $document = new DOMDocument(); 251 $document->preserveWhiteSpace = false; 252 253 $data = array( 254 0 => home_url( '/?baz=qux&foo=bar&s=search+term' ), 255 1 => home_url( '/?baz=qux&foo=bar&s=search+term' ), 256 3 => home_url( '/?paged=3&baz=qux&foo=bar&s=search+term' ), 257 5 => home_url( '/?paged=5&baz=qux&foo=bar&s=search+term' ), 258 6 => home_url( '/?paged=3&baz=qux&foo=bar&s=search+term' ), 259 ); 260 261 foreach ( $data as $index => $expected_href ) { 262 $document->loadHTML( $links[ $index ] ); 263 $tag = $document->getElementsByTagName( 'a' )->item( 0 ); 264 $this->assertNotNull( $tag ); 265 266 $href = $tag->attributes->getNamedItem( 'href' )->value; 267 $this->assertEquals( $expected_href, $href ); 268 } 269 } 270 271 /** 272 * @ticket 30831 273 */ 274 public function test_paginate_links_should_allow_non_default_format_without_add_args() { 275 // Fake the query params. 276 $request_uri = $_SERVER['REQUEST_URI']; 277 $_SERVER['REQUEST_URI'] = add_query_arg( 'foo', 3, home_url() ); 278 279 $links = paginate_links( array( 280 'base' => add_query_arg( 'foo', '%#%' ), 281 'format' => '', 282 'total' => 5, 283 'current' => 3, 284 'type' => 'array', 285 ) ); 286 287 $this->assertContains( '?foo=1', $links[1] ); 288 $this->assertContains( '?foo=2', $links[2] ); 289 $this->assertContains( '?foo=4', $links[4] ); 290 $this->assertContains( '?foo=5', $links[5] ); 291 292 $_SERVER['REQUEST_URI'] = $request_uri; 293 } 294 295 /** 296 * @ticket 30831 297 */ 298 public function test_paginate_links_should_allow_add_args_to_be_bool_false() { 299 // Fake the query params. 300 $request_uri = $_SERVER['REQUEST_URI']; 301 $_SERVER['REQUEST_URI'] = add_query_arg( 'foo', 3, home_url() ); 302 303 $links = paginate_links( array( 304 'add_args' => false, 305 'base' => add_query_arg( 'foo', '%#%' ), 306 'format' => '', 307 'total' => 5, 308 'current' => 3, 309 'type' => 'array', 310 ) ); 311 312 $this->assertContains( "<span class='page-numbers current'>3</span>", $links ); 313 } 232 314 }
Note: See TracChangeset
for help on using the changeset viewer.