WordPress.org

Make WordPress Core


Ignore:
Timestamp:
05/05/2015 09:58:23 PM (6 years ago)
Author:
boonebgorges
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/general/paginateLinks.php

    r31432 r32359  
    312312        $this->assertContains( "<span class='page-numbers current'>3</span>", $links );
    313313    }
     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    }
    314334}
Note: See TracChangeset for help on using the changeset viewer.