Make WordPress Core

Changeset 31432


Ignore:
Timestamp:
02/12/2015 01:38:26 AM (10 years ago)
Author:
dd32
Message:

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

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

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/general-template.php

    r31229 r31432  
    26202620    $args = wp_parse_args( $args, $defaults );
    26212621
     2622    if ( ! is_array( $args['add_args'] ) ) {
     2623        $args['add_args'] = array();
     2624    }
     2625
    26222626    // Merge additional query vars found in the original URL into 'add_args' array.
    26232627    if ( isset( $url_parts[1] ) ) {
     
    26452649        $mid_size = 2;
    26462650    }
    2647     $add_args = is_array( $args['add_args'] ) ? $args['add_args'] : false;
     2651    $add_args = $args['add_args'];
    26482652    $r = '';
    26492653    $page_links = array();
  • trunk/tests/phpunit/tests/general/paginateLinks.php

    r31203 r31432  
    292292        $_SERVER['REQUEST_URI'] = $request_uri;
    293293    }
     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    }
    294314}
Note: See TracChangeset for help on using the changeset viewer.