[wp-trac] [WordPress Trac] #18402: Confused page ordering if filter drops parent pages

WordPress Trac wp-trac at lists.automattic.com
Sun Aug 14 15:34:07 UTC 2011


#18402: Confused page ordering if filter drops parent pages
----------------------------+-----------------------------
 Reporter:  erdnah          |      Owner:
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  Administration  |    Version:  3.2.1
 Severity:  normal          |   Keywords:
----------------------------+-----------------------------
 = Problem =
 In Wordpress's page management section, the page ordering is confused if a
 page filter drops a page parent.

 Originally, I experienced this with the User Access Manager Plugin:
 http://wordpress.org/extend/plugins/user-access-manager/
 This plugin only shows allowed pages to the user.


 = Example =
 {{{
 Page A
 - Page A1
 -- Page A1.1
 -- Page A1.2
 }}}

 By dropping page A, the ordering becomes for example:

 {{{
 -- Page A1.1: Parent Page is Page A1
 -- Page A1.2: Parent Page is Page A1
 - Page A1: Parent Page is A
 }}}

 But should become:

 {{{
 Page A1: Parent Page is A
 -- Page A1.1
 -- Page A1.2
 }}}

 = Solution =
 The confusion results from the function `_display_rows_hierarchical`
 in `wp-admin/includes/class-wp-posts-list-table.php` which only adds pages
 to $top_level_pages whose parent is 0 – the wrong assumption here.

 By adding pages to $top_level_pages whose parent is either 0 or doesn't
 exist in $pages we get a usable order:
 So I added to the above-mentioned file:

 {{{
 #!php
 function is_parent_in_pages( $parent, $pages ) {
     foreach ( $pages as $page ) {
         if ( $page->ID == $parent ) return true;
     }
     return false;
 }
 }}}

 and changed `_display_rows_hierarchical`
 from

 {{{
 #!php
 if ( 0 == $page->post_parent )
     $top_level_pages[] = $page;
 else
     $children_pages[ $page->post_parent ][] = $page;
 }}}

 to

 {{{
 #!php
 if ( 0 == $page->post_parent || !$this->is_parent_in_pages(
 $page->post_parent, $pages ))
     $top_level_pages[] = $page;
 else
     $children_pages[ $page->post_parent ][] = $page;
 }}}


 And finally - in order to remove the leading dash of $top_level_pages - I
 removed
 the $level++ in function `single_row` (same file) below "`case 'title':`"


 Small change, better user experience :)

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/18402>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list