Changeset 53504 for trunk/src/wp-includes/nav-menu.php
- Timestamp:
- 06/15/2022 10:18:02 AM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/nav-menu.php
r53455 r53504 692 692 } 693 693 694 static $fetched = array();695 696 694 if ( ! taxonomy_exists( 'nav_menu' ) ) { 697 695 return false; … … 699 697 700 698 $defaults = array( 701 'order' => 'ASC', 702 'orderby' => 'menu_order', 703 'post_type' => 'nav_menu_item', 704 'post_status' => 'publish', 705 'output' => ARRAY_A, 706 'output_key' => 'menu_order', 707 'nopaging' => true, 708 'tax_query' => array( 699 'order' => 'ASC', 700 'orderby' => 'menu_order', 701 'post_type' => 'nav_menu_item', 702 'post_status' => 'publish', 703 'output' => ARRAY_A, 704 'output_key' => 'menu_order', 705 'nopaging' => true, 706 'update_menu_item_cache' => true, 707 'tax_query' => array( 709 708 array( 710 709 'taxonomy' => 'nav_menu', … … 721 720 } 722 721 723 // Prime posts and terms caches.724 if ( empty( $fetched[ $menu->term_id ] ) ) {725 $fetched[ $menu->term_id ] = true;726 $post_ids = array();727 $term_ids = array();728 foreach ( $items as $item ) {729 $object_id = get_post_meta( $item->ID, '_menu_item_object_id', true );730 $type = get_post_meta( $item->ID, '_menu_item_type', true );731 732 if ( 'post_type' === $type ) {733 $post_ids[] = (int) $object_id;734 } elseif ( 'taxonomy' === $type ) {735 $term_ids[] = (int) $object_id;736 }737 }738 739 if ( ! empty( $post_ids ) ) {740 _prime_post_caches( $post_ids, false );741 }742 unset( $post_ids );743 744 if ( ! empty( $term_ids ) ) {745 _prime_term_caches( $term_ids );746 }747 unset( $term_ids );748 }749 750 722 $items = array_map( 'wp_setup_nav_menu_item', $items ); 751 723 … … 779 751 */ 780 752 return apply_filters( 'wp_get_nav_menu_items', $items, $menu, $args ); 753 } 754 755 /** 756 * Prime all linked objects to menu items. 757 * 758 * @since 6.1.0 759 * 760 * @param WP_Post[] $menu_items Array post objects of menu items. 761 */ 762 function update_menu_item_cache( $menu_items ) { 763 $post_ids = array(); 764 $term_ids = array(); 765 766 foreach ( $menu_items as $menu_item ) { 767 if ( 'nav_menu_item' !== $menu_item->post_type ) { 768 continue; 769 } 770 $object_id = get_post_meta( $menu_item->ID, '_menu_item_object_id', true ); 771 $type = get_post_meta( $menu_item->ID, '_menu_item_type', true ); 772 773 if ( 'post_type' === $type ) { 774 $post_ids[] = (int) $object_id; 775 } elseif ( 'taxonomy' === $type ) { 776 $term_ids[] = (int) $object_id; 777 } 778 } 779 780 if ( ! empty( $post_ids ) ) { 781 _prime_post_caches( $post_ids, false ); 782 } 783 784 if ( ! empty( $term_ids ) ) { 785 _prime_term_caches( $term_ids ); 786 } 781 787 } 782 788
Note: See TracChangeset
for help on using the changeset viewer.