Make WordPress Core

Changeset 42828


Ignore:
Timestamp:
03/11/2018 05:31:04 PM (8 years ago)
Author:
SergeyBiryukov
Message:

Link Template: Apply get_{$adjacent}_post_excluded_terms filter to an empty excluded_terms parameter as well.

Props soulseekah, zottto.
Fixes #43521.

Location:
trunk
Files:
2 edited

Legend:

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

    r42736 r42828  
    16831683        $adjacent = $previous ? 'previous' : 'next';
    16841684
     1685        /**
     1686         * Filters the IDs of terms excluded from adjacent post queries.
     1687         *
     1688         * The dynamic portion of the hook name, `$adjacent`, refers to the type
     1689         * of adjacency, 'next' or 'previous'.
     1690         *
     1691         * @since 4.4.0
     1692         *
     1693         * @param string $excluded_terms Array of excluded term IDs.
     1694         */
     1695        $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
     1696
    16851697        if ( $in_same_term || ! empty( $excluded_terms ) ) {
    16861698                if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
     
    17151727                        $where .= ' AND tt.term_id IN (' . implode( ',', $term_array ) . ')';
    17161728                }
    1717 
    1718                 /**
    1719                  * Filters the IDs of terms excluded from adjacent post queries.
    1720                  *
    1721                  * The dynamic portion of the hook name, `$adjacent`, refers to the type
    1722                  * of adjacency, 'next' or 'previous'.
    1723                  *
    1724                  * @since 4.4.0
    1725                  *
    1726                  * @param string $excluded_terms Array of excluded term IDs.
    1727                  */
    1728                 $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
    17291729
    17301730                if ( ! empty( $excluded_terms ) ) {
  • trunk/tests/phpunit/tests/link/getAdjacentPost.php

    r42343 r42828  
    247247         * @ticket 35211
    248248         */
    249         public function test_excluded_terms_filter() {
     249        public function test_get_adjacent_post_excluded_terms_filter() {
    250250                register_taxonomy( 'wptests_tax', 'post' );
    251251
     
    277277        }
    278278
     279        /**
     280         * @ticket 43521
     281         */
     282        public function test_get_adjacent_post_excluded_terms_filter_should_apply_to_empty_excluded_terms_parameter() {
     283                register_taxonomy( 'wptests_tax', 'post' );
     284
     285                $terms = self::factory()->term->create_many(
     286                        2, array(
     287                                'taxonomy' => 'wptests_tax',
     288                        )
     289                );
     290
     291                $p1 = self::factory()->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );
     292                $p2 = self::factory()->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );
     293                $p3 = self::factory()->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );
     294
     295                wp_set_post_terms( $p1, array( $terms[0], $terms[1] ), 'wptests_tax' );
     296                wp_set_post_terms( $p2, array( $terms[1] ), 'wptests_tax' );
     297                wp_set_post_terms( $p3, array( $terms[0] ), 'wptests_tax' );
     298
     299                $this->go_to( get_permalink( $p1 ) );
     300
     301                $this->exclude_term = $terms[1];
     302                add_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) );
     303
     304                $found = get_adjacent_post( false, array(), true, 'wptests_tax' );
     305
     306                remove_filter( 'get_previous_post_excluded_terms', array( $this, 'filter_excluded_terms' ) );
     307                unset( $this->exclude_term );
     308
     309                $this->assertSame( $p3, $found->ID );
     310        }
     311
    279312        public function filter_excluded_terms( $excluded_terms ) {
    280313                $excluded_terms[] = $this->exclude_term;
Note: See TracChangeset for help on using the changeset viewer.