WordPress.org

Make WordPress Core

Ticket #27123: 27123.diff

File 27123.diff, 1.6 KB (added by kovshenin, 4 years ago)
  • src/wp-includes/taxonomy.php

     
    10661066        $children = $terms[$term_id];
    10671067
    10681068        foreach ( (array) $terms[$term_id] as $child ) {
     1069                if ( $term_id == $child ) {
     1070                        continue;
     1071                }
     1072
    10691073                if ( isset($terms[$child]) )
    10701074                        $children = array_merge($children, get_term_children($child, $taxonomy));
    10711075        }
  • tests/phpunit/tests/term/getTerms.php

     
    333333                $terms = get_terms( 'category', array( 'child_of' => $parent, 'hide_empty' => false ) );
    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}