| 325 | | // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object |
| 326 | | if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) { |
| 327 | | $active_parent_object_ids[] = (int) $menu_item->object_id; |
| 328 | | $active_parent_item_ids[] = (int) $menu_item->db_id; |
| 329 | | $active_object = $queried_object->post_type; |
| | 325 | $menu_item->force_inactive = false; |
| | 326 | $menu_item->force_active = false; |
| | 327 | $menu_item = apply_filters( 'nav_menu_active', false, $menu_item ); |
| | 328 | if( !$menu_item->force_inactive ) { |
| | 329 | // if the menu item corresponds to a taxonomy term for the currently-queried non-hierarchical post object |
| | 330 | if ( $wp_query->is_singular && 'taxonomy' == $menu_item->type && in_array( $menu_item->object_id, $possible_object_parents ) ) { |
| | 331 | $active_parent_object_ids[] = (int) $menu_item->object_id; |
| | 332 | $active_parent_item_ids[] = (int) $menu_item->db_id; |
| | 333 | $active_object = $queried_object->post_type; |
| 331 | | // if the menu item corresponds to the currently-queried post or taxonomy object |
| 332 | | } elseif ( |
| 333 | | $menu_item->object_id == $queried_object_id && |
| 334 | | ( |
| 335 | | ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) || |
| 336 | | ( 'post_type' == $menu_item->type && $wp_query->is_singular ) || |
| 337 | | ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) ) |
| 338 | | ) |
| 339 | | ) { |
| 340 | | $classes[] = 'current-menu-item'; |
| 341 | | $menu_items[$key]->current = true; |
| 342 | | $_anc_id = (int) $menu_item->db_id; |
| 343 | | |
| 344 | | while( |
| 345 | | ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) && |
| 346 | | ! in_array( $_anc_id, $active_ancestor_item_ids ) |
| | 335 | // if the menu item corresponds to the currently-queried post or taxonomy object |
| | 336 | } elseif ( |
| | 337 | $menu_item->object_id == $queried_object_id && |
| | 338 | ( |
| | 339 | ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) || |
| | 340 | ( 'post_type' == $menu_item->type && $wp_query->is_singular ) || |
| | 341 | ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) ) |
| | 342 | ) |
| 351 | | if ( 'post_type' == $menu_item->type && 'page' == $menu_item->object ) { |
| 352 | | // Back compat classes for pages to match wp_page_menu() |
| 353 | | $classes[] = 'page_item'; |
| 354 | | $classes[] = 'page-item-' . $menu_item->object_id; |
| 355 | | $classes[] = 'current_page_item'; |
| 356 | | } |
| 357 | | $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; |
| 358 | | $active_parent_object_ids[] = (int) $menu_item->post_parent; |
| 359 | | $active_object = $menu_item->object; |
| | 348 | while( |
| | 349 | ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) && |
| | 350 | ! in_array( $_anc_id, $active_ancestor_item_ids ) |
| | 351 | ) { |
| | 352 | $active_ancestor_item_ids[] = $_anc_id; |
| | 353 | } |
| 361 | | // if the menu item corresponds to the currently-requested URL |
| 362 | | } elseif ( 'custom' == $menu_item->object ) { |
| 363 | | $current_url = untrailingslashit( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
| 364 | | $item_url = untrailingslashit( strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url ); |
| 365 | | $_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) ); |
| | 355 | if ( 'post_type' == $menu_item->type && 'page' == $menu_item->object ) { |
| | 356 | // Back compat classes for pages to match wp_page_menu() |
| | 357 | $classes[] = 'page_item'; |
| | 358 | $classes[] = 'page-item-' . $menu_item->object_id; |
| | 359 | $classes[] = 'current_page_item'; |
| | 360 | } |
| | 361 | $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; |
| | 362 | $active_parent_object_ids[] = (int) $menu_item->post_parent; |
| | 363 | $active_object = $menu_item->object; |
| 367 | | if ( in_array( $item_url, array( $current_url, $_indexless_current ) ) ) { |
| | 365 | // if the menu item corresponds to the currently-requested URL |
| | 366 | } elseif ( 'custom' == $menu_item->object ) { |
| | 367 | $current_url = untrailingslashit( ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ); |
| | 368 | $item_url = untrailingslashit( strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url ); |
| | 369 | $_indexless_current = untrailingslashit( preg_replace( '/index.php$/', '', $current_url ) ); |
| | 370 | |
| | 371 | if ( in_array( $item_url, array( $current_url, $_indexless_current ) ) ) { |
| | 372 | $classes[] = 'current-menu-item'; |
| | 373 | $menu_items[$key]->current = true; |
| | 374 | $_anc_id = (int) $menu_item->db_id; |
| | 375 | |
| | 376 | while( |
| | 377 | ( $_anc_id = get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) ) && |
| | 378 | ! in_array( $_anc_id, $active_ancestor_item_ids ) |
| | 379 | ) { |
| | 380 | $active_ancestor_item_ids[] = $_anc_id; |
| | 381 | } |
| | 382 | |
| | 383 | if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ) ) ) { |
| | 384 | // Back compat for home link to match wp_page_menu() |
| | 385 | $classes[] = 'current_page_item'; |
| | 386 | } |
| | 387 | $active_parent_item_ids[] = (int) $menu_item->menu_item_parent; |
| | 388 | $active_parent_object_ids[] = (int) $menu_item->post_parent; |
| | 389 | $active_object = $menu_item->object; |
| | 390 | |
| | 391 | // give front page item current-menu-item class when extra query arguments involved |
| | 392 | } elseif ( $item_url == $front_page_url && is_front_page() ) { |
| | 393 | $classes[] = 'current-menu-item'; |
| | 394 | } |
| | 395 | |
| | 396 | if ( untrailingslashit($item_url) == home_url() ) |
| | 397 | $classes[] = 'menu-item-home'; |
| | 398 | } elseif ( $menu_item->force_active ) { |