From 29216371bd899e445e53fa6072ee622c424c0d31 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Tue, 5 May 2015 21:59:26 +0000 Subject: [PATCH] In `paginate_links()`, improve handling of custom pagination query vars. Custom pagination query vars, as provided in the 'base' parameter, must be detected in the current page URL and removed before generating fresh pagination links. The logic introduced in this changeset ensures that these custom query vars are properly detected in cases where the 'format' param contains a `#`. This is a follow-up to [31203] #30831. Fixes #31939. Built from https://develop.svn.wordpress.org/trunk@32359 git-svn-id: http://core.svn.wordpress.org/trunk@32330 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/general-template.php | 17 +++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/wp-includes/general-template.php b/wp-includes/general-template.php index f9a529f069..6ed5151a98 100644 --- a/wp-includes/general-template.php +++ b/wp-includes/general-template.php @@ -2659,12 +2659,21 @@ function paginate_links( $args = '' ) { // Merge additional query vars found in the original URL into 'add_args' array. if ( isset( $url_parts[1] ) ) { // Find the format argument. - $format_query = parse_url( str_replace( '%_%', $args['format'], $args['base'] ), PHP_URL_QUERY ); - wp_parse_str( $format_query, $format_arg ); + $format = explode( '?', str_replace( '%_%', $args['format'], $args['base'] ) ); + $format_query = isset( $format[1] ) ? $format[1] : ''; + wp_parse_str( $format_query, $format_args ); + + // Find the query args of the requested URL. + wp_parse_str( $url_parts[1], $url_query_args ); // Remove the format argument from the array of query arguments, to avoid overwriting custom format. - wp_parse_str( remove_query_arg( array_keys( $format_arg ), $url_parts[1] ), $query_args ); - $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $query_args ) ); + foreach ( $format_args as $format_arg => $format_arg_value ) { + if ( isset( $url_query_args[ $format_arg ] ) ) { + unset( $url_query_args[ $format_arg ] ); + } + } + + $args['add_args'] = array_merge( $args['add_args'], urlencode_deep( $url_query_args ) ); } // Who knows what else people pass in $args diff --git a/wp-includes/version.php b/wp-includes/version.php index 14ae866366..acedc6e2c9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.3-alpha-32358'; +$wp_version = '4.3-alpha-32359'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.