From d12eb2e38e03a7079c453f4d3e851cad7100ec02 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sun, 30 Nov 2014 06:05:24 +0000 Subject: [PATCH] Ensure uniqueness when returning page lists in `get_page_children()`. Fixes failing unit tests. Props boonebgorges. Reverts [30246]. Fixes #14477. Built from https://develop.svn.wordpress.org/trunk@30636 git-svn-id: http://core.svn.wordpress.org/trunk@30626 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 18 ++++++++++++++---- wp-includes/version.php | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 37f97d97fb..6ef8d85fca 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -4280,20 +4280,30 @@ function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' ) * * @param int $page_id Page ID. * @param array $pages List of pages' objects. - * @param bool $ancestors Whether to check a page's ancestors. * @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(); 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; if ( $children = get_page_children( $page->ID, $pages, false ) ) { $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; } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index 7f9ba14424..0f1dcf046d 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.1-beta2-30635'; +$wp_version = '4.1-beta2-30636'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.