Ticket #12821: garyc40-12821-rev1.patch
File garyc40-12821-rev1.patch, 9.9 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 696b911..08a4267 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 c3bfa2b..75698f5 100644
function wp_dropdown_pages($args = '') { 762 762 ); 763 763 764 764 $r = wp_parse_args( $args, $defaults ); 765 766 $get_pages_args = array_intersect_key( $r, array( 'depth' => '', 'child_of' => '' ) ); 767 $get_pages_args['posts_per_page'] = -1; 768 $get_pages_args['nopaging'] = true; 765 769 extract( $r, EXTR_SKIP ); 766 770 767 $pages = get_pages($ r);771 $pages = get_pages($get_pages_args); 768 772 $output = ''; 769 773 $name = esc_attr($name); 770 774 // 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 aa83f55..472c8a4 100644
function set_post_type( $post_id = 0, $post_type = 'post' ) { 1323 1323 */ 1324 1324 function get_posts($args = null) { 1325 1325 $defaults = array( 1326 'numberposts' => 5, 'offset' => 0, 1327 'category' => 0, 'orderby' => 'post_date', 1326 'numberposts' => 5, 'offset' => 0, 'child_of' => 0, 1327 'category' => 0, 'orderby' => 'post_date', 'depth' => 0, 1328 1328 'order' => 'DESC', 'include' => array(), 1329 1329 'exclude' => array(), 'meta_key' => '', 1330 1330 'meta_value' =>'', 'post_type' => 'post', 1331 'suppress_filters' => true 1331 'suppress_filters' => true, 'author' => '', 1332 1332 ); 1333 1333 1334 1334 $r = wp_parse_args( $args, $defaults ); … … function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) 3185 3185 * @param array $pages List of pages' objects. 3186 3186 * @return array 3187 3187 */ 3188 function &get_page_children( $page_id, $pages) {3188 function &get_page_children( $page_id, $pages, $field = 'all' ) { 3189 3189 $page_list = array(); 3190 3190 foreach ( (array) $pages as $page ) { 3191 if ( $page->post_parent == $page_id ) { 3192 $page_list[] = $page; 3191 if ( $page->page_parent == $page_id ) { 3192 if ( $field == 'all' ) { 3193 $page_list[] = $page; 3194 } else { 3195 $page_list[] = $page->$field; 3196 } 3193 3197 if ( $children = get_page_children($page->ID, $pages) ) 3194 3198 $page_list = array_merge($page_list, $children); 3195 3199 } … … function get_page_uri($page) { 3282 3286 * @param mixed $args Optional. Array or string of options that overrides defaults. 3283 3287 * @return array List of pages matching defaults or $args 3284 3288 */ 3285 function &get_pages($args = '') {3289 function get_pages($args = '') { 3286 3290 global $wpdb; 3291 3292 // matching old arguments with get_posts' arguments 3293 if ( isset( $args['parent'] ) ) { 3294 $args['post_parent'] = $args['parent']; 3295 } 3296 if ( isset( $args['sort_order'] ) ) { 3297 $args['order'] = $args['sort_order']; 3298 } 3299 if ( isset( $args['sort_column'] ) ) { 3300 $args['order_by'] = $args['sort_column']; 3301 } 3302 if ( isset( $args['number'] ) ) { 3303 $args['numberposts'] = $args['number']; 3304 } 3305 if ( isset( $args['authors'] ) ) { 3306 $args['author'] = $args['authors']; 3307 } 3287 3308 3288 3309 $defaults = array( 3289 'child_of' => 0, ' sort_order' => 'ASC',3290 ' sort_column' => 'post_title', 'hierarchical' => 1,3310 'child_of' => 0, 'order' => 'ASC', 3311 'order_by' => 'post_title', 'hierarchical' => 1, 3291 3312 'exclude' => array(), 'include' => array(), 3292 3313 'meta_key' => '', 'meta_value' => '', 3293 'authors' => '', ' parent' => -1, 'exclude_tree' => '',3294 'number ' => '', 'offset' => 0,3314 'authors' => '', 'author' => '', 'parent' => -1, 'post_parent' => -1, 'exclude_tree' => '', 3315 'numberposts' => '', 'number' => '', 'offset' => 0, 3295 3316 'post_type' => 'page', 'post_status' => 'publish', 3317 'sort_column' => 'post_title', 'sort_order' => 'ASC', 3296 3318 ); 3297 3319 3298 3320 $r = wp_parse_args( $args, $defaults ); 3299 extract( $r, EXTR_SKIP ); 3300 $number = (int) $number; 3301 $offset = (int) $offset; 3302 3303 // Make sure the post type is hierarchical 3304 $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); 3305 if ( !in_array( $post_type, $hierarchical_post_types ) ) 3306 return false; 3307 3308 // Make sure we have a valid post status 3309 if ( !in_array($post_status, get_post_stati()) ) 3310 return false; 3311 3312 $cache = array(); 3313 $key = md5( serialize( compact(array_keys($defaults)) ) ); 3314 if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) { 3315 if ( is_array($cache) && isset( $cache[ $key ] ) ) { 3316 $pages = apply_filters('get_pages', $cache[ $key ], $r ); 3317 return $pages; 3318 } 3319 } 3320 3321 if ( !is_array($cache) ) 3322 $cache = array(); 3323 3324 $inclusions = ''; 3325 if ( !empty($include) ) { 3326 $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include 3327 $parent = -1; 3328 $exclude = ''; 3329 $meta_key = ''; 3330 $meta_value = ''; 3331 $hierarchical = false; 3332 $incpages = wp_parse_id_list( $include ); 3333 if ( ! empty( $incpages ) ) { 3334 foreach ( $incpages as $incpage ) { 3335 if (empty($inclusions)) 3336 $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage); 3337 else 3338 $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage); 3339 } 3340 } 3341 } 3342 if (!empty($inclusions)) 3343 $inclusions .= ')'; 3344 3345 $exclusions = ''; 3346 if ( !empty($exclude) ) { 3347 $expages = wp_parse_id_list( $exclude ); 3348 if ( ! empty( $expages ) ) { 3349 foreach ( $expages as $expage ) { 3350 if (empty($exclusions)) 3351 $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage); 3352 else 3353 $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage); 3354 } 3355 } 3356 } 3357 if (!empty($exclusions)) 3358 $exclusions .= ')'; 3359 3360 $author_query = ''; 3361 if (!empty($authors)) { 3362 $post_authors = preg_split('/[\s,]+/',$authors); 3363 3364 if ( ! empty( $post_authors ) ) { 3365 foreach ( $post_authors as $post_author ) { 3366 //Do we have an author id or an author login? 3367 if ( 0 == intval($post_author) ) { 3368 $post_author = get_userdatabylogin($post_author); 3369 if ( empty($post_author) ) 3370 continue; 3371 if ( empty($post_author->ID) ) 3372 continue; 3373 $post_author = $post_author->ID; 3374 } 3375 3376 if ( '' == $author_query ) 3377 $author_query = $wpdb->prepare(' post_author = %d ', $post_author); 3378 else 3379 $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); 3380 } 3381 if ( '' != $author_query ) 3382 $author_query = " AND ($author_query)"; 3383 } 3384 } 3385 3386 $join = ''; 3387 $where = "$exclusions $inclusions "; 3388 if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) { 3389 $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )"; 3390 3391 // meta_key and meta_value might be slashed 3392 $meta_key = stripslashes($meta_key); 3393 $meta_value = stripslashes($meta_value); 3394 if ( ! empty( $meta_key ) ) 3395 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key); 3396 if ( ! empty( $meta_value ) ) 3397 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value); 3398 3399 } 3400 3401 if ( $parent >= 0 ) 3402 $where .= $wpdb->prepare(' AND post_parent = %d ', $parent); 3403 3404 $where_post_type = $wpdb->prepare( "post_type = '%s' AND post_status = '%s'", $post_type, $post_status ); 3405 3406 $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where "; 3407 $query .= $author_query; 3408 $query .= " ORDER BY " . $sort_column . " " . $sort_order ; 3409 3410 if ( !empty($number) ) 3411 $query .= ' LIMIT ' . $offset . ',' . $number; 3412 3413 $pages = $wpdb->get_results($query); 3414 3415 if ( empty($pages) ) { 3416 $pages = apply_filters('get_pages', array(), $r); 3417 return $pages; 3418 } 3419 3420 // Sanitize before caching so it'll only get done once 3421 $num_pages = count($pages); 3422 for ($i = 0; $i < $num_pages; $i++) { 3423 $pages[$i] = sanitize_post($pages[$i], 'raw'); 3424 } 3425 3426 // Update cache. 3427 update_page_cache($pages); 3428 3429 if ( $child_of || $hierarchical ) 3430 $pages = & get_page_children($child_of, $pages); 3431 3432 if ( !empty($exclude_tree) ) { 3433 $exclude = (int) $exclude_tree; 3434 $children = get_page_children($exclude, $pages); 3435 $excludes = array(); 3436 foreach ( $children as $child ) 3437 $excludes[] = $child->ID; 3438 $excludes[] = $exclude; 3439 $num_pages = count($pages); 3440 for ( $i = 0; $i < $num_pages; $i++ ) { 3441 if ( in_array($pages[$i]->ID, $excludes) ) 3442 unset($pages[$i]); 3443 } 3444 } 3445 3446 $cache[ $key ] = $pages; 3447 wp_cache_set( 'get_pages', $cache, 'posts' ); 3448 3449 $pages = apply_filters('get_pages', $pages, $r); 3450 3321 $pages = get_posts( $r ); 3451 3322 return $pages; 3452 3323 } 3453 3324 -
wp-includes/query.php
diff --git wp-includes/query.php wp-includes/query.php index 0cd192e..16f3185 100644
class WP_Query { 1892 1892 $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)"; 1893 1893 } 1894 1894 1895 if ( is_numeric($q['post_parent']) )1895 if ( is_numeric($q['post_parent']) && $q['post_parent'] > 0 ) 1896 1896 $where .= $wpdb->prepare( " AND $wpdb->posts.post_parent = %d ", $q['post_parent'] ); 1897 1897 1898 1898 if ( $q['page_id'] ) { … … class WP_Query { 2375 2375 $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); 2376 2376 $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']); 2377 2377 } 2378 2379 if ( ! empty( $q['child_of'] ) && ! empty( $q['hierarchical'] ) ) { 2380 $this->posts = get_page_children( $q['child_of'], $this->posts ); 2381 } 2382 2383 if ( ! empty( $q['exclude_tree'] ) ) { 2384 $exclude_tree = (int) $q['exclude_tree']; 2385 $excluded_children = get_page_children( $exclude_tree, $this->posts, 'ID' ); 2386 $excluded_children[] = $exclude_tree; 2387 2388 foreach ( $this->posts as $index => $post ) { 2389 if ( in_array( $post->ID, $excluded_children ) ) { 2390 unset( $this->posts[$index] ); 2391 } 2392 } 2393 } 2378 2394 2379 2395 // Check post status to determine if post should be displayed. 2380 2396 if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) { … … class WP_Query { 2477 2493 2478 2494 return $this->posts; 2479 2495 } 2480 2496 2481 2497 /** 2482 2498 * Set up the next post and iterate current post index. 2483 2499 *