Ticket #16574: 16574.6.diff
File 16574.6.diff, 6.9 KB (added by , 12 years ago) |
---|
-
wp-includes/nav-menu-template.php
287 287 } 288 288 } 289 289 } 290 } elseif ( ! empty( $queried_object->post_type ) && is_post_type_hierarchical( $queried_object->post_type ) ) {291 _get_post_ancestors( $queried_object );292 290 } elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) { 293 291 $term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy ); 294 292 $term_to_ancestor = array(); … … 419 417 'post_type' == $parent_item->type && 420 418 ! empty( $queried_object->post_type ) && 421 419 is_post_type_hierarchical( $queried_object->post_type ) && 422 in_array( $parent_item->object_id, $queried_object->ancestors) &&420 in_array( $parent_item->object_id, get_post_ancestors( $queried_object ) ) && 423 421 $parent_item->object != $queried_object->ID 424 422 ) || 425 423 -
wp-includes/post-template.php
1035 1035 $css_class = array('page_item', 'page-item-'.$page->ID); 1036 1036 if ( !empty($current_page) ) { 1037 1037 $_current_page = get_page( $current_page ); 1038 _get_post_ancestors($_current_page); 1039 if ( isset($_current_page->ancestors) && in_array($page->ID, (array) $_current_page->ancestors) ) 1038 if ( in_array( $page->ID, get_post_ancestors( $current_page ) ) ) 1040 1039 $css_class[] = 'current_page_ancestor'; 1041 1040 if ( $page->ID == $current_page ) 1042 1041 $css_class[] = 'current_page_item'; -
wp-includes/post.php
378 378 else 379 379 return $null; 380 380 } elseif ( is_object($post) && empty($post->filter) ) { 381 _get_post_ancestors($post);382 381 $_post = sanitize_post($post, 'raw'); 383 382 wp_cache_add($post->ID, $_post, 'posts'); 384 383 } elseif ( is_object($post) && 'raw' == $post->filter ) { … … 394 393 $_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id)); 395 394 if ( ! $_post ) 396 395 return $null; 397 _get_post_ancestors($_post);398 396 $_post = sanitize_post($_post, 'raw'); 399 397 wp_cache_add($_post->ID, $_post, 'posts'); 400 398 } … … 404 402 $_post = sanitize_post($_post, $filter); 405 403 406 404 if ( $output == OBJECT ) { 405 $_post = new _WP_Post_Wrapper( $_post ); 407 406 return $_post; 408 407 } elseif ( $output == ARRAY_A ) { 409 408 $__post = get_object_vars($_post); … … 417 416 } 418 417 419 418 /** 419 * Wrapper class to preserve back-compat for $post->ancestors 420 * 421 * @since 3.4.0 422 */ 423 class _WP_Post_Wrapper { 424 425 private $post; 426 427 function __construct( $post ) { 428 $this->post = $post; 429 } 430 431 function __isset( $key ) { 432 if ( 'ancestors' == $key ) 433 return true; 434 435 return isset( $this->post->$key ); 436 } 437 438 function __get( $key ) { 439 if ( 'ancestors' == $key ) 440 return get_post_ancestors( $this->post ); 441 442 if ( isset( $this->post->$key ) ) 443 return $this->post->$key; 444 } 445 446 function __set( $key, $value ) { 447 if ( 'ancestors' == $key ) 448 return; 449 450 $this->post->$key = $value; 451 } 452 } 453 454 /** 420 455 * Retrieve ancestors of a post. 421 456 * 422 457 * @since 2.5.0 … … 424 459 * @param int|object $post Post ID or post object 425 460 * @return array Ancestor IDs or empty array if none are found. 426 461 */ 427 function get_post_ancestors( $post) {428 $post = get_post( $post);462 function get_post_ancestors( $post ) { 463 $post = get_post( $post ); 429 464 430 if ( !empty($post->ancestors) )431 return $post->ancestors;465 if ( empty( $post ) ) 466 return false; 432 467 433 return array(); 468 $ancestors = wp_cache_get( $post->ID, 'post_ancestors' ); 469 if ( empty( $ancestors ) ) { 470 $ancestors = array(); // Cache was empty; set to array to suppress notices 471 472 if ( !empty( $post->post_parent ) && ( $post->ID != $post->post_parent ) ) { 473 $id = $ancestors[] = $post->post_parent; 474 475 while ( $ancestor = get_post( $id ) ) { 476 477 // Loop detection: If the ancestor has been seen before, break. 478 if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) { 479 break; 480 } 481 482 $id = $ancestors[] = $ancestor->post_parent; 483 } 484 } 485 486 wp_cache_add( $post->ID, $ancestors, 'post_ancestors' ); 487 } 488 489 return $ancestors; 434 490 } 435 491 436 492 /** … … 3300 3356 $page = get_page($page); 3301 3357 $uri = $page->post_name; 3302 3358 3303 // A page cannot be it's own parent. 3304 if ( $page->post_parent == $page->ID ) 3305 return $uri; 3306 3307 while ($page->post_parent != 0) { 3308 $page = get_page($page->post_parent); 3309 $uri = $page->post_name . "/" . $uri; 3359 foreach ( $page->ancestors as $parent ) { 3360 $uri = get_page($parent)->post_name . "/" . $uri; 3310 3361 } 3311 3362 3312 3363 return $uri; … … 4613 4664 } 4614 4665 4615 4666 /** 4616 * Retrieve post ancestors and append to post ancestors property.4617 *4618 * Will only retrieve ancestors once, if property is already set, then nothing4619 * will be done. If there is not a parent post, or post ID and post parent ID4620 * are the same then nothing will be done.4621 *4622 * The parameter is passed by reference, so nothing needs to be returned. The4623 * property will be updated and can be referenced after the function is4624 * complete. The post parent will be an ancestor and the parent of the post4625 * parent will be an ancestor. There will only be two ancestors at the most.4626 *4627 * @since 2.5.04628 * @access private4629 * @uses $wpdb4630 *4631 * @param object $_post Post data.4632 * @return null When nothing needs to be done.4633 */4634 function _get_post_ancestors(&$_post) {4635 global $wpdb;4636 4637 if ( isset($_post->ancestors) )4638 return;4639 4640 $_post->ancestors = array();4641 4642 if ( empty($_post->post_parent) || $_post->ID == $_post->post_parent )4643 return;4644 4645 $id = $_post->ancestors[] = $_post->post_parent;4646 while ( $ancestor = $wpdb->get_var( $wpdb->prepare("SELECT `post_parent` FROM $wpdb->posts WHERE ID = %d LIMIT 1", $id) ) ) {4647 // Loop detection: If the ancestor has been seen before, break.4648 if ( ( $ancestor == $_post->ID ) || in_array($ancestor, $_post->ancestors) )4649 break;4650 $id = $_post->ancestors[] = $ancestor;4651 }4652 }4653 4654 /**4655 No newline at end of file4656 4667 * Determines which fields of posts are to be saved in revisions. 4657 4668 * 4658 4669 * Does two things. If passed a post *array*, it will return a post array ready -
wp-includes/taxonomy.php
3206 3206 $ancestors[] = (int) $term->parent; 3207 3207 $term = get_term($term->parent, $object_type); 3208 3208 } 3209 } elseif ( null !== get_post_type_object( $object_type ) ) { 3210 $object = get_post($object_id); 3211 if ( ! is_wp_error( $object ) && isset( $object->ancestors ) && is_array( $object->ancestors ) ) 3212 $ancestors = $object->ancestors; 3213 else { 3214 while ( ! is_wp_error($object) && ! empty( $object->post_parent ) && ! in_array( $object->post_parent, $ancestors ) ) { 3215 $ancestors[] = (int) $object->post_parent; 3216 $object = get_post($object->post_parent); 3217 } 3218 } 3209 } elseif ( post_type_exists( $object_type ) ) { 3210 $ancestors = get_post_ancestors($object_id); 3219 3211 } 3220 3212 3221 3213 return apply_filters('get_ancestors', $ancestors, $object_id, $object_type);