[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-includes/ -> nav-menu-template.php (source)

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


Generated: Tue Oct 22 08:20:01 2019 Cross-referenced by PHPXref 0.7