Make WordPress Core

Ticket #11047: 11047_break_loop.diff

File 11047_break_loop.diff, 1.7 KB (added by hailin, 16 years ago)

correct patch

  • C:/xampp/htdocs/wordpress_trunk/wp-admin/includes/template.php

     
    15651565        $post = $global_post;
    15661566}
    15671567
    1568 /*
    1569  * display one row if the page doesn't have any children
    1570  * otherwise, display the row and its children in subsequent rows
    1571  */
    15721568/**
    15731569 * {@internal Missing Short Description}}
    15741570 *
     
    15781574 * @param unknown_type $level
    15791575 */
    15801576function display_page_row( $page, $level = 0 ) {
    1581         global $post;
     1577        global $post, $wpdb;
    15821578        static $rowclass;
    15831579
    15841580        $post = $page;
    15851581        setup_postdata($page);
    15861582
    15871583        if ( 0 == $level && (int)$page->post_parent > 0 ) {
    1588                 //sent level 0 by accident, by default, or because we don't know the actual level
     1584                /*
     1585                 * sent level 0 by accident, by default, or because we don't know the actual level
     1586                 * detect and fix possible loops here
     1587                 */
    15891588                $find_main_page = (int)$page->post_parent;
     1589       
     1590                $track_parents[] = $find_main_page;
     1591               
    15901592                while ( $find_main_page > 0 ) {
    15911593                        $parent = get_page($find_main_page);
    15921594
     
    15961598                        $level++;
    15971599                        $find_main_page = (int)$parent->post_parent;
    15981600
     1601                        if ( in_array( $find_main_page, $track_parents ) ) {
     1602                                $parent->post_parent = 0;
     1603                                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $parent->ID) );
     1604                                clean_page_cache( $parent->ID );
     1605                                break;
     1606                        } else {
     1607                                $track_parents[] = $find_main_page;
     1608                        }
     1609
    15991610                        if ( !isset($parent_name) )
    16001611                                $parent_name = $parent->post_title;
    16011612                }