Ticket #15029: 15029.patch
| File 15029.patch, 7.0 KB (added by , 12 years ago) |
|---|
-
src/wp-admin/includes/ajax-actions.php
diff --git src/wp-admin/includes/ajax-actions.php src/wp-admin/includes/ajax-actions.php index 799ef1e..6b63a6f 100644
function wp_ajax_add_tag() { 788 788 789 789 $level = 0; 790 790 if ( is_taxonomy_hierarchical($taxonomy) ) { 791 $level = count( get_ancestors( $tag->term_id, $taxonomy ) );791 $level = count( get_ancestors( $tag->term_id, $taxonomy, 'taxonomy' ) ); 792 792 ob_start(); 793 793 $wp_list_table->single_row( $tag, $level ); 794 794 $noparents = ob_get_clean(); -
src/wp-includes/taxonomy.php
diff --git src/wp-includes/taxonomy.php src/wp-includes/taxonomy.php index 2eecfec..5f6bdf4 100644
function get_term_link( $term, $taxonomy = '') { 4048 4048 } else { 4049 4049 if ( $t->rewrite['hierarchical'] ) { 4050 4050 $hierarchical_slugs = array(); 4051 $ancestors = get_ancestors( $term->term_id, $taxonomy);4051 $ancestors = get_ancestors( $term->term_id, $taxonomy, 'taxonomy' ); 4052 4052 foreach ( (array)$ancestors as $ancestor ) { 4053 4053 $ancestor_term = get_term($ancestor, $taxonomy); 4054 4054 $hierarchical_slugs[] = $ancestor_term->slug; … … function is_object_in_taxonomy($object_type, $taxonomy) { 4279 4279 /** 4280 4280 * Get an array of ancestor IDs for a given object. 4281 4281 * 4282 * @param int $object_id The ID of the object 4283 * @param string $object_type The type of object for which we'll be retrieving ancestors. 4284 * @return array of ancestors from lowest to highest in the hierarchy. 4282 * @param int $object_id The ID of the object. 4283 * @param string $object_type The type of object for which we'll be retrieving ancestors. 4284 * Accepts a post type or a taxonomy name. 4285 * @param string $resource_type Optional. Type of resource $object_type is. Accepts 'post_type' or 'taxonomy'. 4286 * @return array An array of ancestors from lowest to highest in the hierarchy. 4285 4287 */ 4286 function get_ancestors( $object_id = 0, $object_type = '') {4288 function get_ancestors( $object_id = 0, $object_type = '', $resource_type = '' ) { 4287 4289 $object_id = (int) $object_id; 4288 4290 4289 4291 $ancestors = array(); … … function get_ancestors($object_id = 0, $object_type = '') { 4291 4293 if ( empty( $object_id ) ) { 4292 4294 4293 4295 /** This filter is documented in wp-includes/taxonomy.php */ 4294 return apply_filters( 'get_ancestors', $ancestors, $object_id, $object_type );4296 return apply_filters( 'get_ancestors', $ancestors, $object_id, $object_type, $resource_type ); 4295 4297 } 4296 4298 4297 if ( is_taxonomy_hierarchical( $object_type ) ) { 4299 if ( ! $resource_type ) { 4300 if ( is_taxonomy_hierarchical( $object_type ) ) { 4301 $resource_type = 'taxonomy'; 4302 } else if ( post_type_exists( $object_type ) ) { 4303 $resource_type = 'post_type'; 4304 } 4305 } 4306 4307 if ( 'taxonomy' === $resource_type ) { 4298 4308 $term = get_term($object_id, $object_type); 4299 4309 while ( ! is_wp_error($term) && ! empty( $term->parent ) && ! in_array( $term->parent, $ancestors ) ) { 4300 4310 $ancestors[] = (int) $term->parent; 4301 4311 $term = get_term($term->parent, $object_type); 4302 4312 } 4303 } elseif ( post_type_exists( $object_type )) {4313 } elseif ( 'post_type' === $resource_type ) { 4304 4314 $ancestors = get_post_ancestors($object_id); 4305 4315 } 4306 4316 … … function get_ancestors($object_id = 0, $object_type = '') { 4309 4319 * 4310 4320 * @since 3.1.0 4311 4321 * 4312 * @param array $ancestors An array of object ancestors. 4313 * @param int $object_id Object ID. 4314 * @param string $object_type Type of object. 4322 * @param array $ancestors An array of object ancestors. 4323 * @param int $object_id Object ID. 4324 * @param string $object_type Type of object. 4325 * @param string $resource_type Type of resource $object_type is. 4315 4326 */ 4316 4327 return apply_filters( 'get_ancestors', $ancestors, $object_id, $object_type ); 4317 4328 } -
tests/phpunit/tests/taxonomy.php
diff --git tests/phpunit/tests/taxonomy.php tests/phpunit/tests/taxonomy.php index cab1caa..1fd3cd3 100644
class Tests_Taxonomy extends WP_UnitTestCase { 234 234 ); 235 235 $this->assertEquals( 0, wp_insert_category( $cat, false ) ); 236 236 } 237 238 public function test_get_ancestors_taxonomy_non_hierarchical() { 239 register_taxonomy( 'wptests_tax', 'post' ); 240 $t = $this->factory->term->create( array( 241 'taxonomy' => 'wptests_tax', 242 ) ); 243 244 $this->assertSame( array(), get_ancestors( $t, 'wptests_tax' ) ); 245 _unregister_taxonomy( 'wptests_tax' ); 246 } 247 248 public function test_get_ancestors_taxonomy() { 249 register_taxonomy( 'wptests_tax', 'post', array( 250 'hierarchical' => true, 251 ) ); 252 $t1 = $this->factory->term->create( array( 253 'taxonomy' => 'wptests_tax', 254 ) ); 255 $t2 = $this->factory->term->create( array( 256 'taxonomy' => 'wptests_tax', 257 'parent' => $t1, 258 ) ); 259 $t3 = $this->factory->term->create( array( 260 'taxonomy' => 'wptests_tax', 261 'parent' => $t2, 262 ) ); 263 $t4 = $this->factory->term->create( array( 264 'taxonomy' => 'wptests_tax', 265 'parent' => $t1, 266 ) ); 267 268 $this->assertEqualSets( array( $t2, $t1 ), get_ancestors( $t3, 'wptests_tax' ) ); 269 _unregister_taxonomy( 'wptests_tax' ); 270 } 271 272 public function test_get_ancestors_post_type_non_hierarchical() { 273 register_post_type( 'wptests_pt' ); 274 $p = $this->factory->post->create( array( 275 'taxonomy' => 'wptests_pt', 276 ) ); 277 278 $this->assertEqualSets( array(), get_ancestors( $p, 'wptests_tax' ) ); 279 } 280 281 public function test_get_ancestors_post_type() { 282 register_post_type( 'wptests_pt', array( 283 'hierarchical' => true, 284 ) ); 285 $p1 = $this->factory->post->create( array( 286 'post_type' => 'wptests_pt', 287 ) ); 288 $p2 = $this->factory->post->create( array( 289 'post_type' => 'wptests_pt', 290 'post_parent' => $p1, 291 ) ); 292 $p3 = $this->factory->post->create( array( 293 'post_type' => 'wptests_pt', 294 'post_parent' => $p2, 295 ) ); 296 $p4 = $this->factory->post->create( array( 297 'post_type' => 'wptests_pt', 298 'post_parent' => $p1, 299 ) ); 300 301 $this->assertEqualSets( array( $p2, $p1 ), get_ancestors( $p3, 'wptests_pt' ) ); 302 _unregister_post_type( 'wptests_pt' ); 303 } 304 305 /** 306 * @ticket 15029 307 */ 308 public function test_get_ancestors_taxonomy_post_type_conflict_resource_type_taxonomy() { 309 register_post_type( 'wptests_conflict', array( 310 'hierarchical' => true, 311 ) ); 312 $p1 = $this->factory->post->create( array( 313 'post_type' => 'wptests_conflict', 314 ) ); 315 $p2 = $this->factory->post->create( array( 316 'post_type' => 'wptests_conflict', 317 'post_parent' => $p1, 318 ) ); 319 320 register_taxonomy( 'wptests_conflict', 'post', array( 321 'hierarchical' => true, 322 ) ); 323 $t1 = $this->factory->term->create( array( 324 'taxonomy' => 'wptests_conflict', 325 ) ); 326 $t2 = $this->factory->term->create( array( 327 'taxonomy' => 'wptests_conflict', 328 'parent' => $t1, 329 ) ); 330 331 $this->assertEqualSets( array( $p1 ), get_ancestors( $p2, 'wptests_conflict', 'post_type' ) ); 332 $this->assertEqualSets( array( $t1 ), get_ancestors( $t2, 'wptests_conflict', 'taxonomy' ) ); 333 $this->assertEqualSets( array( $t1 ), get_ancestors( $t2, 'wptests_conflict' ) ); 334 _unregister_post_type( 'wptests_pt' ); 335 } 237 336 }
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)