Make WordPress Core

Changeset 8299


Ignore:
Timestamp:
07/09/2008 04:57:18 AM (17 years ago)
Author:
ryan
Message:

Prevent category looping. Props tellyworth. fixes #7267

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/category-template.php

    r8281 r8299  
    11<?php
    22
    3 function get_category_children($id, $before = '/', $after = '') {
     3function get_category_children($id, $before = '/', $after = '', $visited=array()) {
    44    if ( 0 == $id )
    55        return '';
     
    1515        if ( is_wp_error( $category ) )
    1616            return $category;
    17         if ( $category->parent == $id ) {
     17        if ( $category->parent == $id && !in_array($category->term_id, $visited) ) {
     18            $visited[] = $category->term_id;
    1819            $chain .= $before.$category->term_id.$after;
    1920            $chain .= get_category_children($category->term_id, $before, $after);
     
    4546}
    4647
    47 function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE){
     48function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE, $visited = array()){
    4849    $chain = '';
    4950    $parent = &get_category($id);
     
    5657        $name = $parent->cat_name;
    5758
    58     if ( $parent->parent && ($parent->parent != $parent->term_id) )
    59         $chain .= get_category_parents($parent->parent, $link, $separator, $nicename);
     59    if ( $parent->parent && ($parent->parent != $parent->term_id) && !in_array($parent->parent, $visited) ) {
     60        $visited[] = $parent->parent;
     61        $chain .= get_category_parents($parent->parent, $link, $separator, $nicename, $visited);
     62    }
    6063
    6164    if ( $link )
Note: See TracChangeset for help on using the changeset viewer.