Ticket #21309: 21309.2.diff
File 21309.2.diff, 11.5 KB (added by , 13 years ago) |
---|
-
wp-includes/load.php
diff --git wp-includes/load.php wp-includes/load.php index 94e6339..09e6067 100644
function wp_start_object_cache() { 410 410 411 411 if ( function_exists( 'wp_cache_add_global_groups' ) ) { 412 412 wp_cache_add_global_groups( array( 'users', 'userlogins', 'usermeta', 'user_meta', 'site-transient', 'site-options', 'site-lookup', 'blog-lookup', 'blog-details', 'rss', 'global-posts' ) ); 413 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins' ) );413 wp_cache_add_non_persistent_groups( array( 'comment', 'counts', 'plugins', 'post_ancestors' ) ); 414 414 } 415 415 } 416 416 -
wp-includes/nav-menu-template.php
diff --git wp-includes/nav-menu-template.php wp-includes/nav-menu-template.php index 51321f5..2173087 100644
function _wp_menu_item_classes_by_context( &$menu_items ) { 286 286 } 287 287 } 288 288 } 289 } elseif ( ! empty( $queried_object->post_type ) && is_post_type_hierarchical( $queried_object->post_type ) ) {290 _get_post_ancestors( $queried_object );291 289 } elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) { 292 290 $term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy ); 293 291 $term_to_ancestor = array(); -
wp-includes/post-template.php
diff --git wp-includes/post-template.php wp-includes/post-template.php index 0581a10..89ad4c4 100644
class Walker_Page extends Walker { 1016 1016 $css_class = array('page_item', 'page-item-'.$page->ID); 1017 1017 if ( !empty($current_page) ) { 1018 1018 $_current_page = get_page( $current_page ); 1019 _get_post_ancestors($_current_page); 1020 if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) ) 1019 if ( in_array( $page->ID, $_current_page->ancestors ) ) 1021 1020 $css_class[] = 'current_page_ancestor'; 1022 1021 if ( $page->ID == $current_page ) 1023 1022 $css_class[] = 'current_page_item'; -
wp-includes/post.php
diff --git wp-includes/post.php wp-includes/post.php index ea4f3d6..b6c5055 100644
function get_extended($post) { 378 378 * @return mixed Post data 379 379 */ 380 380 function &get_post(&$post, $output = OBJECT, $filter = 'raw') { 381 global $wpdb;382 381 $null = null; 383 382 384 383 if ( empty($post) ) { … … function &get_post(&$post, $output = OBJECT, $filter = 'raw') { 386 385 $_post = & $GLOBALS['post']; 387 386 else 388 387 return $null; 389 } elseif ( is_object($post) && empty($post->filter) ) {390 _get_post_ancestors($post);391 $_post = sanitize_post($post, 'raw');392 wp_cache_add($post->ID, $_post, 'posts');393 } elseif ( is_object($post) && 'raw' == $post->filter ) {394 $_post = $post;395 388 } else { 396 if ( is_object($post) ) 397 $post_id = $post->ID; 398 else 399 $post_id = $post; 389 $_post = WP_Post::get_instance( $post ); 390 if ( !$_post ) 391 return $null; 392 } 393 394 $_post->filter = $filter; 395 396 if ( $output == ARRAY_A ) { 397 $__post = $_post->to_array(); 398 return $__post; 399 } elseif ( $output == ARRAY_N ) { 400 $__post = array_values($_post->to_array()); 401 return $__post; 402 } 403 404 return $_post; 405 } 406 407 /** 408 * WordPress Post class. 409 * 410 * @since 3.5.0 411 * 412 * @property $ID; 413 * @property $post_author; 414 * @property $post_date; 415 * @property $post_date_gmt; 416 * @property $post_content; 417 * @property $post_title; 418 * @property $post_excerpt; 419 * @property $post_status; 420 * @property $comment_status; 421 * @property $ping_status; 422 * @property $post_password; 423 * @property $post_name; 424 * @property $to_ping; 425 * @property $pinged; 426 * @property $post_modified; 427 * @property $post_modified_gmt; 428 * @property $post_content_filtered; 429 * @property $post_parent; 430 * @property $guid; 431 * @property $menu_order; 432 * @property $post_type; 433 * @property $post_mime_type; 434 * @property $comment_count; 435 * @property $ancestors; 436 */ 437 final class WP_Post { 438 439 private $post; 440 441 public $filter = 'raw'; 442 443 public static function get_instance( $post_id ) { 444 global $wpdb; 445 446 if ( is_a( $post_id, __CLASS__ ) ) 447 return $post_id; 448 449 if ( is_object( $post_id ) && isset( $post_id->ID ) ) 450 $post_id = $post_id->ID; 400 451 401 452 $post_id = (int) $post_id; 402 if ( ! $_post = wp_cache_get($post_id, 'posts') ) { 403 $_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id)); 453 if ( !$post_id ) 454 return false; 455 456 if ( ! $_post = wp_cache_get( $post_id, 'posts' ) ) { 457 $_post = $wpdb->get_row( $wpdb->prepare( " 458 SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1 459 ", $post_id ) ); 460 404 461 if ( ! $_post ) 405 return $null;406 _get_post_ancestors($_post); 407 $_post = sanitize_post( $_post, 'raw');408 wp_cache_add( $_post->ID, $_post, 'posts');462 return false; 463 464 $_post = sanitize_post( $_post, 'raw' ); 465 wp_cache_add( $_post->ID, $_post, 'posts' ); 409 466 } 467 468 return new WP_Post( $_post ); 410 469 } 411 470 412 if ($filter != 'raw') 413 $_post = sanitize_post($_post, $filter); 471 private function __construct( $post ) { 472 $this->post = $post; 473 } 414 474 415 if ( $output == OBJECT ) { 416 return $_post; 417 } elseif ( $output == ARRAY_A ) { 418 $__post = get_object_vars($_post); 419 return $__post; 420 } elseif ( $output == ARRAY_N ) { 421 $__post = array_values(get_object_vars($_post)); 422 return $__post; 423 } else { 424 return $_post; 475 public function to_array() { 476 $post = get_object_vars( $this->post ); 477 $post['ancestors'] = array(); 478 $post['filter'] = $this->filter; 479 480 return $post; 481 } 482 483 public function __isset( $key ) { 484 if ( 'ancestors' == $key ) 485 return true; 486 487 return isset( $this->post->$key ); 488 } 489 490 public function &__get( $key ) { 491 if ( 'ancestors' == $key ) 492 $value = get_post_ancestors( $this ); 493 else 494 $value = $this->post->$key; 495 496 if ( $this->filter ) { 497 $value = sanitize_post_field( $key, $value, $this->post->ID, $this->filter ); 498 } 499 500 return $value; 501 } 502 503 public function __set( $key, $value ) { 504 if ( 'ancestors' == $key ) 505 return; 506 507 $this->post->$key = $value; 425 508 } 426 509 } 427 510 … … function &get_post(&$post, $output = OBJECT, $filter = 'raw') { 433 516 * @param int|object $post Post ID or post object 434 517 * @return array Ancestor IDs or empty array if none are found. 435 518 */ 436 function get_post_ancestors($post) { 437 $post = get_post($post); 519 function get_post_ancestors( $post ) { 520 if ( !$post ) 521 return false; 438 522 439 if ( ! isset( $post->ancestors ) )440 _get_post_ancestors( $post);523 if ( ! $ancestors = wp_cache_get( $post->ID, 'post_ancestors' ) ) { 524 $ancestors = array(); 441 525 442 if ( ! empty( $post->ancestors ) )443 return $post->ancestors;526 if ( !empty( $post->post_parent ) && $post->ID != $post->post_parent ) { 527 $id = $ancestors[] = $post->post_parent; 444 528 445 return array(); 529 while ( $ancestor = get_post( $id ) ) { 530 // Loop detection: If the ancestor has been seen before, break. 531 if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) 532 break; 533 534 $id = $ancestors[] = $ancestor->post_parent; 535 } 536 } 537 538 wp_cache_add( $post->ID, $ancestors, 'post_ancestors' ); 539 } 540 541 return $ancestors; 446 542 } 447 543 448 544 /** … … function get_page_uri($page) { 3348 3444 $page = get_page($page); 3349 3445 $uri = $page->post_name; 3350 3446 3351 // A page cannot be it's own parent. 3352 if ( $page->post_parent == $page->ID ) 3353 return $uri; 3354 3355 while ($page->post_parent != 0) { 3356 $page = get_page($page->post_parent); 3357 $uri = $page->post_name . "/" . $uri; 3447 foreach ( $page->ancestors as $parent ) { 3448 $uri = get_page($parent)->post_name . "/" . $uri; 3358 3449 } 3359 3450 3360 3451 return $uri; … … function &get_pages($args = '') { 3406 3497 $key = md5( serialize( compact(array_keys($defaults)) ) ); 3407 3498 if ( $cache = wp_cache_get( 'get_pages', 'posts' ) ) { 3408 3499 if ( is_array($cache) && isset( $cache[ $key ] ) ) { 3409 $pages = apply_filters('get_pages', $cache[ $key ], $r ); 3410 return $pages; 3500 // Convert to WP_Post instances 3501 $pages = array_map( 'get_post', $cache[ $key ] ); 3502 3503 return apply_filters( 'get_pages', $pages, $r ); 3411 3504 } 3412 3505 } 3413 3506 … … function &get_pages($args = '') { 3581 3674 $cache[ $key ] = $pages; 3582 3675 wp_cache_set( 'get_pages', $cache, 'posts' ); 3583 3676 3677 // Convert to WP_Post instances 3678 $pages = array_map( 'get_post', $pages ); 3679 3584 3680 $pages = apply_filters('get_pages', $pages, $r); 3585 3681 3586 3682 return $pages; … … function _save_post_hook( $post_id, $post ) { 4612 4708 } 4613 4709 4614 4710 /** 4615 * Retrieve post ancestors and append to post ancestors property.4616 *4617 * Will only retrieve ancestors once, if property is already set, then nothing4618 * will be done. If there is not a parent post, or post ID and post parent ID4619 * are the same then nothing will be done.4620 *4621 * The parameter is passed by reference, so nothing needs to be returned. The4622 * property will be updated and can be referenced after the function is4623 * complete. The post parent will be an ancestor and the parent of the post4624 * parent will be an ancestor. There will only be two ancestors at the most.4625 *4626 * @since 2.5.04627 * @access private4628 * @uses $wpdb4629 *4630 * @param object $_post Post data.4631 * @return null When nothing needs to be done.4632 */4633 function _get_post_ancestors(&$_post) {4634 global $wpdb;4635 4636 if ( isset($_post->ancestors) )4637 return;4638 4639 $_post->ancestors = array();4640 4641 if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent )4642 return;4643 4644 $id = $_post->ancestors[] = (int) $_post->post_parent;4645 while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {4646 // Loop detection: If the ancestor has been seen before, break.4647 if ( ( $ancestor == $_post->ID ) || in_array($ancestor, $_post->ancestors) )4648 break;4649 $id = $_post->ancestors[] = (int) $ancestor;4650 }4651 }4652 4653 /**4654 4711 * Determines which fields of posts are to be saved in revisions. 4655 4712 * 4656 4713 * Does two things. If passed a post *array*, it will return a post array ready -
wp-includes/query.php
diff --git wp-includes/query.php wp-includes/query.php index e976cdf..0ceb294 100644
class WP_Query { 2645 2645 $this->set_found_posts( $q, $limits ); 2646 2646 2647 2647 _prime_post_caches( $ids, $q['update_post_term_cache'], $q['update_post_meta_cache'] ); 2648 2649 $this->posts = array_map( 'get_post', $ids ); 2648 $this->posts = $ids; 2650 2649 } else { 2651 2650 $this->found_posts = $this->max_num_pages = 0; 2652 2651 $this->posts = array(); … … class WP_Query { 2656 2655 $this->set_found_posts( $q, $limits ); 2657 2656 } 2658 2657 2658 // Convert to WP_Post objects 2659 $this->posts = array_map( 'get_post', $this->posts ); 2660 2659 2661 // Raw results filter. Prior to status checks. 2660 2662 if ( !$q['suppress_filters'] ) 2661 2663 $this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) ); -
wp-includes/taxonomy.php
diff --git wp-includes/taxonomy.php wp-includes/taxonomy.php index 8ea976f..e3f0a16 100644
function get_ancestors($object_id = 0, $object_type = '') { 3207 3207 $ancestors[] = (int) $term->parent; 3208 3208 $term = get_term($term->parent, $object_type); 3209 3209 } 3210 } elseif ( null !== get_post_type_object( $object_type ) ) { 3211 $object = get_post($object_id); 3212 if ( ! is_wp_error( $object ) && isset( $object->ancestors ) && is_array( $object->ancestors ) ) 3213 $ancestors = $object->ancestors; 3214 else { 3215 while ( ! is_wp_error($object) && ! empty( $object->post_parent ) && ! in_array( $object->post_parent, $ancestors ) ) { 3216 $ancestors[] = (int) $object->post_parent; 3217 $object = get_post($object->post_parent); 3218 } 3219 } 3210 } elseif ( post_type_exists( $object_type ) ) { 3211 $ancestors = get_post_ancestors($object_id); 3220 3212 } 3221 3213 3222 3214 return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);