wp/wp-includes/nav-menu-template.php
author ymh <ymh.work@gmail.com>
Mon, 08 Sep 2025 19:44:41 +0200
changeset 23 417f20492bf7
parent 22 8c2e4d02f4ef
permissions -rw-r--r--
Update Docker configuration and plugin versions - Upgrade MariaDB from 10.6 to 11 with auto-upgrade support - Add WordPress debug environment variable to FPM container - Update PHP-FPM Dockerfile base image - Update Include Mastodon Feed plugin with bug fixes and improvements - Update Portfolio plugin (v2.58) with latest translations and demo data enhancements - Remove old README.md from Mastodon Feed plugin 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
     3
 * Nav Menu API: Template functions
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @subpackage Nav_Menus
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
22
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
    10
// Don't load directly.
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
    11
if ( ! defined( 'ABSPATH' ) ) {
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
    12
	die( '-1' );
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
    13
}
8c2e4d02f4ef Update WordPress to latest version (6.7)
ymh <ymh.work@gmail.com>
parents: 21
diff changeset
    14
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    15
/** Walker_Nav_Menu class */
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    16
require_once ABSPATH . WPINC . '/class-walker-nav-menu.php';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
 * Displays a navigation menu.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    22
 * @since 4.7.0 Added the `item_spacing` argument.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    23
 * @since 5.5.0 Added the `container_aria_label` argument.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    25
 * @param array $args {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    26
 *     Optional. Array of nav menu arguments.
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    27
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    28
 *     @type int|string|WP_Term $menu                 Desired menu. Accepts a menu ID, slug, name, or object.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    29
 *                                                    Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    30
 *     @type string             $menu_class           CSS class to use for the ul element which forms the menu.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    31
 *                                                    Default 'menu'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    32
 *     @type string             $menu_id              The ID that is applied to the ul element which forms the menu.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    33
 *                                                    Default is the menu slug, incremented.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    34
 *     @type string             $container            Whether to wrap the ul, and what to wrap it with.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    35
 *                                                    Default 'div'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    36
 *     @type string             $container_class      Class that is applied to the container.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    37
 *                                                    Default 'menu-{menu slug}-container'.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    38
 *     @type string             $container_id         The ID that is applied to the container. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    39
 *     @type string             $container_aria_label The aria-label attribute that is applied to the container
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    40
 *                                                    when it's a nav element. Default empty.
18
be944660c56a Site enmi version 09/2022
ymh <ymh.work@gmail.com>
parents: 16
diff changeset
    41
 *     @type callable|false     $fallback_cb          If the menu doesn't exist, a callback function will fire.
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    42
 *                                                    Default is 'wp_page_menu'. Set to false for no fallback.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    43
 *     @type string             $before               Text before the link markup. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    44
 *     @type string             $after                Text after the link markup. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    45
 *     @type string             $link_before          Text before the link text. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    46
 *     @type string             $link_after           Text after the link text. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    47
 *     @type bool               $echo                 Whether to echo the menu or return it. Default true.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    48
 *     @type int                $depth                How many levels of the hierarchy are to be included.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    49
 *                                                    0 means all. Default 0.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    50
 *                                                    Default 0.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    51
 *     @type object             $walker               Instance of a custom walker class. Default empty.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    52
 *     @type string             $theme_location       Theme location to be used. Must be registered with
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    53
 *                                                    register_nav_menu() in order to be selectable by the user.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    54
 *     @type string             $items_wrap           How the list items should be wrapped. Uses printf() format with
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    55
 *                                                    numbered placeholders. Default is a ul with an id and class.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    56
 *     @type string             $item_spacing         Whether to preserve whitespace within the menu's HTML.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    57
 *                                                    Accepts 'preserve' or 'discard'. Default 'preserve'.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    58
 * }
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    59
 * @return void|string|false Void if 'echo' argument is true, menu output if 'echo' is false.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    60
 *                           False if there are no items or no menu was found.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
function wp_nav_menu( $args = array() ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
	static $menu_id_slugs = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    65
	$defaults = array(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    66
		'menu'                 => '',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    67
		'container'            => 'div',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    68
		'container_class'      => '',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    69
		'container_id'         => '',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    70
		'container_aria_label' => '',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    71
		'menu_class'           => 'menu',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    72
		'menu_id'              => '',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    73
		'echo'                 => true,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    74
		'fallback_cb'          => 'wp_page_menu',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    75
		'before'               => '',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    76
		'after'                => '',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    77
		'link_before'          => '',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    78
		'link_after'           => '',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    79
		'items_wrap'           => '<ul id="%1$s" class="%2$s">%3$s</ul>',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    80
		'item_spacing'         => 'preserve',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    81
		'depth'                => 0,
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    82
		'walker'               => '',
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    83
		'theme_location'       => '',
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
    84
	);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
	$args = wp_parse_args( $args, $defaults );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    87
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    88
	if ( ! in_array( $args['item_spacing'], array( 'preserve', 'discard' ), true ) ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
    89
		// Invalid value, fall back to default.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    90
		$args['item_spacing'] = $defaults['item_spacing'];
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    91
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    92
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
    94
	 * Filters the arguments used to display a navigation menu.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    98
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
    99
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   100
	 * @param array $args Array of wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
	$args = apply_filters( 'wp_nav_menu_args', $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
	$args = (object) $args;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   105
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   106
	 * Filters whether to short-circuit the wp_nav_menu() output.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   107
	 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   108
	 * Returning a non-null value from the filter will short-circuit wp_nav_menu(),
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   109
	 * echoing that value if $args->echo is true, returning that value otherwise.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   110
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   111
	 * @since 3.9.0
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   112
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   113
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   114
	 *
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   115
	 * @param string|null $output Nav menu output to short-circuit with. Default null.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   116
	 * @param stdClass    $args   An object containing wp_nav_menu() arguments.
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   117
	 */
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   118
	$nav_menu = apply_filters( 'pre_wp_nav_menu', null, $args );
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   119
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   120
	if ( null !== $nav_menu ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   121
		if ( $args->echo ) {
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   122
			echo $nav_menu;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   123
			return;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   124
		}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   125
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   126
		return $nav_menu;
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   127
	}
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   128
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   129
	// Get the nav menu based on the requested menu.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
	$menu = wp_get_nav_menu_object( $args->menu );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   132
	// Get the nav menu based on the theme_location.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   133
	$locations = get_nav_menu_locations();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   134
	if ( ! $menu && $args->theme_location && $locations && isset( $locations[ $args->theme_location ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
		$menu = wp_get_nav_menu_object( $locations[ $args->theme_location ] );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   136
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   138
	// Get the first menu that has items if we still can't find a menu.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   139
	if ( ! $menu && ! $args->theme_location ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
		$menus = wp_get_nav_menus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
		foreach ( $menus as $menu_maybe ) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   142
			$menu_items = wp_get_nav_menu_items( $menu_maybe->term_id, array( 'update_post_term_cache' => false ) );
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   143
			if ( $menu_items ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
				$menu = $menu_maybe;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
				break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   150
	if ( empty( $args->menu ) ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   151
		$args->menu = $menu;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   152
	}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   153
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
	// If the menu exists, get its items.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   155
	if ( $menu && ! is_wp_error( $menu ) && ! isset( $menu_items ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
		$menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   157
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
	/*
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
	 * If no menu was found:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
	 *  - Fall back (if one was specified), or bail.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
	 * If no menu items were found:
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
	 *  - Fall back, but only if no theme location was specified.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
	 *  - Otherwise, bail.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
	 */
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   167
	if ( ( ! $menu || is_wp_error( $menu ) || ( isset( $menu_items ) && empty( $menu_items ) && ! $args->theme_location ) )
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   168
		&& isset( $args->fallback_cb ) && $args->fallback_cb && is_callable( $args->fallback_cb ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
			return call_user_func( $args->fallback_cb, (array) $args );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   170
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   172
	if ( ! $menu || is_wp_error( $menu ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   174
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   176
	$nav_menu = '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   177
	$items    = '';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
	$show_container = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
	if ( $args->container ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
		/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   182
		 * Filters the list of HTML tags that are valid for use as menu containers.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
		 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
		 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
		 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   186
		 * @param string[] $tags The acceptable HTML tags for use as menu containers.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   187
		 *                       Default is array containing 'div' and 'nav'.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
		 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
		$allowed_tags = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   190
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   191
		if ( is_string( $args->container ) && in_array( $args->container, $allowed_tags, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
			$show_container = true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   193
			$class          = $args->container_class ? ' class="' . esc_attr( $args->container_class ) . '"' : ' class="menu-' . $menu->slug . '-container"';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   194
			$id             = $args->container_id ? ' id="' . esc_attr( $args->container_id ) . '"' : '';
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   195
			$aria_label     = ( 'nav' === $args->container && $args->container_aria_label ) ? ' aria-label="' . esc_attr( $args->container_aria_label ) . '"' : '';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   196
			$nav_menu      .= '<' . $args->container . $id . $class . $aria_label . '>';
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   200
	// Set up the $menu_item variables.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
	_wp_menu_item_classes_by_context( $menu_items );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   203
	$sorted_menu_items        = array();
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   204
	$menu_items_with_children = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
	foreach ( (array) $menu_items as $menu_item ) {
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   206
		/*
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   207
		 * Fix invalid `menu_item_parent`. See: https://core.trac.wordpress.org/ticket/56926.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   208
		 * Compare as strings. Plugins may change the ID to a string.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   209
		 */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   210
		if ( (string) $menu_item->ID === (string) $menu_item->menu_item_parent ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   211
			$menu_item->menu_item_parent = 0;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   212
		}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   213
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
		$sorted_menu_items[ $menu_item->menu_order ] = $menu_item;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   215
		if ( $menu_item->menu_item_parent ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
			$menu_items_with_children[ $menu_item->menu_item_parent ] = true;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   217
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   220
	// Add the menu-item-has-children class where applicable.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
	if ( $menu_items_with_children ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		foreach ( $sorted_menu_items as &$menu_item ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   223
			if ( isset( $menu_items_with_children[ $menu_item->ID ] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
				$menu_item->classes[] = 'menu-item-has-children';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   225
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
	unset( $menu_items, $menu_item );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   232
	 * Filters the sorted list of menu item objects before generating the menu's HTML.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
	 * @since 3.1.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   236
	 * @param array    $sorted_menu_items The menu items, sorted by each menu item's menu order.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   237
	 * @param stdClass $args              An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
	$sorted_menu_items = apply_filters( 'wp_nav_menu_objects', $sorted_menu_items, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
	$items .= walk_nav_menu_tree( $sorted_menu_items, $args->depth, $args );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   242
	unset( $sorted_menu_items );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   244
	// Attributes.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
	if ( ! empty( $args->menu_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
		$wrap_id = $args->menu_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
	} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
		$wrap_id = 'menu-' . $menu->slug;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   249
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   250
		while ( in_array( $wrap_id, $menu_id_slugs, true ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   251
			if ( preg_match( '#-(\d+)$#', $wrap_id, $matches ) ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   252
				$wrap_id = preg_replace( '#-(\d+)$#', '-' . ++$matches[1], $wrap_id );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   253
			} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
				$wrap_id = $wrap_id . '-1';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   255
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
	$menu_id_slugs[] = $wrap_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
	$wrap_class = $args->menu_class ? $args->menu_class : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   263
	 * Filters the HTML list content for navigation menus.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   267
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   268
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   269
	 * @param string   $items The HTML list content for the menu items.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   270
	 * @param stdClass $args  An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
	$items = apply_filters( 'wp_nav_menu_items', $items, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   274
	 * Filters the HTML list content for a specific navigation menu.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   278
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   279
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   280
	 * @param string   $items The HTML list content for the menu items.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   281
	 * @param stdClass $args  An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
	$items = apply_filters( "wp_nav_menu_{$menu->slug}_items", $items, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
	// Don't print any markup if there are no items at this point.
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   286
	if ( empty( $items ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
		return false;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   288
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
	$nav_menu .= sprintf( $args->items_wrap, esc_attr( $wrap_id ), esc_attr( $wrap_class ), $items );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
	unset( $items );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   293
	if ( $show_container ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
		$nav_menu .= '</' . $args->container . '>';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   295
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
	/**
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   298
	 * Filters the HTML content for navigation menus.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
	 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
	 * @since 3.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
	 *
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   302
	 * @see wp_nav_menu()
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   303
	 *
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   304
	 * @param string   $nav_menu The HTML content for the navigation menu.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   305
	 * @param stdClass $args     An object containing wp_nav_menu() arguments.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
	 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
	$nav_menu = apply_filters( 'wp_nav_menu', $nav_menu, $args );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   309
	if ( $args->echo ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
		echo $nav_menu;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   311
	} else {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
		return $nav_menu;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   313
	}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   317
 * Adds the class property classes for the current context, if applicable.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
 * @access private
5
5e2f62d02dcd upgrade wordpress + plugins
ymh <ymh.work@gmail.com>
parents: 0
diff changeset
   320
 * @since 3.0.0
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
 *
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   322
 * @global WP_Query   $wp_query   WordPress Query object.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   323
 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   324
 *
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
 * @param array $menu_items The current menu item objects to which to add the class property information.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
function _wp_menu_item_classes_by_context( &$menu_items ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
	global $wp_query, $wp_rewrite;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   330
	$queried_object    = $wp_query->get_queried_object();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
	$queried_object_id = (int) $wp_query->queried_object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   333
	$active_object               = '';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   334
	$active_ancestor_item_ids    = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   335
	$active_parent_item_ids      = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   336
	$active_parent_object_ids    = array();
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
	$possible_taxonomy_ancestors = array();
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   338
	$possible_object_parents     = array();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   339
	$home_page_id                = (int) get_option( 'page_for_posts' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
	if ( $wp_query->is_singular && ! empty( $queried_object->post_type ) && ! is_post_type_hierarchical( $queried_object->post_type ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
		foreach ( (array) get_object_taxonomies( $queried_object->post_type ) as $taxonomy ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
			if ( is_taxonomy_hierarchical( $taxonomy ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
				$term_hierarchy = _get_term_hierarchy( $taxonomy );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   345
				$terms          = wp_get_object_terms( $queried_object_id, $taxonomy, array( 'fields' => 'ids' ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
				if ( is_array( $terms ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
					$possible_object_parents = array_merge( $possible_object_parents, $terms );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   348
					$term_to_ancestor        = array();
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   349
					foreach ( (array) $term_hierarchy as $ancestor => $descendents ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   350
						foreach ( (array) $descendents as $desc ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   351
							$term_to_ancestor[ $desc ] = $ancestor;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   352
						}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
					foreach ( $terms as $desc ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
						do {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
							$possible_taxonomy_ancestors[ $taxonomy ][] = $desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
							if ( isset( $term_to_ancestor[ $desc ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
								$_desc = $term_to_ancestor[ $desc ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
								unset( $term_to_ancestor[ $desc ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
								$desc = $_desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
							} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
								$desc = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
						} while ( ! empty( $desc ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
	} elseif ( ! empty( $queried_object->taxonomy ) && is_taxonomy_hierarchical( $queried_object->taxonomy ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   371
		$term_hierarchy   = _get_term_hierarchy( $queried_object->taxonomy );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
		$term_to_ancestor = array();
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   373
		foreach ( (array) $term_hierarchy as $ancestor => $descendents ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   374
			foreach ( (array) $descendents as $desc ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   375
				$term_to_ancestor[ $desc ] = $ancestor;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   376
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
		$desc = $queried_object->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
		do {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
			$possible_taxonomy_ancestors[ $queried_object->taxonomy ][] = $desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
			if ( isset( $term_to_ancestor[ $desc ] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
				$_desc = $term_to_ancestor[ $desc ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
				unset( $term_to_ancestor[ $desc ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
				$desc = $_desc;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
				$desc = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
		} while ( ! empty( $desc ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
	$possible_object_parents = array_filter( $possible_object_parents );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   393
	$front_page_url         = home_url();
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   394
	$front_page_id          = (int) get_option( 'page_on_front' );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   395
	$privacy_policy_page_id = (int) get_option( 'wp_page_for_privacy_policy' );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
	foreach ( (array) $menu_items as $key => $menu_item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   399
		$menu_items[ $key ]->current = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   401
		$classes   = (array) $menu_item->classes;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
		$classes[] = 'menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
		$classes[] = 'menu-item-type-' . $menu_item->type;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
		$classes[] = 'menu-item-object-' . $menu_item->object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   406
		// This menu item is set as the 'Front Page'.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   407
		if ( 'post_type' === $menu_item->type && $front_page_id === (int) $menu_item->object_id ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   408
			$classes[] = 'menu-item-home';
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   409
		}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   410
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   411
		// This menu item is set as the 'Privacy Policy Page'.
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   412
		if ( 'post_type' === $menu_item->type && $privacy_policy_page_id === (int) $menu_item->object_id ) {
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   413
			$classes[] = 'menu-item-privacy-policy';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   414
		}
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   415
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   416
		// If the menu item corresponds to a taxonomy term for the currently queried non-hierarchical post object.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   417
		if ( $wp_query->is_singular && 'taxonomy' === $menu_item->type
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   418
			&& in_array( (int) $menu_item->object_id, $possible_object_parents, true )
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   419
		) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
			$active_parent_object_ids[] = (int) $menu_item->object_id;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   421
			$active_parent_item_ids[]   = (int) $menu_item->db_id;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   422
			$active_object              = $queried_object->post_type;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   424
			// If the menu item corresponds to the currently queried post or taxonomy object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
		} elseif (
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   426
			(int) $menu_item->object_id === $queried_object_id
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   427
			&& (
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   428
				( ! empty( $home_page_id ) && 'post_type' === $menu_item->type
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   429
					&& $wp_query->is_home && $home_page_id === (int) $menu_item->object_id )
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   430
				|| ( 'post_type' === $menu_item->type && $wp_query->is_singular )
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   431
				|| ( 'taxonomy' === $menu_item->type
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   432
					&& ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax )
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   433
					&& $queried_object->taxonomy === $menu_item->object )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
			)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
		) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   436
			$classes[]                   = 'current-menu-item';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   437
			$menu_items[ $key ]->current = true;
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   438
			$ancestor_id                 = (int) $menu_item->db_id;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   440
			while (
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   441
				( $ancestor_id = (int) get_post_meta( $ancestor_id, '_menu_item_menu_item_parent', true ) )
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   442
				&& ! in_array( $ancestor_id, $active_ancestor_item_ids, true )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
			) {
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   444
				$active_ancestor_item_ids[] = $ancestor_id;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   447
			if ( 'post_type' === $menu_item->type && 'page' === $menu_item->object ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   448
				// Back compat classes for pages to match wp_page_menu().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
				$classes[] = 'page_item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
				$classes[] = 'page-item-' . $menu_item->object_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
				$classes[] = 'current_page_item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
			}
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   453
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   454
			$active_parent_item_ids[]   = (int) $menu_item->menu_item_parent;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
			$active_parent_object_ids[] = (int) $menu_item->post_parent;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   456
			$active_object              = $menu_item->object;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   458
			// If the menu item corresponds to the currently queried post type archive.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   459
		} elseif (
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   460
			'post_type_archive' === $menu_item->type
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   461
			&& is_post_type_archive( array( $menu_item->object ) )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   462
		) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   463
			$classes[]                   = 'current-menu-item';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   464
			$menu_items[ $key ]->current = true;
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   465
			$ancestor_id                 = (int) $menu_item->db_id;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   466
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   467
			while (
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   468
				( $ancestor_id = (int) get_post_meta( $ancestor_id, '_menu_item_menu_item_parent', true ) )
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   469
				&& ! in_array( $ancestor_id, $active_ancestor_item_ids, true )
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   470
			) {
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   471
				$active_ancestor_item_ids[] = $ancestor_id;
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   472
			}
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   473
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   474
			$active_parent_item_ids[] = (int) $menu_item->menu_item_parent;
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   475
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   476
			// If the menu item corresponds to the currently requested URL.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   477
		} elseif ( 'custom' === $menu_item->object && isset( $_SERVER['HTTP_HOST'] ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
			$_root_relative_current = untrailingslashit( $_SERVER['REQUEST_URI'] );
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   479
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   480
			// If it's the customize page then it will strip the query var off the URL before entering the comparison block.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   481
			if ( is_customize_preview() ) {
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   482
				$_root_relative_current = strtok( untrailingslashit( $_SERVER['REQUEST_URI'] ), '?' );
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   483
			}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   484
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   485
			$current_url        = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_root_relative_current );
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   486
			$raw_item_url       = strpos( $menu_item->url, '#' ) ? substr( $menu_item->url, 0, strpos( $menu_item->url, '#' ) ) : $menu_item->url;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   487
			$item_url           = set_url_scheme( untrailingslashit( $raw_item_url ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
			$_indexless_current = untrailingslashit( preg_replace( '/' . preg_quote( $wp_rewrite->index, '/' ) . '$/', '', $current_url ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   490
			$matches = array(
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   491
				$current_url,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   492
				urldecode( $current_url ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   493
				$_indexless_current,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   494
				urldecode( $_indexless_current ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   495
				$_root_relative_current,
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   496
				urldecode( $_root_relative_current ),
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   497
			);
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   499
			if ( $raw_item_url && in_array( $item_url, $matches, true ) ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   500
				$classes[]                   = 'current-menu-item';
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   501
				$menu_items[ $key ]->current = true;
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   502
				$ancestor_id                 = (int) $menu_item->db_id;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   503
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   504
				while (
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   505
					( $ancestor_id = (int) get_post_meta( $ancestor_id, '_menu_item_menu_item_parent', true ) )
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   506
					&& ! in_array( $ancestor_id, $active_ancestor_item_ids, true )
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
				) {
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   508
					$active_ancestor_item_ids[] = $ancestor_id;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   511
				if ( in_array( home_url(), array( untrailingslashit( $current_url ), untrailingslashit( $_indexless_current ) ), true ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   512
					// Back compat for home link to match wp_page_menu().
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
					$classes[] = 'current_page_item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
				}
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   515
				$active_parent_item_ids[]   = (int) $menu_item->menu_item_parent;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
				$active_parent_object_ids[] = (int) $menu_item->post_parent;
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   517
				$active_object              = $menu_item->object;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   519
				// Give front page item the 'current-menu-item' class when extra query arguments are involved.
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   520
			} elseif ( $item_url === $front_page_url && is_front_page() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
				$classes[] = 'current-menu-item';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   524
			if ( untrailingslashit( $item_url ) === home_url() ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
				$classes[] = 'menu-item-home';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   526
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   529
		// Back-compat with wp_page_menu(): add "current_page_parent" to static home page link for any non-page query.
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   530
		if ( ! empty( $home_page_id ) && 'post_type' === $menu_item->type
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   531
			&& empty( $wp_query->is_page ) && $home_page_id === (int) $menu_item->object_id
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   532
		) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
			$classes[] = 'current_page_parent';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   534
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   536
		$menu_items[ $key ]->classes = array_unique( $classes );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
	$active_ancestor_item_ids = array_filter( array_unique( $active_ancestor_item_ids ) );
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   539
	$active_parent_item_ids   = array_filter( array_unique( $active_parent_item_ids ) );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
	$active_parent_object_ids = array_filter( array_unique( $active_parent_object_ids ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   542
	// Set parent's class.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
	foreach ( (array) $menu_items as $key => $parent_item ) {
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   544
		$classes                                   = (array) $parent_item->classes;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   545
		$menu_items[ $key ]->current_item_ancestor = false;
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   546
		$menu_items[ $key ]->current_item_parent   = false;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
		if (
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   549
			isset( $parent_item->type )
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   550
			&& (
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   551
				// Ancestral post object.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
				(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   553
					'post_type' === $parent_item->type
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   554
					&& ! empty( $queried_object->post_type )
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   555
					&& is_post_type_hierarchical( $queried_object->post_type )
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   556
					&& in_array( (int) $parent_item->object_id, $queried_object->ancestors, true )
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   557
					&& (int) $parent_item->object_id !== $queried_object->ID
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
				) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   560
				// Ancestral term.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
				(
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   562
					'taxonomy' === $parent_item->type
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   563
					&& isset( $possible_taxonomy_ancestors[ $parent_item->object ] )
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   564
					&& in_array( (int) $parent_item->object_id, $possible_taxonomy_ancestors[ $parent_item->object ], true )
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   565
					&& (
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
						! isset( $queried_object->term_id ) ||
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   567
						(int) $parent_item->object_id !== $queried_object->term_id
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
					)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
				)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
			)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
		) {
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   572
			if ( ! empty( $queried_object->taxonomy ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   573
				$classes[] = 'current-' . $queried_object->taxonomy . '-ancestor';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   574
			} else {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   575
				$classes[] = 'current-' . $queried_object->post_type . '-ancestor';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   576
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   579
		if ( in_array( (int) $parent_item->db_id, $active_ancestor_item_ids, true ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   580
			$classes[] = 'current-menu-ancestor';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   581
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   582
			$menu_items[ $key ]->current_item_ancestor = true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   584
		if ( in_array( (int) $parent_item->db_id, $active_parent_item_ids, true ) ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   585
			$classes[] = 'current-menu-parent';
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   586
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   587
			$menu_items[ $key ]->current_item_parent = true;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
		}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   589
		if ( in_array( (int) $parent_item->object_id, $active_parent_object_ids, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
			$classes[] = 'current-' . $active_object . '-parent';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   591
		}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   593
		if ( 'post_type' === $parent_item->type && 'page' === $parent_item->object ) {
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   594
			// Back compat classes for pages to match wp_page_menu().
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   595
			if ( in_array( 'current-menu-parent', $classes, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
				$classes[] = 'current_page_parent';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   597
			}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   598
			if ( in_array( 'current-menu-ancestor', $classes, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
				$classes[] = 'current_page_ancestor';
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   600
			}
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
9
177826044cd9 upgrade wordpress to 5.2.3
ymh <ymh.work@gmail.com>
parents: 7
diff changeset
   603
		$menu_items[ $key ]->classes = array_unique( $classes );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
	}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
/**
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   608
 * Retrieves the HTML list content for nav menu items.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
 * @uses Walker_Nav_Menu to create HTML list content.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
 * @since 3.0.0
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   612
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   613
 * @param array    $items The menu items, sorted by each menu item's menu order.
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   614
 * @param int      $depth Depth of the item in reference to parents.
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   615
 * @param stdClass $args  An object containing wp_nav_menu() arguments.
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   616
 * @return string The HTML list content for the menu items.
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
 */
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   618
function walk_nav_menu_tree( $items, $depth, $args ) {
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   619
	$walker = ( empty( $args->walker ) ) ? new Walker_Nav_Menu() : $args->walker;
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
19
3d72ae0968f4 upgrade wordpress to 6.0.2
ymh <ymh.work@gmail.com>
parents: 18
diff changeset
   621
	return $walker->walk( $items, $depth, $args );
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
 * Prevents a menu item ID from being used more than once.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
 * @since 3.0.1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
 * @access private
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   629
 *
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   630
 * @param string $id
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   631
 * @param object $item
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   632
 * @return string
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
function _nav_menu_item_id_use_once( $id, $item ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
	static $_used_ids = array();
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   636
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   637
	if ( in_array( $item->ID, $_used_ids, true ) ) {
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
		return '';
7
cf61fcea0001 resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents: 5
diff changeset
   639
	}
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   640
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
	$_used_ids[] = $item->ID;
16
a86126ab1dd4 update enmi-conf
ymh <ymh.work@gmail.com>
parents: 9
diff changeset
   642
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
	return $id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
}
21
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   645
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   646
/**
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   647
 * Remove the `menu-item-has-children` class from bottom level menu items.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   648
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   649
 * This runs on the {@see 'nav_menu_css_class'} filter. The $args and $depth
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   650
 * parameters were added after the filter was originally introduced in
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   651
 * WordPress 3.0.0 so this needs to allow for cases in which the filter is
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   652
 * called without them.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   653
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   654
 * @see https://core.trac.wordpress.org/ticket/56926
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   655
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   656
 * @since 6.2.0
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   657
 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   658
 * @param string[]       $classes   Array of the CSS classes that are applied to the menu item's `<li>` element.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   659
 * @param WP_Post        $menu_item The current menu item object.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   660
 * @param stdClass|false $args      An object of wp_nav_menu() arguments. Default false ($args unspecified when filter is called).
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   661
 * @param int|false      $depth     Depth of menu item. Default false ($depth unspecified when filter is called).
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   662
 * @return string[] Modified nav menu classes.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   663
 */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   664
function wp_nav_menu_remove_menu_item_has_children_class( $classes, $menu_item, $args = false, $depth = false ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   665
	/*
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   666
	 * Account for the filter being called without the $args or $depth parameters.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   667
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   668
	 * This occurs when a theme uses a custom walker calling the `nav_menu_css_class`
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   669
	 * filter using the legacy formats prior to the introduction of the $args and
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   670
	 * $depth parameters.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   671
	 *
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   672
	 * As both of these parameters are required for this function to determine
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   673
	 * both the current and maximum depth of the menu tree, the function does not
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   674
	 * attempt to remove the `menu-item-has-children` class if these parameters
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   675
	 * are not set.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   676
	 */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   677
	if ( false === $depth || false === $args ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   678
		return $classes;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   679
	}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   680
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   681
	// Max-depth is 1-based.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   682
	$max_depth = isset( $args->depth ) ? (int) $args->depth : 0;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   683
	// Depth is 0-based so needs to be increased by one.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   684
	$depth = $depth + 1;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   685
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   686
	// Complete menu tree is displayed.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   687
	if ( 0 === $max_depth ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   688
		return $classes;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   689
	}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   690
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   691
	/*
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   692
	 * Remove the `menu-item-has-children` class from bottom level menu items.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   693
	 * -1 is used to display all menu items in one level so the class should
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   694
	 * be removed from all menu items.
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   695
	 */
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   696
	if ( -1 === $max_depth || $depth >= $max_depth ) {
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   697
		$classes = array_diff( $classes, array( 'menu-item-has-children' ) );
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   698
	}
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   699
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   700
	return $classes;
48c4eec2b7e6 Add CLAUDE.md documentation and sync WordPress core files
ymh <ymh.work@gmail.com>
parents: 19
diff changeset
   701
}