From 504bc044d8e1249c8ab0c02244e57cf220af2b6a Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 8 Dec 2008 19:29:42 +0000 Subject: [PATCH] Check for circular post parent dependencies. Exclude the current post and its children from the parent dropdown. git-svn-id: http://svn.automattic.com/wordpress/trunk@10129 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/edit-page-form.php | 2 +- wp-includes/post.php | 30 +++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/wp-admin/edit-page-form.php b/wp-admin/edit-page-form.php index e65be6224..823305595 100644 --- a/wp-admin/edit-page-form.php +++ b/wp-admin/edit-page-form.php @@ -270,7 +270,7 @@ function page_attributes_meta_box($post){ ?>
- $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('Main Page (no parent)'))); ?> + $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('Main Page (no parent)'))); ?>

post_parent == $post_ID ) + $post_parent = 0; + } + } + if ( isset($menu_order) ) $menu_order = (int) $menu_order; else @@ -2059,7 +2071,7 @@ function &get_pages($args = '') { 'sort_column' => 'post_title', 'hierarchical' => 1, 'exclude' => '', 'include' => '', 'meta_key' => '', 'meta_value' => '', - 'authors' => '', 'parent' => -1 + 'authors' => '', 'parent' => -1, 'exclude_tree' => '' ); $r = wp_parse_args( $args, $defaults ); @@ -2170,6 +2182,22 @@ function &get_pages($args = '') { if ( $child_of || $hierarchical ) $pages = & get_page_children($child_of, $pages); + if ( !empty($exclude_tree) ) { + $exclude = array(); + + $exclude = (int) $exclude_tree; + $children = get_page_children($exclude, $pages); + $excludes = array(); + foreach ( $children as $child ) + $excludes[] = $child->ID; + $excludes[] = $exclude; + $total = count($pages); + for ( $i = 0; $i < $total; $i++ ) { + if ( in_array($pages[$i]->ID, $excludes) ) + unset($pages[$i]); + } + } + $cache[ $key ] = $pages; wp_cache_set( 'get_pages', $cache, 'posts' );