WordPress.org

Make WordPress Core

Changeset 30636


Ignore:
Timestamp:
11/30/2014 06:04:31 AM (5 years ago)
Author:
wonderboymusic
Message:

Ensure uniqueness when returning page lists in get_page_children(). Fixes failing unit tests.

Props boonebgorges.
Reverts [30246].
Fixes #14477.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r30629 r30636  
    42814281 * @param int   $page_id    Page ID.
    42824282 * @param array $pages      List of pages' objects.
    4283  * @param bool  $ancestors  Whether to check a page's ancestors.
    42844283 * @return array List of page children.
    42854284 */
    4286 function get_page_children( $page_id, $pages, $ancestors = true ) {
     4285function get_page_children( $page_id, $pages ) {
    42874286    $page_list = array();
    42884287    foreach ( (array) $pages as $page ) {
    4289         if ( $page->post_parent == $page_id || ( $ancestors && in_array( $page_id, $page->ancestors ) ) ) {
     4288        if ( $page->post_parent == $page_id || in_array( $page_id, $page->ancestors ) ) {
    42904289            $page_list[] = $page;
    42914290            if ( $children = get_page_children( $page->ID, $pages, false ) ) {
     
    42944293        }
    42954294    }
    4296     return $page_list;
     4295
     4296    // Ensure uniqueness.
     4297    $page_ids = array();
     4298    $unique_page_list = array();
     4299    foreach ( $page_list as $page_list_item ) {
     4300        if ( ! in_array( $page_list_item->ID, $page_ids ) ) {
     4301            $unique_page_list[] = $page_list_item;
     4302            $page_ids[] = $page_list_item->ID;
     4303        }
     4304    }
     4305
     4306    return $unique_page_list;
    42974307}
    42984308
Note: See TracChangeset for help on using the changeset viewer.