Ticket #12821: 12821.3.diff
File 12821.3.diff, 10.7 KB (added by , 14 years ago) |
---|
-
wp-admin/includes/class-wp-posts-list-table.php
diff --git wp-admin/includes/class-wp-posts-list-table.php wp-admin/includes/class-wp-posts-list-table.php index e623ab5..3519e51 100644
class WP_Posts_List_Table extends WP_List_Table { 340 340 $level = 0; 341 341 342 342 if ( ! $pages ) { 343 $pages = get_pages( array( ' sort_column' => 'menu_order' ) );343 $pages = get_pages( array( 'order_by' => 'menu_order' ) ); 344 344 345 345 if ( ! $pages ) 346 346 return false; -
wp-includes/post-template.php
diff --git wp-includes/post-template.php wp-includes/post-template.php index bf4671b..ffb7275 100644
function the_meta() { 756 756 */ 757 757 function wp_dropdown_pages($args = '') { 758 758 $defaults = array( 759 'depth' => 0, 'child_of' => 0,760 759 'selected' => 0, 'echo' => 1, 761 760 'name' => 'page_id', 'id' => '', 762 761 'show_option_none' => '', 'show_option_no_change' => '', 763 'option_none_value' => '' 762 'option_none_value' => '', 763 'depth' => 0, 764 764 ); 765 765 766 // pick out only arguments which are to be passed to get_pages() 767 // these arguments will be wp_parse_args() inside get_pages() 768 $get_pages_args = array_diff_key( $args, $defaults ); 769 $pages = get_pages($get_pages_args); 770 766 771 $r = wp_parse_args( $args, $defaults ); 767 772 extract( $r, EXTR_SKIP ); 768 773 769 $pages = get_pages($r);770 774 $output = ''; 771 775 $name = esc_attr($name); 772 776 // Back-compat with old system where both id and name were based on $name argument -
wp-includes/post.php
diff --git wp-includes/post.php wp-includes/post.php index 0acf641..7763c25 100644
function set_post_type( $post_id = 0, $post_type = 'post' ) { 1330 1330 */ 1331 1331 function get_posts($args = null) { 1332 1332 $defaults = array( 1333 'numberposts' => 5, 'offset' => 0, 1333 'numberposts' => 5, 'offset' => 0, 'child_of' => 0, 1334 1334 'category' => 0, 'orderby' => 'post_date', 1335 1335 'order' => 'DESC', 'include' => array(), 1336 1336 'exclude' => array(), 'meta_key' => '', 1337 1337 'meta_value' =>'', 'post_type' => 'post', 1338 'suppress_filters' => true 1338 'suppress_filters' => true, 'author' => '', 1339 1339 ); 1340 1340 1341 1341 $r = wp_parse_args( $args, $defaults ); … … function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) 3192 3192 * @param array $pages List of pages' objects. 3193 3193 * @return array 3194 3194 */ 3195 function &get_page_children( $page_id, $pages) {3195 function &get_page_children( $page_id, $pages, $field = 'all' ) { 3196 3196 $page_list = array(); 3197 3197 foreach ( (array) $pages as $page ) { 3198 3198 if ( $page->post_parent == $page_id ) { 3199 $page_list[] = $page; 3199 if ( $field == 'all' ) { 3200 $page_list[] = $page; 3201 } else { 3202 $page_list[] = $page->$field; 3203 } 3200 3204 if ( $children = get_page_children($page->ID, $pages) ) 3201 3205 $page_list = array_merge($page_list, $children); 3202 3206 } … … function get_page_uri($page) { 3289 3293 * @param mixed $args Optional. Array or string of options that overrides defaults. 3290 3294 * @return array List of pages matching defaults or $args 3291 3295 */ 3292 function &get_pages($args = '') {3296 function get_pages($args = '') { 3293 3297 global $wpdb; 3294 3298 3299 // matching old arguments with get_posts' arguments 3300 if ( isset( $args['parent'] ) ) { 3301 $args['post_parent'] = $args['parent']; 3302 } 3303 if ( isset( $args['sort_order'] ) ) { 3304 $args['order'] = $args['sort_order']; 3305 } 3306 if ( isset( $args['sort_column'] ) ) { 3307 $args['order_by'] = $args['sort_column']; 3308 } 3309 if ( isset( $args['number'] ) ) { 3310 $args['numberposts'] = $args['number']; 3311 } 3312 if ( isset( $args['authors'] ) ) { 3313 $args['author'] = $args['authors']; 3314 } 3315 3295 3316 $defaults = array( 3296 'child_of' => 0, ' sort_order' => 'ASC',3297 ' sort_column' => 'post_title', 'hierarchical' => 1,3317 'child_of' => 0, 'order' => 'ASC', 3318 'order_by' => 'post_title', 'hierarchical' => 1, 3298 3319 'exclude' => array(), 'include' => array(), 3299 3320 'meta_key' => '', 'meta_value' => '', 3300 'authors' => '', ' parent' => -1, 'exclude_tree' => '',3301 'number ' => '', 'offset' => 0,3321 'authors' => '', 'author' => '', 'parent' => -1, 'post_parent' => -1, 'exclude_tree' => '', 3322 'numberposts' => '', 'number' => '', 'offset' => 0, 3302 3323 'post_type' => 'page', 'post_status' => 'publish', 3324 'sort_column' => 'post_title', 'sort_order' => 'ASC', 3325 'posts_per_page' => -1, 'nopaging' => true, 3303 3326 ); 3304 3327 3305 3328 $r = wp_parse_args( $args, $defaults ); 3306 extract( $r, EXTR_SKIP ); 3307 $number = (int) $number; 3308 $offset = (int) $offset; 3309 3310 // Make sure the post type is hierarchical 3311 $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); 3312 if ( !in_array( $post_type, $hierarchical_post_types ) ) 3313 return false; 3314 3315 // Make sure we have a valid post status 3316 if ( !in_array($post_status, get_post_stati()) ) 3317 return false; 3318 3319 $cache = array(); 3320 $key = md5( serialize( compact(array_keys($defaults)) ) ); 3321 if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) { 3322 if ( is_array($cache) && isset( $cache[ $key ] ) ) { 3323 $pages = apply_filters('get_pages', $cache[ $key ], $r ); 3324 return $pages; 3325 } 3326 } 3327 3328 if ( !is_array($cache) ) 3329 $cache = array(); 3330 3331 $inclusions = ''; 3332 if ( !empty($include) ) { 3333 $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include 3334 $parent = -1; 3335 $exclude = ''; 3336 $meta_key = ''; 3337 $meta_value = ''; 3338 $hierarchical = false; 3339 $incpages = wp_parse_id_list( $include ); 3340 if ( ! empty( $incpages ) ) { 3341 foreach ( $incpages as $incpage ) { 3342 if (empty($inclusions)) 3343 $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage); 3344 else 3345 $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage); 3346 } 3347 } 3348 } 3349 if (!empty($inclusions)) 3350 $inclusions .= ')'; 3351 3352 $exclusions = ''; 3353 if ( !empty($exclude) ) { 3354 $expages = wp_parse_id_list( $exclude ); 3355 if ( ! empty( $expages ) ) { 3356 foreach ( $expages as $expage ) { 3357 if (empty($exclusions)) 3358 $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage); 3359 else 3360 $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage); 3361 } 3362 } 3363 } 3364 if (!empty($exclusions)) 3365 $exclusions .= ')'; 3366 3367 $author_query = ''; 3368 if (!empty($authors)) { 3369 $post_authors = preg_split('/[\s,]+/',$authors); 3370 3371 if ( ! empty( $post_authors ) ) { 3372 foreach ( $post_authors as $post_author ) { 3373 //Do we have an author id or an author login? 3374 if ( 0 == intval($post_author) ) { 3375 $post_author = get_userdatabylogin($post_author); 3376 if ( empty($post_author) ) 3377 continue; 3378 if ( empty($post_author->ID) ) 3379 continue; 3380 $post_author = $post_author->ID; 3381 } 3382 3383 if ( '' == $author_query ) 3384 $author_query = $wpdb->prepare(' post_author = %d ', $post_author); 3385 else 3386 $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); 3387 } 3388 if ( '' != $author_query ) 3389 $author_query = " AND ($author_query)"; 3390 } 3391 } 3392 3393 $join = ''; 3394 $where = "$exclusions $inclusions "; 3395 if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) { 3396 $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )"; 3397 3398 // meta_key and meta_value might be slashed 3399 $meta_key = stripslashes($meta_key); 3400 $meta_value = stripslashes($meta_value); 3401 if ( ! empty( $meta_key ) ) 3402 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key); 3403 if ( ! empty( $meta_value ) ) 3404 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value); 3405 3406 } 3407 3408 if ( $parent >= 0 ) 3409 $where .= $wpdb->prepare(' AND post_parent = %d ', $parent); 3410 3411 $where_post_type = $wpdb->prepare( "post_type = '%s' AND post_status = '%s'", $post_type, $post_status ); 3412 3413 $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where "; 3414 $query .= $author_query; 3415 $query .= " ORDER BY " . $sort_column . " " . $sort_order ; 3416 3417 if ( !empty($number) ) 3418 $query .= ' LIMIT ' . $offset . ',' . $number; 3419 3420 $pages = $wpdb->get_results($query); 3421 3422 if ( empty($pages) ) { 3423 $pages = apply_filters('get_pages', array(), $r); 3424 return $pages; 3425 } 3426 3427 // Sanitize before caching so it'll only get done once 3428 $num_pages = count($pages); 3429 for ($i = 0; $i < $num_pages; $i++) { 3430 $pages[$i] = sanitize_post($pages[$i], 'raw'); 3431 } 3432 3433 // Update cache. 3434 update_page_cache($pages); 3435 3436 if ( $child_of || $hierarchical ) 3437 $pages = & get_page_children($child_of, $pages); 3438 3439 if ( !empty($exclude_tree) ) { 3440 $exclude = (int) $exclude_tree; 3441 $children = get_page_children($exclude, $pages); 3442 $excludes = array(); 3443 foreach ( $children as $child ) 3444 $excludes[] = $child->ID; 3445 $excludes[] = $exclude; 3446 $num_pages = count($pages); 3447 for ( $i = 0; $i < $num_pages; $i++ ) { 3448 if ( in_array($pages[$i]->ID, $excludes) ) 3449 unset($pages[$i]); 3450 } 3451 } 3452 3453 $cache[ $key ] = $pages; 3454 wp_cache_set( 'get_pages', $cache, 'posts' ); 3455 3456 $pages = apply_filters('get_pages', $pages, $r); 3457 3329 $pages = get_posts( $r ); 3330 $pages = apply_filters( 'get_pages', $pages, $r ); 3458 3331 return $pages; 3459 3332 } 3460 3333 -
wp-includes/query.php
diff --git wp-includes/query.php wp-includes/query.php index 3389232..66cbda9 100644
class WP_Query { 2108 2108 $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)"; 2109 2109 } 2110 2110 2111 if ( is_numeric($q['post_parent']) )2111 if ( is_numeric($q['post_parent']) && $q['post_parent'] > 0 ) 2112 2112 $where .= $wpdb->prepare( " AND $wpdb->posts.post_parent = %d ", $q['post_parent'] ); 2113 2113 2114 2114 if ( $q['page_id'] ) { … … class WP_Query { 2604 2604 $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); 2605 2605 $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']); 2606 2606 } 2607 2608 if ( ! empty( $q['child_of'] ) && ! empty( $q['hierarchical'] ) ) { 2609 $this->posts = get_page_children( $q['child_of'], $this->posts ); 2610 } 2611 2612 if ( ! empty( $q['exclude_tree'] ) ) { 2613 $exclude_tree = (int) $q['exclude_tree']; 2614 $excluded_children = get_page_children( $exclude_tree, $this->posts, 'ID' ); 2615 $excluded_children[] = $exclude_tree; 2616 2617 foreach ( $this->posts as $index => $post ) { 2618 if ( in_array( $post->ID, $excluded_children ) ) { 2619 unset( $this->posts[$index] ); 2620 } 2621 } 2622 } 2607 2623 2608 2624 // Check post status to determine if post should be displayed. 2609 2625 if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) { … … class WP_Query { 2691 2707 $this->posts = apply_filters_ref_array('the_posts', array( $this->posts, &$this ) ); 2692 2708 2693 2709 $this->post_count = count($this->posts); 2694 2710 2695 2711 // Sanitize before caching so it'll only get done once 2696 for ( $i = 0; $i < $this->post_count; $i++) {2697 $this->posts[$ i] = sanitize_post($this->posts[$i], 'raw');2712 foreach ( $this->posts as $key => $post ) { 2713 $this->posts[$key] = sanitize_post( $this->posts[$key], 'raw' ); 2698 2714 } 2699 2715 2700 2716 if ( $q['cache_results'] ) … … class WP_Query { 2706 2722 2707 2723 return $this->posts; 2708 2724 } 2709 2725 2710 2726 /** 2711 2727 * Set up the next post and iterate current post index. 2712 2728 *