Make WordPress Core

Changeset 36078


Ignore:
Timestamp:
12/23/2015 07:56:32 PM (8 years ago)
Author:
boonebgorges
Message:

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.

Location:
trunk
Files:
2 edited

Legend:

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

    r36011 r36078  
    15691569    $join = '';
    15701570    $where = '';
     1571    $adjacent = $previous ? 'previous' : 'next';
    15711572
    15721573    if ( $in_same_term || ! empty( $excluded_terms ) ) {
     
    16001601            $where .= " AND tt.term_id IN (" . implode( ',', $term_array ) . ")";
    16011602        }
     1603
     1604        /**
     1605         * Filter the IDs of terms excluded from adjacent post queries.
     1606         *
     1607         * The dynamic portion of the hook name, `$adjacent`, refers to the type
     1608         * of adjacency, 'next' or 'previous'.
     1609         *
     1610         * @since 4.4.0
     1611         *
     1612         * @param string $excluded_terms Array of excluded term IDs.
     1613         */
     1614        $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
    16021615
    16031616        if ( ! empty( $excluded_terms ) ) {
     
    16361649    }
    16371650
    1638     $adjacent = $previous ? 'previous' : 'next';
    16391651    $op = $previous ? '<' : '>';
    16401652    $order = $previous ? 'DESC' : 'ASC';
    1641 
    1642     /**
    1643      * Filter the excluded term ids
    1644      *
    1645      * The dynamic portion of the hook name, `$adjacent`, refers to the type
    1646      * of adjacency, 'next' or 'previous'.
    1647      *
    1648      * @since 4.4.0
    1649      *
    1650      * @param string $excluded_terms Array of excluded term IDs.
    1651      */
    1652     $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
    16531653
    16541654    /**
  • trunk/tests/phpunit/tests/link/getAdjacentPost.php

    r36077 r36078  
    55 */
    66class Tests_Link_GetAdjacentPost extends WP_UnitTestCase {
     7    protected $exclude_term;
     8
    79    /**
    810     * @ticket 17807
     
    211213        $this->assertEquals( $p3, $found->ID );
    212214    }
     215
     216    /**
     217     * @ticket 35211
     218     */
     219    public function test_excluded_terms_filter() {
     220        register_taxonomy( 'wptests_tax', 'post' );
     221
     222        $terms = self::factory()->term->create_many( 2, array(
     223            'taxonomy' => 'wptests_tax',
     224        ) );
     225
     226        $p1 = self::factory()->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );
     227        $p2 = self::factory()->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );
     228        $p3 = self::factory()->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );
     229
     230        wp_set_post_terms( $p1, array( $terms[0], $terms[1] ), 'wptests_tax' );
     231        wp_set_post_terms( $p2, array( $terms[1] ), 'wptests_tax' );
     232        wp_set_post_terms( $p3, array( $terms[0] ), 'wptests_tax' );
     233
     234        $this->go_to( get_permalink( $p1 ) );
     235
     236        $this->exclude_term = $terms[1];
     237        add_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) );
     238
     239        $found = get_adjacent_post( true, array(), true, 'wptests_tax' );
     240
     241        remove_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) );
     242        unset( $this->exclude_term );
     243
     244        $this->assertSame( $p3, $found->ID );
     245    }
     246
     247    public function filter_excluded_terms( $excluded_terms ) {
     248        $excluded_terms[] = $this->exclude_term;
     249        return $excluded_terms;
     250    }
    213251}
Note: See TracChangeset for help on using the changeset viewer.