Ticket #12821: garyc40-12821-rev2.patch
File garyc40-12821-rev2.patch, 10.8 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 f25ca4b..0ed5bba 100644
class WP_Posts_List_Table extends WP_List_Table { 339 339 $level = 0; 340 340 341 341 if ( ! $pages ) { 342 $pages = get_pages( array( ' sort_column' => 'menu_order' ) );342 $pages = get_pages( array( 'order_by' => 'menu_order' ) ); 343 343 344 344 if ( ! $pages ) 345 345 return false; -
wp-includes/post-template.php
diff --git wp-includes/post-template.php wp-includes/post-template.php index c3bfa2b..99e39a8 100644
function the_meta() { 754 754 */ 755 755 function wp_dropdown_pages($args = '') { 756 756 $defaults = array( 757 'depth' => 0, 'child_of' => 0,758 757 'selected' => 0, 'echo' => 1, 759 758 'name' => 'page_id', 'id' => '', 760 759 'show_option_none' => '', 'show_option_no_change' => '', 761 'option_none_value' => '' 760 'option_none_value' => '', 761 'depth' => 0, 762 762 ); 763 763 764 // pick out only arguments which are to be passed to get_pages() 765 // these arguments will be wp_parse_args() inside get_pages() 766 $get_pages_args = array_diff_key( $args, $defaults ); 767 $pages = get_pages($get_pages_args); 768 764 769 $r = wp_parse_args( $args, $defaults ); 765 770 extract( $r, EXTR_SKIP ); 766 771 767 $pages = get_pages($r);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 b4dea59..678a521 100644
function set_post_type( $post_id = 0, $post_type = 'post' ) { 1328 1328 */ 1329 1329 function get_posts($args = null) { 1330 1330 $defaults = array( 1331 'numberposts' => 5, 'offset' => 0, 1332 'category' => 0, 'orderby' => 'post_date', 1331 'numberposts' => 5, 'offset' => 0, 'child_of' => 0, 1332 'category' => 0, 'orderby' => 'post_date', 'depth' => 0, 1333 1333 'order' => 'DESC', 'include' => array(), 1334 1334 'exclude' => array(), 'meta_key' => '', 1335 1335 'meta_value' =>'', 'post_type' => 'post', 1336 'suppress_filters' => true 1336 'suppress_filters' => true, 'author' => '', 1337 1337 ); 1338 1338 1339 1339 $r = wp_parse_args( $args, $defaults ); … … function get_page_by_title($page_title, $output = OBJECT, $post_type = 'page' ) 3190 3190 * @param array $pages List of pages' objects. 3191 3191 * @return array 3192 3192 */ 3193 function &get_page_children( $page_id, $pages) {3193 function &get_page_children( $page_id, $pages, $field = 'all' ) { 3194 3194 $page_list = array(); 3195 3195 foreach ( (array) $pages as $page ) { 3196 3196 if ( $page->post_parent == $page_id ) { 3197 $page_list[] = $page; 3197 if ( $field == 'all' ) { 3198 $page_list[] = $page; 3199 } else { 3200 $page_list[] = $page->$field; 3201 } 3198 3202 if ( $children = get_page_children($page->ID, $pages) ) 3199 3203 $page_list = array_merge($page_list, $children); 3200 3204 } … … function get_page_uri($page) { 3287 3291 * @param mixed $args Optional. Array or string of options that overrides defaults. 3288 3292 * @return array List of pages matching defaults or $args 3289 3293 */ 3290 function &get_pages($args = '') {3294 function get_pages($args = '') { 3291 3295 global $wpdb; 3292 3296 3297 // matching old arguments with get_posts' arguments 3298 if ( isset( $args['parent'] ) ) { 3299 $args['post_parent'] = $args['parent']; 3300 } 3301 if ( isset( $args['sort_order'] ) ) { 3302 $args['order'] = $args['sort_order']; 3303 } 3304 if ( isset( $args['sort_column'] ) ) { 3305 $args['order_by'] = $args['sort_column']; 3306 } 3307 if ( isset( $args['number'] ) ) { 3308 $args['numberposts'] = $args['number']; 3309 } 3310 if ( isset( $args['authors'] ) ) { 3311 $args['author'] = $args['authors']; 3312 } 3313 3293 3314 $defaults = array( 3294 'child_of' => 0, ' sort_order' => 'ASC',3295 ' sort_column' => 'post_title', 'hierarchical' => 1,3315 'child_of' => 0, 'order' => 'ASC', 3316 'order_by' => 'post_title', 'hierarchical' => 1, 3296 3317 'exclude' => array(), 'include' => array(), 3297 3318 'meta_key' => '', 'meta_value' => '', 3298 'authors' => '', ' parent' => -1, 'exclude_tree' => '',3299 'number ' => '', 'offset' => 0,3319 'authors' => '', 'author' => '', 'parent' => -1, 'post_parent' => -1, 'exclude_tree' => '', 3320 'numberposts' => '', 'number' => '', 'offset' => 0, 3300 3321 'post_type' => 'page', 'post_status' => 'publish', 3322 'sort_column' => 'post_title', 'sort_order' => 'ASC', 3323 'posts_per_page' => -1, 'nopaging' => true, 3301 3324 ); 3302 3325 3303 3326 $r = wp_parse_args( $args, $defaults ); 3304 extract( $r, EXTR_SKIP ); 3305 $number = (int) $number; 3306 $offset = (int) $offset; 3307 3308 // Make sure the post type is hierarchical 3309 $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) ); 3310 if ( !in_array( $post_type, $hierarchical_post_types ) ) 3311 return false; 3312 3313 // Make sure we have a valid post status 3314 if ( !in_array($post_status, get_post_stati()) ) 3315 return false; 3316 3317 $cache = array(); 3318 $key = md5( serialize( compact(array_keys($defaults)) ) ); 3319 if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) { 3320 if ( is_array($cache) && isset( $cache[ $key ] ) ) { 3321 $pages = apply_filters('get_pages', $cache[ $key ], $r ); 3322 return $pages; 3323 } 3324 } 3325 3326 if ( !is_array($cache) ) 3327 $cache = array(); 3328 3329 $inclusions = ''; 3330 if ( !empty($include) ) { 3331 $child_of = 0; //ignore child_of, parent, exclude, meta_key, and meta_value params if using include 3332 $parent = -1; 3333 $exclude = ''; 3334 $meta_key = ''; 3335 $meta_value = ''; 3336 $hierarchical = false; 3337 $incpages = wp_parse_id_list( $include ); 3338 if ( ! empty( $incpages ) ) { 3339 foreach ( $incpages as $incpage ) { 3340 if (empty($inclusions)) 3341 $inclusions = $wpdb->prepare(' AND ( ID = %d ', $incpage); 3342 else 3343 $inclusions .= $wpdb->prepare(' OR ID = %d ', $incpage); 3344 } 3345 } 3346 } 3347 if (!empty($inclusions)) 3348 $inclusions .= ')'; 3349 3350 $exclusions = ''; 3351 if ( !empty($exclude) ) { 3352 $expages = wp_parse_id_list( $exclude ); 3353 if ( ! empty( $expages ) ) { 3354 foreach ( $expages as $expage ) { 3355 if (empty($exclusions)) 3356 $exclusions = $wpdb->prepare(' AND ( ID <> %d ', $expage); 3357 else 3358 $exclusions .= $wpdb->prepare(' AND ID <> %d ', $expage); 3359 } 3360 } 3361 } 3362 if (!empty($exclusions)) 3363 $exclusions .= ')'; 3364 3365 $author_query = ''; 3366 if (!empty($authors)) { 3367 $post_authors = preg_split('/[\s,]+/',$authors); 3368 3369 if ( ! empty( $post_authors ) ) { 3370 foreach ( $post_authors as $post_author ) { 3371 //Do we have an author id or an author login? 3372 if ( 0 == intval($post_author) ) { 3373 $post_author = get_userdatabylogin($post_author); 3374 if ( empty($post_author) ) 3375 continue; 3376 if ( empty($post_author->ID) ) 3377 continue; 3378 $post_author = $post_author->ID; 3379 } 3380 3381 if ( '' == $author_query ) 3382 $author_query = $wpdb->prepare(' post_author = %d ', $post_author); 3383 else 3384 $author_query .= $wpdb->prepare(' OR post_author = %d ', $post_author); 3385 } 3386 if ( '' != $author_query ) 3387 $author_query = " AND ($author_query)"; 3388 } 3389 } 3390 3391 $join = ''; 3392 $where = "$exclusions $inclusions "; 3393 if ( ! empty( $meta_key ) || ! empty( $meta_value ) ) { 3394 $join = " LEFT JOIN $wpdb->postmeta ON ( $wpdb->posts.ID = $wpdb->postmeta.post_id )"; 3395 3396 // meta_key and meta_value might be slashed 3397 $meta_key = stripslashes($meta_key); 3398 $meta_value = stripslashes($meta_value); 3399 if ( ! empty( $meta_key ) ) 3400 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_key = %s", $meta_key); 3401 if ( ! empty( $meta_value ) ) 3402 $where .= $wpdb->prepare(" AND $wpdb->postmeta.meta_value = %s", $meta_value); 3403 3404 } 3405 3406 if ( $parent >= 0 ) 3407 $where .= $wpdb->prepare(' AND post_parent = %d ', $parent); 3408 3409 $where_post_type = $wpdb->prepare( "post_type = '%s' AND post_status = '%s'", $post_type, $post_status ); 3410 3411 $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where "; 3412 $query .= $author_query; 3413 $query .= " ORDER BY " . $sort_column . " " . $sort_order ; 3414 3415 if ( !empty($number) ) 3416 $query .= ' LIMIT ' . $offset . ',' . $number; 3417 3418 $pages = $wpdb->get_results($query); 3419 3420 if ( empty($pages) ) { 3421 $pages = apply_filters('get_pages', array(), $r); 3422 return $pages; 3423 } 3424 3425 // Sanitize before caching so it'll only get done once 3426 $num_pages = count($pages); 3427 for ($i = 0; $i < $num_pages; $i++) { 3428 $pages[$i] = sanitize_post($pages[$i], 'raw'); 3429 } 3430 3431 // Update cache. 3432 update_page_cache($pages); 3433 3434 if ( $child_of || $hierarchical ) 3435 $pages = & get_page_children($child_of, $pages); 3436 3437 if ( !empty($exclude_tree) ) { 3438 $exclude = (int) $exclude_tree; 3439 $children = get_page_children($exclude, $pages); 3440 $excludes = array(); 3441 foreach ( $children as $child ) 3442 $excludes[] = $child->ID; 3443 $excludes[] = $exclude; 3444 $num_pages = count($pages); 3445 for ( $i = 0; $i < $num_pages; $i++ ) { 3446 if ( in_array($pages[$i]->ID, $excludes) ) 3447 unset($pages[$i]); 3448 } 3449 } 3450 3451 $cache[ $key ] = $pages; 3452 wp_cache_set( 'get_pages', $cache, 'posts' ); 3453 3454 $pages = apply_filters('get_pages', $pages, $r); 3455 3327 $pages = get_posts( $r ); 3328 $pages = apply_filters( 'get_pages', $pages, $r ); 3456 3329 return $pages; 3457 3330 } 3458 3331 -
wp-includes/query.php
diff --git wp-includes/query.php wp-includes/query.php index fbf6d35..4b49c45 100644
class WP_Query { 2025 2025 $where .= " AND {$wpdb->posts}.ID NOT IN ($post__not_in)"; 2026 2026 } 2027 2027 2028 if ( is_numeric($q['post_parent']) )2028 if ( is_numeric($q['post_parent']) && $q['post_parent'] > 0 ) 2029 2029 $where .= $wpdb->prepare( " AND $wpdb->posts.post_parent = %d ", $q['post_parent'] ); 2030 2030 2031 2031 if ( $q['page_id'] ) { … … class WP_Query { 2508 2508 $this->found_posts = apply_filters_ref_array( 'found_posts', array( $this->found_posts, &$this ) ); 2509 2509 $this->max_num_pages = ceil($this->found_posts / $q['posts_per_page']); 2510 2510 } 2511 2512 if ( ! empty( $q['child_of'] ) && ! empty( $q['hierarchical'] ) ) { 2513 $this->posts = get_page_children( $q['child_of'], $this->posts ); 2514 } 2515 2516 if ( ! empty( $q['exclude_tree'] ) ) { 2517 $exclude_tree = (int) $q['exclude_tree']; 2518 $excluded_children = get_page_children( $exclude_tree, $this->posts, 'ID' ); 2519 $excluded_children[] = $exclude_tree; 2520 2521 foreach ( $this->posts as $index => $post ) { 2522 if ( in_array( $post->ID, $excluded_children ) ) { 2523 unset( $this->posts[$index] ); 2524 } 2525 } 2526 } 2511 2527 2512 2528 // Check post status to determine if post should be displayed. 2513 2529 if ( !empty($this->posts) && ($this->is_single || $this->is_page) ) { … … class WP_Query { 2595 2611 $this->posts = apply_filters_ref_array('the_posts', array( $this->posts, &$this ) ); 2596 2612 2597 2613 $this->post_count = count($this->posts); 2598 2614 2599 2615 // Sanitize before caching so it'll only get done once 2600 for ( $i = 0; $i < $this->post_count; $i++) {2601 $this->posts[$ i] = sanitize_post($this->posts[$i], 'raw');2616 foreach ( $this->posts as $key => $post ) { 2617 $this->posts[$key] = sanitize_post( $this->posts[$key], 'raw' ); 2602 2618 } 2603 2619 2604 2620 if ( $q['cache_results'] ) … … class WP_Query { 2610 2626 2611 2627 return $this->posts; 2612 2628 } 2613 2629 2614 2630 /** 2615 2631 * Set up the next post and iterate current post index. 2616 2632 *