Make WordPress Core


Ignore:
Timestamp:
03/27/2014 01:17:41 AM (11 years ago)
Author:
wonderboymusic
Message:

Use wp_parse_id_list() when parsing exclude_tree in get_pages(). Add unit tests to ensure a URL string, array with string as value, and array with array as value for exclude_tree can be used to specify multiple IDs.

Props cgaffga, roothorick, hakre, tbrams for patches across the years.
Fixes #9153.

File:
1 edited

Legend:

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

    r27726 r27767  
    37433743        'exclude' => array(), 'include' => array(),
    37443744        'meta_key' => '', 'meta_value' => '',
    3745         'authors' => '', 'parent' => -1, 'exclude_tree' => '',
     3745        'authors' => '', 'parent' => -1, 'exclude_tree' => array(),
    37463746        'number' => '', 'offset' => 0,
    37473747        'post_type' => 'page', 'post_status' => 'publish',
     
    39253925        $pages = get_page_children($child_of, $pages);
    39263926
    3927     if ( !empty($exclude_tree) ) {
    3928         $exclude = (int) $exclude_tree;
    3929         $children = get_page_children($exclude, $pages);
    3930         $excludes = array();
    3931         foreach ( $children as $child )
    3932             $excludes[] = $child->ID;
    3933         $excludes[] = $exclude;
    3934         $num_pages = count($pages);
     3927    if ( ! empty( $exclude_tree ) ) {
     3928        $exclude = wp_parse_id_list( $exclude_tree );
     3929        foreach( $exclude as $id ) {
     3930            $children = get_page_children( $id, $pages );
     3931            foreach ( $children as $child ) {
     3932                $exclude[] = $child->ID;
     3933            }
     3934        }
     3935
     3936        $num_pages = count( $pages );
    39353937        for ( $i = 0; $i < $num_pages; $i++ ) {
    3936             if ( in_array($pages[$i]->ID, $excludes) )
    3937                 unset($pages[$i]);
     3938            if ( in_array( $pages[$i]->ID, $exclude ) ) {
     3939                unset( $pages[$i] );
     3940            }
    39383941        }
    39393942    }
Note: See TracChangeset for help on using the changeset viewer.