[wp-trac] [WordPress Trac] #18402: Confused page ordering if filter drops parent pages
WordPress Trac
noreply at wordpress.org
Tue Mar 20 09:20:35 UTC 2018
#18402: Confused page ordering if filter drops parent pages
-------------------------------------+-----------------------------
Reporter: erdnah | Owner: nacin
Type: enhancement | Status: closed
Priority: normal | Milestone:
Component: Posts, Post Types | Version: 3.2
Severity: normal | Resolution: wontfix
Keywords: ui-feedback needs-patch | Focuses: administration
-------------------------------------+-----------------------------
Changes (by ocean90):
* milestone: Future Release =>
Old 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:
>
> {{{
> #!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 :)
New 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:
{{{
#!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: <https://core.trac.wordpress.org/ticket/18402#comment:23>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list