Avoid a PHP Warning when `add_args` is passed as `false` to `paginate_links()`.

Props boonebgorges for the unit test.
See #30831 [31203].


git-svn-id: https://develop.svn.wordpress.org/trunk@31432 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse 2015-02-12 01:38:26 +00:00
parent d17168583d
commit afef491a75
2 changed files with 25 additions and 1 deletions

View File

@ -2619,6 +2619,10 @@ function paginate_links( $args = '' ) {
$args = wp_parse_args( $args, $defaults );
if ( ! is_array( $args['add_args'] ) ) {
$args['add_args'] = array();
}
// Merge additional query vars found in the original URL into 'add_args' array.
if ( isset( $url_parts[1] ) ) {
// Find the format argument.
@ -2644,7 +2648,7 @@ function paginate_links( $args = '' ) {
if ( $mid_size < 0 ) {
$mid_size = 2;
}
$add_args = is_array( $args['add_args'] ) ? $args['add_args'] : false;
$add_args = $args['add_args'];
$r = '';
$page_links = array();
$dots = false;

View File

@ -291,4 +291,24 @@ EXPECTED;
$_SERVER['REQUEST_URI'] = $request_uri;
}
/**
* @ticket 30831
*/
public function test_paginate_links_should_allow_add_args_to_be_bool_false() {
// Fake the query params.
$request_uri = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = add_query_arg( 'foo', 3, home_url() );
$links = paginate_links( array(
'add_args' => false,
'base' => add_query_arg( 'foo', '%#%' ),
'format' => '',
'total' => 5,
'current' => 3,
'type' => 'array',
) );
$this->assertContains( "<span class='page-numbers current'>3</span>", $links );
}
}