Make WordPress Core

Changeset 44591


Ignore:
Timestamp:
01/15/2019 01:53:02 AM (8 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.

Location:
trunk
Files:
2 edited

Legend:

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

    r44499 r44591  
    16881688        $adjacent = $previous ? 'previous' : 'next';
    16891689
     1690        if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
     1691                // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
     1692                if ( false !== strpos( $excluded_terms, ' and ' ) ) {
     1693                        _deprecated_argument( __FUNCTION__, '3.3.0', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
     1694                        $excluded_terms = explode( ' and ', $excluded_terms );
     1695                } else {
     1696                        $excluded_terms = explode( ',', $excluded_terms );
     1697                }
     1698
     1699                $excluded_terms = array_map( 'intval', $excluded_terms );
     1700        }
     1701
    16901702        /**
    16911703         * Filters the IDs of terms excluded from adjacent post queries.
     
    16961708         * @since 4.4.0
    16971709         *
    1698          * @param string $excluded_terms Array of excluded term IDs.
     1710         * @param array $excluded_terms Array of excluded term IDs.
    16991711         */
    17001712        $excluded_terms = apply_filters( "get_{$adjacent}_post_excluded_terms", $excluded_terms );
    17011713
    17021714        if ( $in_same_term || ! empty( $excluded_terms ) ) {
    1703                 if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
    1704                         // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
    1705                         if ( false !== strpos( $excluded_terms, ' and ' ) ) {
    1706                                 _deprecated_argument( __FUNCTION__, '3.3.0', sprintf( __( 'Use commas instead of %s to separate excluded terms.' ), "'and'" ) );
    1707                                 $excluded_terms = explode( ' and ', $excluded_terms );
    1708                         } else {
    1709                                 $excluded_terms = explode( ',', $excluded_terms );
    1710                         }
    1711 
    1712                         $excluded_terms = array_map( 'intval', $excluded_terms );
    1713                 }
    1714 
    17151715                if ( $in_same_term ) {
    17161716                        $join  .= " INNER JOIN $wpdb->term_relationships AS tr ON p.ID = tr.object_id INNER JOIN $wpdb->term_taxonomy tt ON tr.term_taxonomy_id = tt.term_taxonomy_id";
  • 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.