Make WordPress Core


Ignore:
Timestamp:
01/15/2019 01:53:02 AM (6 years ago)
Author:
pento
Message:

Link Template: In get_adjacent_post(), move the sanitisation of $excluded_terms earlier.

This is a followup to [42828], ensuring that the get_{$adjacent}_post_excluded_terms filter is always passed an array, as expected.

Props soulseekah, zottto.
Fixes #43521.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/link/getAdjacentPost.php

    r43571 r44591  
    313313    }
    314314
     315    /**
     316     * @ticket 43521
     317     */
     318    public function test_excluded_terms_filter_empty() {
     319        register_taxonomy( 'wptests_tax', 'post' );
     320
     321        $terms = self::factory()->term->create_many(
     322            2,
     323            array(
     324                'taxonomy' => 'wptests_tax',
     325            )
     326        );
     327
     328        $p1 = self::factory()->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );
     329        $p2 = self::factory()->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );
     330        $p3 = self::factory()->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );
     331
     332        wp_set_post_terms( $p1, array( $terms[0], $terms[1] ), 'wptests_tax' );
     333        wp_set_post_terms( $p2, array( $terms[1] ), 'wptests_tax' );
     334        wp_set_post_terms( $p3, array( $terms[0] ), 'wptests_tax' );
     335
     336        $this->go_to( get_permalink( $p1 ) );
     337
     338        $this->exclude_term = $terms[1];
     339        add_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) );
     340
     341        $found = get_adjacent_post( false, array(), true, 'wptests_tax' );
     342
     343        remove_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) );
     344        unset( $this->exclude_term );
     345
     346        $this->assertSame( $p3, $found->ID );
     347    }
     348
    315349    public function filter_excluded_terms( $excluded_terms ) {
    316350        $excluded_terms[] = $this->exclude_term;
Note: See TracChangeset for help on using the changeset viewer.