Make WordPress Core

Ticket #15459: 15459.4.diff

File 15459.4.diff, 4.8 KB (added by nofearinc, 10 years ago)

fix the ID fetching if an object reference exists

  • wp-admin/includes/post.php

     
    985985                $query['order'] = 'asc';
    986986                $query['posts_per_page'] = -1;
    987987                $query['posts_per_archive_page'] = -1;
     988                $query['fields'] = 'id=>parent';
    988989        }
    989990
    990991        if ( ! empty( $q['show_sticky'] ) )
  • wp-admin/includes/class-wp-posts-list-table.php

     
    450450                $count = 0;
    451451                $start = ( $pagenum - 1 ) * $per_page;
    452452                $end = $start + $per_page;
     453                $to_display = array();
    453454
    454455                foreach ( $pages as $page ) {
    455456                        if ( $count >= $end )
    456457                                break;
    457458
    458459                        if ( $count >= $start ) {
    459                                 echo "\t";
    460                                 $this->single_row( $page, $level );
     460                                $to_display[$page->ID] = $level;
    461461                        }
    462462
    463463                        $count++;
    464464
    465465                        if ( isset( $children_pages ) )
    466                                 $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
     466                                $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
    467467                }
    468468
    469469                // If it is the last pagenum and there are orphaned pages, display them with paging as well.
     
    474474                                                break;
    475475
    476476                                        if ( $count >= $start ) {
    477                                                 echo "\t";
    478                                                 $this->single_row( $op, 0 );
     477                                                $to_display[$op->ID] = 0;
    479478                                        }
    480479
    481480                                        $count++;
    482481                                }
    483482                        }
    484483                }
     484
     485                $ids = array_keys( $to_display );
     486                _prime_post_caches( $ids );
     487
     488                if ( ! isset( $GLOBALS['post'] ) ) {
     489                        // touch_time() requires a global post set
     490                        $GLOBALS['post'] = array_shift( $ids );
     491                }
     492
     493                foreach ( $to_display as $page_id => $level ) {
     494                        echo "\t";
     495                        $this->single_row( $page_id, $level );
     496                }
    485497        }
    486498
    487499        /**
     
    496508         * @param int $level
    497509         * @param int $pagenum
    498510         * @param int $per_page
     511         * @param array $to_display list of pages to be displayed
    499512         */
    500         private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page ) {
     513        private function _page_rows( &$children_pages, &$count, $parent, $level, $pagenum, $per_page, &$to_display ) {
    501514
    502515                if ( ! isset( $children_pages[$parent] ) )
    503516                        return;
     
    515528                                $my_parents = array();
    516529                                $my_parent = $page->post_parent;
    517530                                while ( $my_parent ) {
    518                                         $my_parent = get_post( $my_parent );
     531                                        // Get the ID from the list or the attribute if my_parent is an object
     532                                        $parent_id = $my_parent;
     533                                        if ( is_object( $my_parent ) ) {
     534                                                $parent_id = $my_parent->ID;
     535                                        }
     536                                       
     537                                        $my_parent = get_post( $parent_id );
    519538                                        $my_parents[] = $my_parent;
    520539                                        if ( !$my_parent->post_parent )
    521540                                                break;
     
    523542                                }
    524543                                $num_parents = count( $my_parents );
    525544                                while ( $my_parent = array_pop( $my_parents ) ) {
    526                                         echo "\t";
    527                                         $this->single_row( $my_parent, $level - $num_parents );
     545                                        $to_display[$my_parent->ID] = $level - $num_parents;
    528546                                        $num_parents--;
    529547                                }
    530548                        }
    531549
    532550                        if ( $count >= $start ) {
    533                                 echo "\t";
    534                                 $this->single_row( $page, $level );
     551                                $to_display[$page->ID] = $level;
    535552                        }
    536553
    537554                        $count++;
    538555
    539                         $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page );
     556                        $this->_page_rows( $children_pages, $count, $page->ID, $level + 1, $pagenum, $per_page, $to_display );
    540557                }
    541558
    542559                unset( $children_pages[$parent] ); //required in order to keep track of orphans
     
    547564                static $alternate;
    548565
    549566                $global_post = get_post();
     567
     568                if ( is_integer( $post ) ) {
     569                        $post = get_post( $post );
     570                }
     571               
    550572                $GLOBALS['post'] = $post;
    551573                setup_postdata( $post );
    552574
  • wp-includes/class-wp.php

     
    2525         * @since 2.0.0
    2626         * @var array
    2727         */
    28         public $private_query_vars = array( 'offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in', 'post_parent', 'post_parent__in', 'post_parent__not_in' );
     28        public $private_query_vars = array( 'offset', 'posts_per_page', 'posts_per_archive_page', 'showposts', 'nopaging', 'post_type', 'post_status', 'category__in', 'category__not_in', 'category__and', 'tag__in', 'tag__not_in', 'tag__and', 'tag_slug__in', 'tag_slug__and', 'tag_id', 'post_mime_type', 'perm', 'comments_per_page', 'post__in', 'post__not_in', 'post_parent', 'post_parent__in', 'post_parent__not_in', 'fields' );
    2929
    3030        /**
    3131         * Extra query variables set by the user.