In `get_page_children()`, only check `$page->ancestors` once to avoid duplicates when the function recurses. Adds an argument, `$ancestors`.
Fixes #18962. Built from https://develop.svn.wordpress.org/trunk@30246 git-svn-id: http://core.svn.wordpress.org/trunk@30246 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d5a9d63114
commit
03ea739661
|
@ -4278,17 +4278,19 @@ function get_page_by_title( $page_title, $output = OBJECT, $post_type = 'page' )
|
||||||
*
|
*
|
||||||
* @since 1.5.1
|
* @since 1.5.1
|
||||||
*
|
*
|
||||||
* @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) {
|
function get_page_children( $page_id, $pages, $ancestors = true ) {
|
||||||
$page_list = array();
|
$page_list = array();
|
||||||
foreach ( (array) $pages as $page ) {
|
foreach ( (array) $pages as $page ) {
|
||||||
if ( $page->post_parent == $page_id || in_array( $page_id, $page->ancestors ) ) {
|
if ( $page->post_parent == $page_id || ( $ancestors && in_array( $page_id, $page->ancestors ) ) ) {
|
||||||
$page_list[] = $page;
|
$page_list[] = $page;
|
||||||
if ( $children = get_page_children($page->ID, $pages) )
|
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;
|
return $page_list;
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.1-alpha-30245';
|
$wp_version = '4.1-alpha-30246';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue