Ensure uniqueness when returning page lists in get_page_children()
. Fixes failing unit tests.
Props boonebgorges. Reverts [30246]. Fixes #14477. git-svn-id: https://develop.svn.wordpress.org/trunk@30636 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
2afe26faa5
commit
cb648b68e1
@ -4280,20 +4280,30 @@ function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' )
|
|||||||
*
|
*
|
||||||
* @param int $page_id Page ID.
|
* @param int $page_id Page ID.
|
||||||
* @param array $pages List of pages' objects.
|
* @param array $pages List of pages' objects.
|
||||||
* @param bool $ancestors Whether to check a page's ancestors.
|
|
||||||
* @return array List of page children.
|
* @return array List of page children.
|
||||||
*/
|
*/
|
||||||
function get_page_children( $page_id, $pages, $ancestors = true ) {
|
function get_page_children( $page_id, $pages ) {
|
||||||
$page_list = array();
|
$page_list = array();
|
||||||
foreach ( (array) $pages as $page ) {
|
foreach ( (array) $pages as $page ) {
|
||||||
if ( $page->post_parent == $page_id || ( $ancestors && in_array( $page_id, $page->ancestors ) ) ) {
|
if ( $page->post_parent == $page_id || in_array( $page_id, $page->ancestors ) ) {
|
||||||
$page_list[] = $page;
|
$page_list[] = $page;
|
||||||
if ( $children = get_page_children( $page->ID, $pages, false ) ) {
|
if ( $children = get_page_children( $page->ID, $pages, false ) ) {
|
||||||
$page_list = array_merge( $page_list, $children );
|
$page_list = array_merge( $page_list, $children );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $page_list;
|
|
||||||
|
// Ensure uniqueness.
|
||||||
|
$page_ids = array();
|
||||||
|
$unique_page_list = array();
|
||||||
|
foreach ( $page_list as $page_list_item ) {
|
||||||
|
if ( ! in_array( $page_list_item->ID, $page_ids ) ) {
|
||||||
|
$unique_page_list[] = $page_list_item;
|
||||||
|
$page_ids[] = $page_list_item->ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $unique_page_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user