Check for circular post parent dependencies. Exclude the current post and its children from the parent dropdown.
git-svn-id: https://develop.svn.wordpress.org/trunk@10129 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e1df6f154e
commit
cbef7dc6c4
|
@ -270,7 +270,7 @@ function page_attributes_meta_box($post){
|
|||
?>
|
||||
<h5><?php _e('Parent') ?></h5>
|
||||
<label class="hidden" for="parent_id"><?php _e('Page Parent') ?></label>
|
||||
<?php wp_dropdown_pages(array('selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('Main Page (no parent)'))); ?>
|
||||
<?php wp_dropdown_pages(array('exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('Main Page (no parent)'))); ?>
|
||||
<p><?php _e('You can arrange your pages in hierarchies, for example you could have an “About” page that has “Life Story” and “My Dog” pages under it. There are no limits to how deeply nested you can make pages.'); ?></p>
|
||||
<?php
|
||||
if ( 0 != count( get_page_templates() ) ) {
|
||||
|
|
|
@ -1417,6 +1417,18 @@ function wp_insert_post($postarr = array(), $wp_error = false) {
|
|||
else
|
||||
$post_parent = 0;
|
||||
|
||||
if ( !empty($post_ID) ) {
|
||||
if ( $post_parent == $post_ID ) {
|
||||
// Post can't be its own parent
|
||||
$post_parent = 0;
|
||||
} elseif ( !empty($post_parent) ) {
|
||||
$parent_post = get_post($post_parent);
|
||||
// Check for circular dependency
|
||||
if ( $parent_post->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' );
|
||||
|
||||
|
|
Loading…
Reference in New Issue