Changeset 47550 for trunk/src/wp-includes/nav-menu-template.php
- Timestamp:
- 04/05/2020 03:00:44 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/nav-menu-template.php
r47219 r47550 175 175 */ 176 176 $allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) ); 177 if ( is_string( $args->container ) && in_array( $args->container, $allowed_tags ) ) { 177 178 if ( is_string( $args->container ) && in_array( $args->container, $allowed_tags, true ) ) { 178 179 $show_container = true; 179 180 $class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-' . $menu->slug . '-container"'; … … 224 225 } else { 225 226 $wrap_id = 'menu-' . $menu->slug; 226 while ( in_array( $wrap_id, $menu_id_slugs ) ) { 227 228 while ( in_array( $wrap_id, $menu_id_slugs, true ) ) { 227 229 if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) ) { 228 230 $wrap_id = preg_replace( '#-(\d+)$#', '-' . ++$matches[1], $wrap_id ); … … 398 400 // If the menu item corresponds to the currently queried post or taxonomy object. 399 401 } elseif ( 400 $menu_item->object_id == $queried_object_id && 401 ( 402 ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) || 403 ( 'post_type' == $menu_item->type && $wp_query->is_singular ) || 404 ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) && $queried_object->taxonomy == $menu_item->object ) 402 $menu_item->object_id == $queried_object_id 403 && ( 404 ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) 405 || ( 'post_type' == $menu_item->type && $wp_query->is_singular ) 406 || ( 'taxonomy' == $menu_item->type 407 && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) && $queried_object->taxonomy == $menu_item->object ) 405 408 ) 406 409 ) { … … 410 413 411 414 while ( 412 ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&413 ! in_array( $_anc_id, $active_ancestor_item_ids)415 ( $_anc_id = (int) get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) 416 && ! in_array( $_anc_id, $active_ancestor_item_ids, true ) 414 417 ) { 415 418 $active_ancestor_item_ids[] = $_anc_id; … … 429 432 // If the menu item corresponds to the currently queried post type archive. 430 433 } elseif ( 431 'post_type_archive' == $menu_item->type &&432 is_post_type_archive( array( $menu_item->object ) )434 'post_type_archive' == $menu_item->type 435 && is_post_type_archive( array( $menu_item->object ) ) 433 436 ) { 434 437 $classes[] = 'current-menu-item'; … … 437 440 438 441 while ( 439 ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&440 ! in_array( $_anc_id, $active_ancestor_item_ids)442 ( $_anc_id = (int) get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) 443 && ! in_array( $_anc_id, $active_ancestor_item_ids, true ) 441 444 ) { 442 445 $active_ancestor_item_ids[] = $_anc_id; … … 468 471 ); 469 472 470 if ( $raw_item_url && in_array( $item_url, $matches ) ) {473 if ( $raw_item_url && in_array( $item_url, $matches, true ) ) { 471 474 $classes[] = 'current-menu-item'; 472 475 $menu_items[ $key ]->current = true; … … 474 477 475 478 while ( 476 ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) &&477 ! in_array( $_anc_id, $active_ancestor_item_ids)479 ( $_anc_id = (int) get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) 480 && ! in_array( $_anc_id, $active_ancestor_item_ids, true ) 478 481 ) { 479 482 $active_ancestor_item_ids[] = $_anc_id; 480 483 } 481 484 482 if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ) ) ) {485 if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ), true ) ) { 483 486 // Back compat for home link to match wp_page_menu(). 484 487 $classes[] = 'current_page_item'; … … 516 519 517 520 if ( 518 isset( $parent_item->type ) &&519 (521 isset( $parent_item->type ) 522 && ( 520 523 // Ancestral post object. 521 524 ( 522 'post_type' == $parent_item->type &&523 ! empty( $queried_object->post_type ) &&524 is_post_type_hierarchical( $queried_object->post_type ) &&525 in_array( $parent_item->object_id, $queried_object->ancestors ) &&526 $parent_item->object != $queried_object->ID525 'post_type' == $parent_item->type 526 && ! empty( $queried_object->post_type ) 527 && is_post_type_hierarchical( $queried_object->post_type ) 528 && in_array( $parent_item->object_id, $queried_object->ancestors ) 529 && $parent_item->object != $queried_object->ID 527 530 ) || 528 531 529 532 // Ancestral term. 530 533 ( 531 'taxonomy' == $parent_item->type &&532 isset( $possible_taxonomy_ancestors[ $parent_item->object ] ) &&533 in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] ) &&534 (534 'taxonomy' == $parent_item->type 535 && isset( $possible_taxonomy_ancestors[ $parent_item->object ] ) 536 && in_array( $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ] ) 537 && ( 535 538 ! isset( $queried_object->term_id ) || 536 539 $parent_item->object_id != $queried_object->term_id … … 539 542 ) 540 543 ) { 541 $classes[] = empty( $queried_object->taxonomy ) ? 'current-' . $queried_object->post_type . '-ancestor' : 'current-' . $queried_object->taxonomy . '-ancestor'; 542 } 543 544 if ( in_array( intval( $parent_item->db_id ), $active_ancestor_item_ids ) ) { 545 $classes[] = 'current-menu-ancestor'; 544 if ( ! empty( $queried_object->taxonomy ) ) { 545 $classes[] = 'current-' . $queried_object->taxonomy . '-ancestor'; 546 } else { 547 $classes[] = 'current-' . $queried_object->post_type . '-ancestor'; 548 } 549 } 550 551 if ( in_array( (int) $parent_item->db_id, $active_ancestor_item_ids, true ) ) { 552 $classes[] = 'current-menu-ancestor'; 553 546 554 $menu_items[ $key ]->current_item_ancestor = true; 547 555 } 548 if ( in_array( $parent_item->db_id, $active_parent_item_ids ) ) { 549 $classes[] = 'current-menu-parent'; 556 if ( in_array( (int) $parent_item->db_id, $active_parent_item_ids, true ) ) { 557 $classes[] = 'current-menu-parent'; 558 550 559 $menu_items[ $key ]->current_item_parent = true; 551 560 } 552 if ( in_array( $parent_item->object_id, $active_parent_object_ids) ) {561 if ( in_array( (int) $parent_item->object_id, $active_parent_object_ids, true ) ) { 553 562 $classes[] = 'current-' . $active_object . '-parent'; 554 563 } … … 556 565 if ( 'post_type' == $parent_item->type && 'page' == $parent_item->object ) { 557 566 // Back compat classes for pages to match wp_page_menu(). 558 if ( in_array( 'current-menu-parent', $classes ) ) {567 if ( in_array( 'current-menu-parent', $classes, true ) ) { 559 568 $classes[] = 'current_page_parent'; 560 569 } 561 if ( in_array( 'current-menu-ancestor', $classes ) ) {570 if ( in_array( 'current-menu-ancestor', $classes, true ) ) { 562 571 $classes[] = 'current_page_ancestor'; 563 572 } … … 598 607 function _nav_menu_item_id_use_once( $id, $item ) { 599 608 static $_used_ids = array(); 600 if ( in_array( $item->ID, $_used_ids ) ) { 609 610 if ( in_array( $item->ID, $_used_ids, true ) ) { 601 611 return ''; 602 612 } 613 603 614 $_used_ids[] = $item->ID; 615 604 616 return $id; 605 617 }
Note: See TracChangeset
for help on using the changeset viewer.