From afef491a750ded563a274ceea2064276677a0e05 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Thu, 12 Feb 2015 01:38:26 +0000 Subject: [PATCH] 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 --- src/wp-includes/general-template.php | 6 +++++- tests/phpunit/tests/general/paginateLinks.php | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/general-template.php b/src/wp-includes/general-template.php index 6f0ff15c2d..15ec1e4396 100644 --- a/src/wp-includes/general-template.php +++ b/src/wp-includes/general-template.php @@ -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; diff --git a/tests/phpunit/tests/general/paginateLinks.php b/tests/phpunit/tests/general/paginateLinks.php index 930dcde301..b6c1a32879 100644 --- a/tests/phpunit/tests/general/paginateLinks.php +++ b/tests/phpunit/tests/general/paginateLinks.php @@ -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( "3", $links ); + } }