WordPress.org

Make WordPress Core

Opened 22 months ago

Last modified 6 weeks ago

#18402 reviewing defect (bug)

Confused page ordering if filter drops parent pages

Reported by: erdnah Owned by: nacin
Priority: normal Milestone: 3.6
Component: Administration Version: 3.2.1
Severity: normal Keywords: has-patch 2nd-opinion ui-feedback
Cc:

Description

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:

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

if ( 0 == $page->post_parent )
    $top_level_pages[] = $page;
else 
    $children_pages[ $page->post_parent ][] = $page;

to

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 :)

Attachments (3)

21272-trashing-parents.jpg (205.3 KB) - added by pdclark 11 months ago.
Display of proposed changes and patched changes
21272.patch (1.5 KB) - added by pdclark 11 months ago.
Make changes recommended in report; also remove "Page Parent" text when parent is trashed.
18402.diff (1.4 KB) - added by DrewAPicture 6 weeks ago.

Download all attachments as: .zip

Change History (13)

comment:1 SergeyBiryukov22 months ago

  • Keywords needs-patch added

comment:2 erdnah22 months ago

  • Keywords has-patch added; needs-patch removed

comment:3 erdnah22 months ago

  • Keywords needs-patch added; has-patch removed

comment:4 erdnah22 months ago

Correction of my Example section:

It should become:

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

(one dash only of course, not two)

pdclark11 months ago

Display of proposed changes and patched changes

pdclark11 months ago

Make changes recommended in report; also remove "Page Parent" text when parent is trashed.

comment:5 pdclark11 months ago

  • Keywords has-patch added; needs-patch removed
  • Owner set to nacin
  • Status changed from new to reviewing

Attached a patch for the proposed changes, as well as a screenshot. It seemed awkward to me to display "Post Parent: X" when "X" had been trashed, so I also removed that text for that case. See the attached screenshot, 21272-trashing-parents.jpg.

comment:6 follow-up: MikeHansenMe10 months ago

  • Keywords 2nd-opinion added

Tested on 3.5-alpha-21751 and it works as described. My only question would be should "grandchild" then show "child" as the parent? ex (Grandchild | Parent Page : Child)

comment:7 in reply to: ↑ 6 pdclark3 months ago

  • Keywords ui-feedback added

Replying to MikeHansenMe:

Tested on 3.5-alpha-21751 and it works as described. My only question would be should "grandchild" then show "child" as the parent? ex (Grandchild | Parent Page : Child)

The code that adds the filter for "Parent Page:" to display is commented:

//sent level 0 by accident, by default, or because we don't know the actual level

Because this patch causes the child and grandchild page's hierarchical level to be set correctly (not sent in error or unknown), "Parent Page:" doesn't display for either the child or the grandchild. See the furthest-right window in this screenshot

Who should make the final call on this?

comment:8 SergeyBiryukov3 months ago

  • Milestone changed from Awaiting Review to 3.6

comment:9 SergeyBiryukov3 months ago

As noted in the IRC discussion, the patch would make the output more consistent with the default behavior of wp_list_pages().

DrewAPicture6 weeks ago

comment:10 DrewAPicture6 weeks ago

18402.diff adds an @since to the method docblock and completes the @return tag.

Note: See TracTickets for help on using tickets.