Make WordPress Core


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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.