From 76c787d4d22392d62f4ebaabc98440cdca926be0 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 8 Oct 2010 16:22:14 +0000 Subject: [PATCH] Some more hierarchy loop detection. git-svn-id: http://svn.automattic.com/wordpress/trunk@15758 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 180962c18e..f6032a7c29 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -4019,8 +4019,12 @@ function clean_post_cache($id) { do_action('clean_post_cache', $id); if ( $children = $wpdb->get_col( $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_parent = %d", $id) ) ) { - foreach( $children as $cid ) + foreach ( $children as $cid ) { + // Loop detection + if ( $cid == $id ) + continue; clean_post_cache( $cid ); + } } if ( is_multisite() ) @@ -4325,7 +4329,8 @@ function _get_post_ancestors(&$_post) { $id = $_post->ancestors[] = $_post->post_parent; while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) { - if ( $id == $ancestor ) + // Loop detection: If the ancestor has been seen before, break. + if ( ( $ancestor == $_post->ID ) || in_array($ancestor, $_post->ancestors) ) break; $id = $_post->ancestors[] = $ancestor; }