Ticket #32833: 32833.diff
| File 32833.diff, 3.5 KB (added by , 11 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 1494 1494 $where = ''; 1495 1495 1496 1496 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 1500 1497 if ( ! empty( $excluded_terms ) && ! is_array( $excluded_terms ) ) { 1501 1498 // back-compat, $excluded_terms used to be $excluded_terms with IDs separated by " and " 1502 1499 if ( false !== strpos( $excluded_terms, ' and ' ) ) { … … function get_adjacent_post( $in_same_term = false, $excluded_terms = '', $previo 1510 1507 } 1511 1508 1512 1509 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 1513 1513 if ( ! is_object_in_taxonomy( $post->post_type, $taxonomy ) ) 1514 1514 return ''; 1515 1515 $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 { 257 257 $this->assertEmpty( get_adjacent_post( false, array(), false ) ); 258 258 } 259 259 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 260 313 public function test_wp_make_link_relative_with_http_scheme() { 261 314 $link = 'http://example.com/this-is-a-test-http-url/'; 262 315 $relative_link = wp_make_link_relative( $link );
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)