WordPress.org

Make WordPress Core

Ticket #32833: 32833.diff

File 32833.diff, 3.5 KB (added by boonebgorges, 6 years ago)
  • src/wp-includes/link-template.php

    diff --git src/wp-includes/link-template.php src/wp-includes/link-template.php
    index bee11f9..689a8ae 100644
    function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previo 
    14941494        $where = '';
    14951495
    14961496        if ( $in_same_term || ! empty( $excluded_terms ) ) {
    1497                 $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";
    1498                 $where = $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
    1499 
    15001497                if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) {
    15011498                        // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and "
    15021499                        if ( false !== strpos( $excluded_terms, ' and ' ) ) {
    function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previo 
    15101507                }
    15111508
    15121509                if ( $in_same_term ) {
     1510                        $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";
     1511                        $where .= $wpdb->prepare( "AND tt.taxonomy = %s", $taxonomy );
     1512
    15131513                        if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) )
    15141514                                return '';
    15151515                        $term_array = wp_get_object_terms( $post->ID, $taxonomy, array( 'fields' => 'ids' ) );
  • tests/phpunit/tests/link.php

    diff --git tests/phpunit/tests/link.php tests/phpunit/tests/link.php
    index 1090efe..3271be0 100644
    class Tests_Link extends WP_UnitTestCase { 
    257257                $this->assertEmpty( get_adjacent_post( false, array(), false ) );
    258258        }
    259259
     260        /**
     261         * @ticket 32833
     262         */
     263        public function test_get_adjacent_post_excluded_terms() {
     264                register_taxonomy( 'wptests_tax', 'post' );
     265
     266                $t = $this->factory->term->create( array(
     267                        'taxonomy' => 'wptests_tax',
     268                ) );
     269
     270                $p1 = $this->factory->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );
     271                $p2 = $this->factory->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );
     272                $p3 = $this->factory->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );
     273
     274                wp_set_post_terms( $p2, array( $t ), 'wptests_tax' );
     275
     276                // Fake current page.
     277                $GLOBALS['post'] = get_post( $p1 );
     278
     279                $found = get_adjacent_post( false, array( $t ), true, 'wptests_tax' );
     280
     281                // Should skip $p2, which belongs to $t.
     282                $this->assertEquals( $p3, $found->ID );
     283        }
     284
     285        /**
     286         * @ticket 32833
     287         */
     288        public function test_get_adjacent_post_excluded_terms_should_not_require_posts_to_have_terms_in_any_taxonomy() {
     289                register_taxonomy( 'wptests_tax', 'post' );
     290
     291                $t = $this->factory->term->create( array(
     292                        'taxonomy' => 'wptests_tax',
     293                ) );
     294
     295                $p1 = $this->factory->post->create( array( 'post_date' => '2015-08-27 12:00:00' ) );
     296                $p2 = $this->factory->post->create( array( 'post_date' => '2015-08-26 12:00:00' ) );
     297                $p3 = $this->factory->post->create( array( 'post_date' => '2015-08-25 12:00:00' ) );
     298
     299                wp_set_post_terms( $p2, array( $t ), 'wptests_tax' );
     300
     301                // Make sure that $p3 doesn't have the 'Uncategorized' category.
     302                wp_delete_object_term_relationships( $p3, 'category' );
     303
     304                // Fake current page.
     305                $GLOBALS['post'] = get_post( $p1 );
     306
     307                $found = get_adjacent_post( false, array( $t ), true, 'wptests_tax' );
     308
     309                // Should skip $p2, which belongs to $t.
     310                $this->assertEquals( $p3, $found->ID );
     311        }
     312
    260313        public function test_wp_make_link_relative_with_http_scheme() {
    261314                $link = 'http://example.com/this-is-a-test-http-url/';
    262315                $relative_link = wp_make_link_relative( $link );