Ticket #36745: 36745.1.patch
File 36745.1.patch, 3.6 KB (added by , 8 years ago) |
---|
-
src/wp-includes/nav-menu-template.php
482 482 $home_page_id = (int) get_option( 'page_for_posts' ); 483 483 484 484 if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) { 485 foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy) {486 if ( is_taxonomy_hierarchical( $taxonomy )) {485 foreach ( (array) get_object_taxonomies( $queried_object->post_type, 'objects' ) as $taxonomy => $taxonomy_object ) { 486 if ( $taxonomy_object->hierarchical && $taxonomy_object->public ) { 487 487 $term_hierarchy = _get_term_hierarchy( $taxonomy ); 488 $terms = wp_get_object_terms( $queried_object_id, $taxonomy, array( 'fields' => 'ids' ) ); 489 if ( is_array( $terms ) ) { 488 $term_list = get_the_terms( $queried_object_id, $taxonomy ); 489 if ( is_array( $term_list ) ) { 490 $terms = wp_list_pluck( $term_list, 'term_id' ); 490 491 $possible_object_parents = array_merge( $possible_object_parents, $terms ); 491 492 $term_to_ancestor = array(); 492 493 foreach ( (array) $term_hierarchy as $anc => $descs ) { -
tests/phpunit/tests/post/nav-menu.php
110 110 $page_items = wp_get_associated_nav_menu_items( $page_id ); 111 111 $this->assertEqualSets( array(), $page_items ); 112 112 } 113 114 /** 115 * @ticket 36745 116 */ 117 function test_wp_get_associated_nav_menu_cache() { 118 global $wpdb; 119 $cat_id = self::factory()->category->create(); 120 $tag_id = self::factory()->tag->create(); 121 $post_id = self::factory()->post->create(); 122 $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) ); 113 123 124 wp_set_post_terms( $post_id, $cat_id, 'category' ); 125 wp_set_post_terms( $post_id, $tag_id, 'post_tag' ); 126 127 $cat_insert = wp_update_nav_menu_item( $this->menu_id, 0, array( 128 'menu-item-type' => 'taxonomy', 129 'menu-item-object' => 'category', 130 'menu-item-object-id' => $cat_id, 131 'menu-item-status' => 'publish' 132 ) ); 133 134 $tag_insert = wp_update_nav_menu_item( $this->menu_id, 0, array( 135 'menu-item-type' => 'taxonomy', 136 'menu-item-object' => 'post_tag', 137 'menu-item-object-id' => $tag_id, 138 'menu-item-status' => 'publish' 139 ) ); 140 141 $post_insert = wp_update_nav_menu_item( $this->menu_id, 0, array( 142 'menu-item-type' => 'post_type', 143 'menu-item-object' => 'post', 144 'menu-item-object-id' => $post_id, 145 'menu-item-status' => 'publish' 146 ) ); 147 148 $page_insert = wp_update_nav_menu_item( $this->menu_id, 0, array( 149 'menu-item-type' => 'post_type', 150 'menu-item-object' => 'page', 151 'menu-item-object-id' => $page_id, 152 'menu-item-status' => 'publish' 153 ) ); 154 155 $permalink = get_permalink( $post_id ); 156 $this->go_to( $permalink ); 157 158 $menu_items = wp_get_nav_menu_items( $this->menu_id, array( 'update_post_term_cache' => false ) ); 159 160 // Check that no more queries after recalling 161 $before = $wpdb->num_queries; 162 _wp_menu_item_classes_by_context( $menu_items ); 163 $first = $wpdb->num_queries; 164 _wp_menu_item_classes_by_context( $menu_items ); 165 $second = $wpdb->num_queries; 166 167 $this->assertEquals( $before, $wpdb->num_queries ); 168 $this->assertEquals( $first, $wpdb->num_queries ); 169 $this->assertEquals( $second, $wpdb->num_queries ); 170 171 } 172 114 173 /** 115 174 * @ticket 27113 116 175 */