Make WordPress Core

Changeset 30246


Ignore:
Timestamp:
11/05/2014 08:04:55 PM (10 years ago)
Author:
wonderboymusic
Message:

In get_page_children(), only check $page->ancestors once to avoid duplicates when the function recurses. Adds an argument, $ancestors.

Fixes #18962.

File:
1 edited

Legend:

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

    r30159 r30246  
    42794279 * @since 1.5.1
    42804280 *
    4281  * @param int   $page_id Page ID.
    4282  * @param array $pages   List of pages' objects.
     4281 * @param int   $page_id    Page ID.
     4282 * @param array $pages      List of pages' objects.
     4283 * @param bool  $ancestors  Whether to check a page's ancestors.
    42834284 * @return array List of page children.
    42844285 */
    4285 function get_page_children($page_id, $pages) {
     4286function get_page_children( $page_id, $pages, $ancestors = true ) {
    42864287    $page_list = array();
    42874288    foreach ( (array) $pages as $page ) {
    4288         if ( $page->post_parent == $page_id || in_array( $page_id, $page->ancestors ) ) {
     4289        if ( $page->post_parent == $page_id || ( $ancestors && in_array( $page_id, $page->ancestors ) ) ) {
    42894290            $page_list[] = $page;
    4290             if ( $children = get_page_children($page->ID, $pages) )
    4291                 $page_list = array_merge($page_list, $children);
     4291            if ( $children = get_page_children( $page->ID, $pages, false ) ) {
     4292                $page_list = array_merge( $page_list, $children );
     4293            }
    42924294        }
    42934295    }
Note: See TracChangeset for help on using the changeset viewer.