Ticket #16574: 16574.4.diff
File 16574.4.diff, 6.4 KB (added by , 13 years ago) |
---|
-
wp-includes/nav-menu-template.php
diff --git wp-includes/nav-menu-template.php wp-includes/nav-menu-template.php index 1dfc661..4789fc4 100644
function _wp_menu_item_classes_by_context( &$menu_items ) { 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(); … … function _wp_menu_item_classes_by_context( &$menu_items ) { 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
diff --git wp-includes/post-template.php wp-includes/post-template.php index 7a60672..b2a63fa 100644
class Walker_Page extends Walker { 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
diff --git wp-includes/post.php wp-includes/post.php index 3fcaa46..675041f 100644
function &get_post(&$post, $output = OBJECT, $filter = 'raw') { 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 ) { … … function &get_post(&$post, $output = OBJECT, $filter = 'raw') { 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 } … … function &get_post(&$post, $output = OBJECT, $filter = 'raw') { 424 422 * @param int|object $post Post ID or post object 425 423 * @return array Ancestor IDs or empty array if none are found. 426 424 */ 427 function get_post_ancestors($post) { 428 $post = get_post($post); 425 function get_post_ancestors( $post ) { 426 $post = get_post( $post ); 427 428 if ( !$post ) 429 return false; 430 431 if ( ! $ancestors = wp_cache_get( $post->ID, 'post_ancestors' ) ) { 432 $ancestors = array(); 433 434 if ( !empty( $post->post_parent ) && $post->ID != $post->post_parent ) { 435 $id = $ancestors[] = $post->post_parent; 436 437 while ( $ancestor = get_post( $id ) ) { 438 // Loop detection: If the ancestor has been seen before, break. 439 if ( empty( $ancestor->post_parent ) || ( $ancestor->post_parent == $post->ID ) || in_array( $ancestor->post_parent, $ancestors ) ) 440 break; 429 441 430 if ( !empty($post->ancestors) ) 431 return $post->ancestors; 442 $id = $ancestors[] = $ancestor->post_parent; 443 } 444 } 445 446 wp_cache_add( $post->ID, $ancestors, 'post_ancestors' ); 447 } 432 448 433 return array();449 return $ancestors; 434 450 } 435 451 436 452 /** … … function _save_post_hook($post_id, $post) { 4613 4629 } 4614 4630 4615 4631 /** 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 4632 * Determines which fields of posts are to be saved in revisions. 4656 4633 * 4657 4634 * Does two things. If passed a post *array*, it will return a post array ready … … function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache 5338 5315 5339 5316 update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache ); 5340 5317 } 5341 } 5342 No newline at end of file 5318 } -
wp-includes/taxonomy.php
diff --git wp-includes/taxonomy.php wp-includes/taxonomy.php index 6334ee7..3da27dd 100644
function get_ancestors($object_id = 0, $object_type = '') { 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);