Ticket #7267: prevent-category-looping-r8296.patch
| File prevent-category-looping-r8296.patch, 1.8 KB (added by tellyworth, 5 years ago) |
|---|
-
wp-includes/category-template.php
1 1 <?php 2 2 3 function get_category_children($id, $before = '/', $after = '' ) {3 function get_category_children($id, $before = '/', $after = '', $visited=array()) { 4 4 if ( 0 == $id ) 5 5 return ''; 6 6 … … 14 14 $category = get_category($cat_id); 15 15 if ( is_wp_error( $category ) ) 16 16 return $category; 17 if ( $category->parent == $id ) { 17 if ( $category->parent == $id && !in_array($category->term_id, $visited) ) { 18 $visited[] = $category->term_id; 18 19 $chain .= $before.$category->term_id.$after; 19 20 $chain .= get_category_children($category->term_id, $before, $after); 20 21 } … … 44 45 return apply_filters('category_link', $catlink, $category_id); 45 46 } 46 47 47 function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE ){48 function get_category_parents($id, $link = FALSE, $separator = '/', $nicename = FALSE, $visited = array()){ 48 49 $chain = ''; 49 50 $parent = &get_category($id); 50 51 if ( is_wp_error( $parent ) ) … … 55 56 else 56 57 $name = $parent->cat_name; 57 58 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 } 60 63 61 64 if ( $link ) 62 65 $chain .= '<a href="' . get_category_link($parent->term_id) . '" title="' . sprintf(__("View all posts in %s"), $parent->cat_name) . '">'.$name.'</a>' . $separator;
