Ticket #11018: 11018_page_loop.diff

File 11018_page_loop.diff, 1.7 KB (added by hailin, 4 years ago)

patch

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

     
    15601560        $post = $global_post; 
    15611561} 
    15621562 
    1563 /* 
    1564  * display one row if the page doesn't have any children 
    1565  * otherwise, display the row and its children in subsequent rows 
    1566  */ 
    15671563/** 
    15681564 * {@internal Missing Short Description}} 
    15691565 * 
     
    15731569 * @param unknown_type $level 
    15741570 */ 
    15751571function display_page_row( $page, $level = 0 ) { 
    1576         global $post; 
     1572        global $post, $wpdb; 
    15771573        static $rowclass; 
    15781574 
    15791575        $post = $page; 
    15801576        setup_postdata($page); 
    15811577 
    15821578        if ( 0 == $level && (int)$page->post_parent > 0 ) { 
    1583                 //sent level 0 by accident, by default, or because we don't know the actual level 
     1579                /*  
     1580                 * sent level 0 by accident, by default, or because we don't know the actual level 
     1581                 * detect and fix possible loops here  
     1582                 */ 
    15841583                $find_main_page = (int)$page->post_parent; 
     1584         
     1585                $track_parents[] = $find_main_page;  
     1586                 
    15851587                while ( $find_main_page > 0 ) { 
    15861588                        $parent = get_page($find_main_page); 
    15871589 
     
    15911593                        $level++; 
    15921594                        $find_main_page = (int)$parent->post_parent; 
    15931595 
     1596                        if ( in_array( $find_main_page, $track_parents ) ) { 
     1597                                $parent->post_parent = 0;  
     1598                                $wpdb->query( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = '0' WHERE ID = %d", $parent->ID) ); 
     1599                                clean_page_cache( $parent->ID ); 
     1600                                break;  
     1601                        } else { 
     1602                                $track_parents[] = $find_main_page;  
     1603                        } 
     1604 
    15941605                        if ( !isset($parent_name) ) 
    15951606                                $parent_name = $parent->post_title; 
    15961607                }