Edit File by line
/home/barbar84/www/wp-inclu...
File: nav-menu-template.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Nav Menu API: Template functions
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
* @subpackage Nav_Menus
[5] Fix | Delete
* @since 3.0.0
[6] Fix | Delete
*/
[7] Fix | Delete
[8] Fix | Delete
/** Walker_Nav_Menu class */
[9] Fix | Delete
require_once ABSPATH . WPINC . '/class-walker-nav-menu.php';
[10] Fix | Delete
[11] Fix | Delete
/**
[12] Fix | Delete
* Displays a navigation menu.
[13] Fix | Delete
*
[14] Fix | Delete
* @since 3.0.0
[15] Fix | Delete
* @since 4.7.0 Added the `item_spacing` argument.
[16] Fix | Delete
* @since 5.5.0 Added the `container_aria_label` argument.
[17] Fix | Delete
*
[18] Fix | Delete
* @param array $args {
[19] Fix | Delete
* Optional. Array of nav menu arguments.
[20] Fix | Delete
*
[21] Fix | Delete
* @type int|string|WP_Term $menu Desired menu. Accepts a menu ID, slug, name, or object.
[22] Fix | Delete
* Default empty.
[23] Fix | Delete
* @type string $menu_class CSS class to use for the ul element which forms the menu.
[24] Fix | Delete
* Default 'menu'.
[25] Fix | Delete
* @type string $menu_id The ID that is applied to the ul element which forms the menu.
[26] Fix | Delete
* Default is the menu slug, incremented.
[27] Fix | Delete
* @type string $container Whether to wrap the ul, and what to wrap it with.
[28] Fix | Delete
* Default 'div'.
[29] Fix | Delete
* @type string $container_class Class that is applied to the container.
[30] Fix | Delete
* Default 'menu-{menu slug}-container'.
[31] Fix | Delete
* @type string $container_id The ID that is applied to the container. Default empty.
[32] Fix | Delete
* @type string $container_aria_label The aria-label attribute that is applied to the container
[33] Fix | Delete
* when it's a nav element. Default empty.
[34] Fix | Delete
* @type callable|false $fallback_cb If the menu doesn't exist, a callback function will fire.
[35] Fix | Delete
* Default is 'wp_page_menu'. Set to false for no fallback.
[36] Fix | Delete
* @type string $before Text before the link markup. Default empty.
[37] Fix | Delete
* @type string $after Text after the link markup. Default empty.
[38] Fix | Delete
* @type string $link_before Text before the link text. Default empty.
[39] Fix | Delete
* @type string $link_after Text after the link text. Default empty.
[40] Fix | Delete
* @type bool $echo Whether to echo the menu or return it. Default true.
[41] Fix | Delete
* @type int $depth How many levels of the hierarchy are to be included.
[42] Fix | Delete
* 0 means all. Default 0.
[43] Fix | Delete
* Default 0.
[44] Fix | Delete
* @type object $walker Instance of a custom walker class. Default empty.
[45] Fix | Delete
* @type string $theme_location Theme location to be used. Must be registered with
[46] Fix | Delete
* register_nav_menu() in order to be selectable by the user.
[47] Fix | Delete
* @type string $items_wrap How the list items should be wrapped. Uses printf() format with
[48] Fix | Delete
* numbered placeholders. Default is a ul with an id and class.
[49] Fix | Delete
* @type string $item_spacing Whether to preserve whitespace within the menu's HTML.
[50] Fix | Delete
* Accepts 'preserve' or 'discard'. Default 'preserve'.
[51] Fix | Delete
* }
[52] Fix | Delete
* @return void|string|false Void if 'echo' argument is true, menu output if 'echo' is false.
[53] Fix | Delete
* False if there are no items or no menu was found.
[54] Fix | Delete
*/
[55] Fix | Delete
function wp_nav_menu( $args = array() ) {
[56] Fix | Delete
static $menu_id_slugs = array();
[57] Fix | Delete
[58] Fix | Delete
$defaults = array(
[59] Fix | Delete
'menu' => '',
[60] Fix | Delete
'container' => 'div',
[61] Fix | Delete
'container_class' => '',
[62] Fix | Delete
'container_id' => '',
[63] Fix | Delete
'container_aria_label' => '',
[64] Fix | Delete
'menu_class' => 'menu',
[65] Fix | Delete
'menu_id' => '',
[66] Fix | Delete
'echo' => true,
[67] Fix | Delete
'fallback_cb' => 'wp_page_menu',
[68] Fix | Delete
'before' => '',
[69] Fix | Delete
'after' => '',
[70] Fix | Delete
'link_before' => '',
[71] Fix | Delete
'link_after' => '',
[72] Fix | Delete
'items_wrap' => '<ul id="%1$s" class="%2$s">%3$s</ul>',
[73] Fix | Delete
'item_spacing' => 'preserve',
[74] Fix | Delete
'depth' => 0,
[75] Fix | Delete
'walker' => '',
[76] Fix | Delete
'theme_location' => '',
[77] Fix | Delete
);
[78] Fix | Delete
[79] Fix | Delete
$args = wp_parse_args( $args, $defaults );
[80] Fix | Delete
[81] Fix | Delete
if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
[82] Fix | Delete
// Invalid value, fall back to default.
[83] Fix | Delete
$args['item_spacing'] = $defaults['item_spacing'];
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
/**
[87] Fix | Delete
* Filters the arguments used to display a navigation menu.
[88] Fix | Delete
*
[89] Fix | Delete
* @since 3.0.0
[90] Fix | Delete
*
[91] Fix | Delete
* @see wp_nav_menu()
[92] Fix | Delete
*
[93] Fix | Delete
* @param array $args Array of wp_nav_menu() arguments.
[94] Fix | Delete
*/
[95] Fix | Delete
$args = apply_filters( 'wp_nav_menu_args', $args );
[96] Fix | Delete
$args = (object) $args;
[97] Fix | Delete
[98] Fix | Delete
/**
[99] Fix | Delete
* Filters whether to short-circuit the wp_nav_menu() output.
[100] Fix | Delete
*
[101] Fix | Delete
* Returning a non-null value from the filter will short-circuit wp_nav_menu(),
[102] Fix | Delete
* echoing that value if $args->echo is true, returning that value otherwise.
[103] Fix | Delete
*
[104] Fix | Delete
* @since 3.9.0
[105] Fix | Delete
*
[106] Fix | Delete
* @see wp_nav_menu()
[107] Fix | Delete
*
[108] Fix | Delete
* @param string|null $output Nav menu output to short-circuit with. Default null.
[109] Fix | Delete
* @param stdClass $args An object containing wp_nav_menu() arguments.
[110] Fix | Delete
*/
[111] Fix | Delete
$nav_menu = apply_filters( 'pre_wp_nav_menu', null, $args );
[112] Fix | Delete
[113] Fix | Delete
if ( null !== $nav_menu ) {
[114] Fix | Delete
if ( $args->echo ) {
[115] Fix | Delete
echo $nav_menu;
[116] Fix | Delete
return;
[117] Fix | Delete
}
[118] Fix | Delete
[119] Fix | Delete
return $nav_menu;
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
// Get the nav menu based on the requested menu.
[123] Fix | Delete
$menu = wp_get_nav_menu_object( $args->menu );
[124] Fix | Delete
[125] Fix | Delete
// Get the nav menu based on the theme_location.
[126] Fix | Delete
$locations = get_nav_menu_locations();
[127] Fix | Delete
if ( ! $menu && $args->theme_location && $locations && isset( $locations[ $args->theme_location ] ) ) {
[128] Fix | Delete
$menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
// Get the first menu that has items if we still can't find a menu.
[132] Fix | Delete
if ( ! $menu && ! $args->theme_location ) {
[133] Fix | Delete
$menus = wp_get_nav_menus();
[134] Fix | Delete
foreach ( $menus as $menu_maybe ) {
[135] Fix | Delete
$menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) );
[136] Fix | Delete
if ( $menu_items ) {
[137] Fix | Delete
$menu = $menu_maybe;
[138] Fix | Delete
break;
[139] Fix | Delete
}
[140] Fix | Delete
}
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
if ( empty( $args->menu ) ) {
[144] Fix | Delete
$args->menu = $menu;
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
// If the menu exists, get its items.
[148] Fix | Delete
if ( $menu && ! is_wp_error( $menu ) && ! isset( $menu_items ) ) {
[149] Fix | Delete
$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
/*
[153] Fix | Delete
* If no menu was found:
[154] Fix | Delete
* - Fall back (if one was specified), or bail.
[155] Fix | Delete
*
[156] Fix | Delete
* If no menu items were found:
[157] Fix | Delete
* - Fall back, but only if no theme location was specified.
[158] Fix | Delete
* - Otherwise, bail.
[159] Fix | Delete
*/
[160] Fix | Delete
if ( ( ! $menu || is_wp_error( $menu ) || ( isset( $menu_items ) && empty( $menu_items ) && ! $args->theme_location ) )
[161] Fix | Delete
&& isset( $args->fallback_cb ) && $args->fallback_cb && is_callable( $args->fallback_cb ) ) {
[162] Fix | Delete
return call_user_func( $args->fallback_cb, (array) $args );
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
if ( ! $menu || is_wp_error( $menu ) ) {
[166] Fix | Delete
return false;
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
$nav_menu = '';
[170] Fix | Delete
$items = '';
[171] Fix | Delete
[172] Fix | Delete
$show_container = false;
[173] Fix | Delete
if ( $args->container ) {
[174] Fix | Delete
/**
[175] Fix | Delete
* Filters the list of HTML tags that are valid for use as menu containers.
[176] Fix | Delete
*
[177] Fix | Delete
* @since 3.0.0
[178] Fix | Delete
*
[179] Fix | Delete
* @param string[] $tags The acceptable HTML tags for use as menu containers.
[180] Fix | Delete
* Default is array containing 'div' and 'nav'.
[181] Fix | Delete
*/
[182] Fix | Delete
$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
[183] Fix | Delete
[184] Fix | Delete
if ( is_string( $args->container ) && in_array( $args->container, $allowed_tags, true ) ) {
[185] Fix | Delete
$show_container = true;
[186] Fix | Delete
$class = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-' . $menu->slug . '-container"';
[187] Fix | Delete
$id = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : '';
[188] Fix | Delete
$aria_label = ( 'nav' === $args->container && $args->container_aria_label ) ? ' aria-label="' . esc_attr( $args->container_aria_label ) . '"' : '';
[189] Fix | Delete
$nav_menu .= '<' . $args->container . $id . $class . $aria_label . '>';
[190] Fix | Delete
}
[191] Fix | Delete
}
[192] Fix | Delete
[193] Fix | Delete
// Set up the $menu_item variables.
[194] Fix | Delete
_wp_menu_item_classes_by_context( $menu_items );
[195] Fix | Delete
[196] Fix | Delete
$sorted_menu_items = array();
[197] Fix | Delete
$menu_items_with_children = array();
[198] Fix | Delete
foreach ( (array) $menu_items as $menu_item ) {
[199] Fix | Delete
$sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
[200] Fix | Delete
if ( $menu_item->menu_item_parent ) {
[201] Fix | Delete
$menu_items_with_children[ $menu_item->menu_item_parent ] = true;
[202] Fix | Delete
}
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
// Add the menu-item-has-children class where applicable.
[206] Fix | Delete
if ( $menu_items_with_children ) {
[207] Fix | Delete
foreach ( $sorted_menu_items as &$menu_item ) {
[208] Fix | Delete
if ( isset( $menu_items_with_children[ $menu_item->ID ] ) ) {
[209] Fix | Delete
$menu_item->classes[] = 'menu-item-has-children';
[210] Fix | Delete
}
[211] Fix | Delete
}
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
unset( $menu_items, $menu_item );
[215] Fix | Delete
[216] Fix | Delete
/**
[217] Fix | Delete
* Filters the sorted list of menu item objects before generating the menu's HTML.
[218] Fix | Delete
*
[219] Fix | Delete
* @since 3.1.0
[220] Fix | Delete
*
[221] Fix | Delete
* @param array $sorted_menu_items The menu items, sorted by each menu item's menu order.
[222] Fix | Delete
* @param stdClass $args An object containing wp_nav_menu() arguments.
[223] Fix | Delete
*/
[224] Fix | Delete
$sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args );
[225] Fix | Delete
[226] Fix | Delete
$items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args );
[227] Fix | Delete
unset( $sorted_menu_items );
[228] Fix | Delete
[229] Fix | Delete
// Attributes.
[230] Fix | Delete
if ( ! empty( $args->menu_id ) ) {
[231] Fix | Delete
$wrap_id = $args->menu_id;
[232] Fix | Delete
} else {
[233] Fix | Delete
$wrap_id = 'menu-' . $menu->slug;
[234] Fix | Delete
[235] Fix | Delete
while ( in_array( $wrap_id, $menu_id_slugs, true ) ) {
[236] Fix | Delete
if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) ) {
[237] Fix | Delete
$wrap_id = preg_replace( '#-(\d+)$#', '-' . ++$matches[1], $wrap_id );
[238] Fix | Delete
} else {
[239] Fix | Delete
$wrap_id = $wrap_id . '-1';
[240] Fix | Delete
}
[241] Fix | Delete
}
[242] Fix | Delete
}
[243] Fix | Delete
$menu_id_slugs[] = $wrap_id;
[244] Fix | Delete
[245] Fix | Delete
$wrap_class = $args->menu_class ? $args->menu_class : '';
[246] Fix | Delete
[247] Fix | Delete
/**
[248] Fix | Delete
* Filters the HTML list content for navigation menus.
[249] Fix | Delete
*
[250] Fix | Delete
* @since 3.0.0
[251] Fix | Delete
*
[252] Fix | Delete
* @see wp_nav_menu()
[253] Fix | Delete
*
[254] Fix | Delete
* @param string $items The HTML list content for the menu items.
[255] Fix | Delete
* @param stdClass $args An object containing wp_nav_menu() arguments.
[256] Fix | Delete
*/
[257] Fix | Delete
$items = apply_filters( 'wp_nav_menu_items', $items, $args );
[258] Fix | Delete
/**
[259] Fix | Delete
* Filters the HTML list content for a specific navigation menu.
[260] Fix | Delete
*
[261] Fix | Delete
* @since 3.0.0
[262] Fix | Delete
*
[263] Fix | Delete
* @see wp_nav_menu()
[264] Fix | Delete
*
[265] Fix | Delete
* @param string $items The HTML list content for the menu items.
[266] Fix | Delete
* @param stdClass $args An object containing wp_nav_menu() arguments.
[267] Fix | Delete
*/
[268] Fix | Delete
$items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );
[269] Fix | Delete
[270] Fix | Delete
// Don't print any markup if there are no items at this point.
[271] Fix | Delete
if ( empty( $items ) ) {
[272] Fix | Delete
return false;
[273] Fix | Delete
}
[274] Fix | Delete
[275] Fix | Delete
$nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items );
[276] Fix | Delete
unset( $items );
[277] Fix | Delete
[278] Fix | Delete
if ( $show_container ) {
[279] Fix | Delete
$nav_menu .= '</' . $args->container . '>';
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
/**
[283] Fix | Delete
* Filters the HTML content for navigation menus.
[284] Fix | Delete
*
[285] Fix | Delete
* @since 3.0.0
[286] Fix | Delete
*
[287] Fix | Delete
* @see wp_nav_menu()
[288] Fix | Delete
*
[289] Fix | Delete
* @param string $nav_menu The HTML content for the navigation menu.
[290] Fix | Delete
* @param stdClass $args An object containing wp_nav_menu() arguments.
[291] Fix | Delete
*/
[292] Fix | Delete
$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args );
[293] Fix | Delete
[294] Fix | Delete
if ( $args->echo ) {
[295] Fix | Delete
echo $nav_menu;
[296] Fix | Delete
} else {
[297] Fix | Delete
return $nav_menu;
[298] Fix | Delete
}
[299] Fix | Delete
}
[300] Fix | Delete
[301] Fix | Delete
/**
[302] Fix | Delete
* Adds the class property classes for the current context, if applicable.
[303] Fix | Delete
*
[304] Fix | Delete
* @access private
[305] Fix | Delete
* @since 3.0.0
[306] Fix | Delete
*
[307] Fix | Delete
* @global WP_Query $wp_query WordPress Query object.
[308] Fix | Delete
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
[309] Fix | Delete
*
[310] Fix | Delete
* @param array $menu_items The current menu item objects to which to add the class property information.
[311] Fix | Delete
*/
[312] Fix | Delete
function _wp_menu_item_classes_by_context( &$menu_items ) {
[313] Fix | Delete
global $wp_query, $wp_rewrite;
[314] Fix | Delete
[315] Fix | Delete
$queried_object = $wp_query->get_queried_object();
[316] Fix | Delete
$queried_object_id = (int) $wp_query->queried_object_id;
[317] Fix | Delete
[318] Fix | Delete
$active_object = '';
[319] Fix | Delete
$active_ancestor_item_ids = array();
[320] Fix | Delete
$active_parent_item_ids = array();
[321] Fix | Delete
$active_parent_object_ids = array();
[322] Fix | Delete
$possible_taxonomy_ancestors = array();
[323] Fix | Delete
$possible_object_parents = array();
[324] Fix | Delete
$home_page_id = (int) get_option( 'page_for_posts' );
[325] Fix | Delete
[326] Fix | Delete
if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) {
[327] Fix | Delete
foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy ) {
[328] Fix | Delete
if ( is_taxonomy_hierarchical( $taxonomy ) ) {
[329] Fix | Delete
$term_hierarchy = _get_term_hierarchy( $taxonomy );
[330] Fix | Delete
$terms = wp_get_object_terms( $queried_object_id, $taxonomy, array( 'fields' => 'ids' ) );
[331] Fix | Delete
if ( is_array( $terms ) ) {
[332] Fix | Delete
$possible_object_parents = array_merge( $possible_object_parents, $terms );
[333] Fix | Delete
$term_to_ancestor = array();
[334] Fix | Delete
foreach ( (array) $term_hierarchy as $anc => $descs ) {
[335] Fix | Delete
foreach ( (array) $descs as $desc ) {
[336] Fix | Delete
$term_to_ancestor[ $desc ] = $anc;
[337] Fix | Delete
}
[338] Fix | Delete
}
[339] Fix | Delete
[340] Fix | Delete
foreach ( $terms as $desc ) {
[341] Fix | Delete
do {
[342] Fix | Delete
$possible_taxonomy_ancestors[ $taxonomy ][] = $desc;
[343] Fix | Delete
if ( isset( $term_to_ancestor[ $desc ] ) ) {
[344] Fix | Delete
$_desc = $term_to_ancestor[ $desc ];
[345] Fix | Delete
unset( $term_to_ancestor[ $desc ] );
[346] Fix | Delete
$desc = $_desc;
[347] Fix | Delete
} else {
[348] Fix | Delete
$desc = 0;
[349] Fix | Delete
}
[350] Fix | Delete
} while ( ! empty( $desc ) );
[351] Fix | Delete
}
[352] Fix | Delete
}
[353] Fix | Delete
}
[354] Fix | Delete
}
[355] Fix | Delete
} elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) {
[356] Fix | Delete
$term_hierarchy = _get_term_hierarchy( $queried_object->taxonomy );
[357] Fix | Delete
$term_to_ancestor = array();
[358] Fix | Delete
foreach ( (array) $term_hierarchy as $anc => $descs ) {
[359] Fix | Delete
foreach ( (array) $descs as $desc ) {
[360] Fix | Delete
$term_to_ancestor[ $desc ] = $anc;
[361] Fix | Delete
}
[362] Fix | Delete
}
[363] Fix | Delete
$desc = $queried_object->term_id;
[364] Fix | Delete
do {
[365] Fix | Delete
$possible_taxonomy_ancestors[ $queried_object->taxonomy ][] = $desc;
[366] Fix | Delete
if ( isset( $term_to_ancestor[ $desc ] ) ) {
[367] Fix | Delete
$_desc = $term_to_ancestor[ $desc ];
[368] Fix | Delete
unset( $term_to_ancestor[ $desc ] );
[369] Fix | Delete
$desc = $_desc;
[370] Fix | Delete
} else {
[371] Fix | Delete
$desc = 0;
[372] Fix | Delete
}
[373] Fix | Delete
} while ( ! empty( $desc ) );
[374] Fix | Delete
}
[375] Fix | Delete
[376] Fix | Delete
$possible_object_parents = array_filter( $possible_object_parents );
[377] Fix | Delete
[378] Fix | Delete
$front_page_url = home_url();
[379] Fix | Delete
$front_page_id = (int) get_option( 'page_on_front' );
[380] Fix | Delete
$privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
[381] Fix | Delete
[382] Fix | Delete
foreach ( (array) $menu_items as $key => $menu_item ) {
[383] Fix | Delete
[384] Fix | Delete
$menu_items[ $key ]->current = false;
[385] Fix | Delete
[386] Fix | Delete
$classes = (array) $menu_item->classes;
[387] Fix | Delete
$classes[] = 'menu-item';
[388] Fix | Delete
$classes[] = 'menu-item-type-' . $menu_item->type;
[389] Fix | Delete
$classes[] = 'menu-item-object-' . $menu_item->object;
[390] Fix | Delete
[391] Fix | Delete
// This menu item is set as the 'Front Page'.
[392] Fix | Delete
if ( 'post_type' === $menu_item->type && $front_page_id === (int) $menu_item->object_id ) {
[393] Fix | Delete
$classes[] = 'menu-item-home';
[394] Fix | Delete
}
[395] Fix | Delete
[396] Fix | Delete
// This menu item is set as the 'Privacy Policy Page'.
[397] Fix | Delete
if ( 'post_type' === $menu_item->type && $privacy_policy_page_id === (int) $menu_item->object_id ) {
[398] Fix | Delete
$classes[] = 'menu-item-privacy-policy';
[399] Fix | Delete
}
[400] Fix | Delete
[401] Fix | Delete
// If the menu item corresponds to a taxonomy term for the currently queried non-hierarchical post object.
[402] Fix | Delete
if ( $wp_query->is_singular && 'taxonomy' === $menu_item->type
[403] Fix | Delete
&& in_array( (int) $menu_item->object_id, $possible_object_parents, true )
[404] Fix | Delete
) {
[405] Fix | Delete
$active_parent_object_ids[] = (int) $menu_item->object_id;
[406] Fix | Delete
$active_parent_item_ids[] = (int) $menu_item->db_id;
[407] Fix | Delete
$active_object = $queried_object->post_type;
[408] Fix | Delete
[409] Fix | Delete
// If the menu item corresponds to the currently queried post or taxonomy object.
[410] Fix | Delete
} elseif (
[411] Fix | Delete
$menu_item->object_id == $queried_object_id
[412] Fix | Delete
&& (
[413] Fix | Delete
( ! empty( $home_page_id ) && 'post_type' === $menu_item->type
[414] Fix | Delete
&& $wp_query->is_home && $home_page_id == $menu_item->object_id )
[415] Fix | Delete
|| ( 'post_type' === $menu_item->type && $wp_query->is_singular )
[416] Fix | Delete
|| ( 'taxonomy' === $menu_item->type
[417] Fix | Delete
&& ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax )
[418] Fix | Delete
&& $queried_object->taxonomy == $menu_item->object )
[419] Fix | Delete
)
[420] Fix | Delete
) {
[421] Fix | Delete
$classes[] = 'current-menu-item';
[422] Fix | Delete
$menu_items[ $key ]->current = true;
[423] Fix | Delete
$_anc_id = (int) $menu_item->db_id;
[424] Fix | Delete
[425] Fix | Delete
while (
[426] Fix | Delete
( $_anc_id = (int) get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) )
[427] Fix | Delete
&& ! in_array( $_anc_id, $active_ancestor_item_ids, true )
[428] Fix | Delete
) {
[429] Fix | Delete
$active_ancestor_item_ids[] = $_anc_id;
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
if ( 'post_type' === $menu_item->type && 'page' === $menu_item->object ) {
[433] Fix | Delete
// Back compat classes for pages to match wp_page_menu().
[434] Fix | Delete
$classes[] = 'page_item';
[435] Fix | Delete
$classes[] = 'page-item-' . $menu_item->object_id;
[436] Fix | Delete
$classes[] = 'current_page_item';
[437] Fix | Delete
}
[438] Fix | Delete
[439] Fix | Delete
$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
[440] Fix | Delete
$active_parent_object_ids[] = (int) $menu_item->post_parent;
[441] Fix | Delete
$active_object = $menu_item->object;
[442] Fix | Delete
[443] Fix | Delete
// If the menu item corresponds to the currently queried post type archive.
[444] Fix | Delete
} elseif (
[445] Fix | Delete
'post_type_archive' === $menu_item->type
[446] Fix | Delete
&& is_post_type_archive( array( $menu_item->object ) )
[447] Fix | Delete
) {
[448] Fix | Delete
$classes[] = 'current-menu-item';
[449] Fix | Delete
$menu_items[ $key ]->current = true;
[450] Fix | Delete
$_anc_id = (int) $menu_item->db_id;
[451] Fix | Delete
[452] Fix | Delete
while (
[453] Fix | Delete
( $_anc_id = (int) get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) )
[454] Fix | Delete
&& ! in_array( $_anc_id, $active_ancestor_item_ids, true )
[455] Fix | Delete
) {
[456] Fix | Delete
$active_ancestor_item_ids[] = $_anc_id;
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
[460] Fix | Delete
[461] Fix | Delete
// If the menu item corresponds to the currently requested URL.
[462] Fix | Delete
} elseif ( 'custom' === $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) {
[463] Fix | Delete
$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
[464] Fix | Delete
[465] Fix | Delete
// If it's the customize page then it will strip the query var off the URL before entering the comparison block.
[466] Fix | Delete
if ( is_customize_preview() ) {
[467] Fix | Delete
$_root_relative_current = strtok( untrailingslashit( $_SERVER['REQUEST_URI'] ), '?' );
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
$current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );
[471] Fix | Delete
$raw_item_url = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
[472] Fix | Delete
$item_url = set_url_scheme( untrailingslashit( $raw_item_url ) );
[473] Fix | Delete
$_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) );
[474] Fix | Delete
[475] Fix | Delete
$matches = array(
[476] Fix | Delete
$current_url,
[477] Fix | Delete
urldecode( $current_url ),
[478] Fix | Delete
$_indexless_current,
[479] Fix | Delete
urldecode( $_indexless_current ),
[480] Fix | Delete
$_root_relative_current,
[481] Fix | Delete
urldecode( $_root_relative_current ),
[482] Fix | Delete
);
[483] Fix | Delete
[484] Fix | Delete
if ( $raw_item_url && in_array( $item_url, $matches, true ) ) {
[485] Fix | Delete
$classes[] = 'current-menu-item';
[486] Fix | Delete
$menu_items[ $key ]->current = true;
[487] Fix | Delete
$_anc_id = (int) $menu_item->db_id;
[488] Fix | Delete
[489] Fix | Delete
while (
[490] Fix | Delete
( $_anc_id = (int) get_post_meta( $_anc_id, '_menu_item_menu_item_parent', true ) )
[491] Fix | Delete
&& ! in_array( $_anc_id, $active_ancestor_item_ids, true )
[492] Fix | Delete
) {
[493] Fix | Delete
$active_ancestor_item_ids[] = $_anc_id;
[494] Fix | Delete
}
[495] Fix | Delete
[496] Fix | Delete
if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ), true ) ) {
[497] Fix | Delete
// Back compat for home link to match wp_page_menu().
[498] Fix | Delete
$classes[] = 'current_page_item';
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function