Make WordPress Core

Changeset 10129


Ignore:
Timestamp:
12/08/2008 07:29:42 PM (16 years ago)
Author:
ryan
Message:

Check for circular post parent dependencies. Exclude the current post and its children from the parent dropdown.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/edit-page-form.php

    r10094 r10129  
    271271<h5><?php _e('Parent') ?></h5>
    272272<label class="hidden" for="parent_id"><?php _e('Page Parent') ?></label>
    273 <?php wp_dropdown_pages(array('selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('Main Page (no parent)'))); ?>
     273<?php wp_dropdown_pages(array('exclude_tree' => $post->ID, 'selected' => $post->post_parent, 'name' => 'parent_id', 'show_option_none' => __('Main Page (no parent)'))); ?>
    274274<p><?php _e('You can arrange your pages in hierarchies, for example you could have an &#8220;About&#8221; page that has &#8220;Life Story&#8221; and &#8220;My Dog&#8221; pages under it. There are no limits to how deeply nested you can make pages.'); ?></p>
    275275<?php
  • trunk/wp-includes/post.php

    r10088 r10129  
    14181418        $post_parent = 0;
    14191419
     1420    if ( !empty($post_ID) ) {
     1421        if ( $post_parent == $post_ID ) {
     1422            // Post can't be its own parent
     1423            $post_parent = 0;
     1424        } elseif ( !empty($post_parent) ) {
     1425            $parent_post = get_post($post_parent);
     1426            // Check for circular dependency
     1427            if ( $parent_post->post_parent == $post_ID )
     1428                $post_parent = 0;
     1429        }
     1430    }
     1431
    14201432    if ( isset($menu_order) )
    14211433        $menu_order = (int) $menu_order;
     
    20602072        'exclude' => '', 'include' => '',
    20612073        'meta_key' => '', 'meta_value' => '',
    2062         'authors' => '', 'parent' => -1
     2074        'authors' => '', 'parent' => -1, 'exclude_tree' => ''
    20632075    );
    20642076
     
    21702182    if ( $child_of || $hierarchical )
    21712183        $pages = & get_page_children($child_of, $pages);
     2184
     2185    if ( !empty($exclude_tree) ) {
     2186        $exclude = array();
     2187       
     2188        $exclude = (int) $exclude_tree;
     2189        $children = get_page_children($exclude, $pages);
     2190        $excludes = array();
     2191        foreach ( $children as $child )
     2192            $excludes[] = $child->ID;
     2193        $excludes[] = $exclude;
     2194        $total = count($pages);
     2195        for ( $i = 0; $i < $total; $i++ ) {
     2196            if ( in_array($pages[$i]->ID, $excludes) )
     2197                unset($pages[$i]);
     2198        }
     2199    }
    21722200
    21732201    $cache[ $key ] = $pages;
Note: See TracChangeset for help on using the changeset viewer.