Make WordPress Core

Changeset 27837


Ignore:
Timestamp:
03/29/2014 06:07:17 AM (12 years ago)
Author:
nacin
Message:

Avoid infinite recursion in get_term_children() when a term is incorrectly a parent of itself.

props kovshenin.
fixes #27123.

Location:
trunk
Files:
2 edited

Legend:

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

    r27827 r27837  
    11081108
    11091109        foreach ( (array) $terms[$term_id] as $child ) {
     1110                if ( $term_id == $child ) {
     1111                        continue;
     1112                }
     1113
    11101114                if ( isset($terms[$child]) )
    11111115                        $children = array_merge($children, get_term_children($child, $taxonomy));
  • trunk/tests/phpunit/tests/term/getTerms.php

    r27459 r27837  
    334334                $this->assertEquals( 1, count( $terms ) );
    335335        }
     336
     337        /**
     338         * @ticket 27123
     339         */
     340        function test_get_term_children_recursion() {
     341                // Assume there is a way to insert a term with the parent pointing to itself
     342                // See: https://core.trac.wordpress.org/changeset/15806
     343                remove_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10 );
     344
     345                $term = wp_insert_term( 'Test', 'category' );
     346                $term = wp_update_term( $term['term_id'], 'category', array( 'parent' => $term['term_id'] ) );
     347                $term = get_term( $term['term_id'], 'category' );
     348
     349                $this->assertEquals( $term->term_id, $term->parent );
     350                $this->assertInternalType( 'array', get_term_children( $term->term_id, 'category' ) );
     351
     352                add_filter( 'wp_update_term_parent', 'wp_check_term_hierarchy_for_loops', 10, 3 );
     353        }
    336354}
Note: See TracChangeset for help on using the changeset viewer.