mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 14:20:15 +00:00
Move excluded_terms filter in get_adjacent_post().
The filter was added in 4.4 [34528] #9571, but in a place where it could not affect the adjacent post query. Fixes #35211. git-svn-id: https://develop.svn.wordpress.org/trunk@36078 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
* @covers ::get_adjacent_link
|
||||
*/
|
||||
class Tests_Link_GetAdjacentPost extends WP_UnitTestCase {
|
||||
protected $exclude_term;
|
||||
|
||||
/**
|
||||
* @ticket 17807
|
||||
*/
|
||||
@@ -210,4 +212,40 @@ class Tests_Link_GetAdjacentPost extends WP_UnitTestCase {
|
||||
// Should skip $p2, which belongs to $t.
|
||||
$this->assertEquals( $p3, $found->ID );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 35211
|
||||
*/
|
||||
public function test_excluded_terms_filter() {
|
||||
register_taxonomy( 'wptests_tax', 'post' );
|
||||
|
||||
$terms = self::factory()->term->create_many( 2, array(
|
||||
'taxonomy' => 'wptests_tax',
|
||||
) );
|
||||
|
||||
$p1 = self::factory()->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );
|
||||
$p2 = self::factory()->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );
|
||||
$p3 = self::factory()->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );
|
||||
|
||||
wp_set_post_terms( $p1, array( $terms[0], $terms[1] ), 'wptests_tax' );
|
||||
wp_set_post_terms( $p2, array( $terms[1] ), 'wptests_tax' );
|
||||
wp_set_post_terms( $p3, array( $terms[0] ), 'wptests_tax' );
|
||||
|
||||
$this->go_to( get_permalink( $p1 ) );
|
||||
|
||||
$this->exclude_term = $terms[1];
|
||||
add_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) );
|
||||
|
||||
$found = get_adjacent_post( true, array(), true, 'wptests_tax' );
|
||||
|
||||
remove_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) );
|
||||
unset( $this->exclude_term );
|
||||
|
||||
$this->assertSame( $p3, $found->ID );
|
||||
}
|
||||
|
||||
public function filter_excluded_terms( $excluded_terms ) {
|
||||
$excluded_terms[] = $this->exclude_term;
|
||||
return $excluded_terms;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user