/wp-content/themes/genesis/lib/structure/menu.php

https://github.com/livinglab/openlab · PHP · 166 lines · 71 code · 26 blank · 69 comment · 11 complexity · 4afb07616b95db0c3013bd63c4bddccf MD5 · raw file

  1. <?php
  2. /**
  3. * Genesis Framework.
  4. *
  5. * WARNING: This file is part of the core Genesis Framework. DO NOT edit this file under any circumstances.
  6. * Please do all modifications in the form of a child theme.
  7. *
  8. * @package Genesis\Menus
  9. * @author StudioPress
  10. * @license GPL-2.0-or-later
  11. * @link https://my.studiopress.com/themes/genesis/
  12. */
  13. add_filter( 'nav_menu_link_attributes', 'genesis_nav_menu_link_attributes' );
  14. /**
  15. * Pass nav menu link attributes through attribute parser.
  16. *
  17. * Adds nav menu link attributes via the Genesis markup API.
  18. *
  19. * @since 2.2.0
  20. *
  21. * @param array $atts {
  22. * The HTML attributes applied to the menu item's link element, empty strings are ignored.
  23. *
  24. * @type string $title Title attribute.
  25. * @type string $target Target attribute.
  26. * @type string $rel The rel attribute.
  27. * @type string $href The href attribute.
  28. * }
  29. * @return array Maybe modified menu attributes array.
  30. */
  31. function genesis_nav_menu_link_attributes( $atts ) {
  32. if ( genesis_html5() ) {
  33. $atts = genesis_parse_attr( 'nav-link', $atts );
  34. }
  35. return $atts;
  36. }
  37. add_action( 'after_setup_theme', 'genesis_register_nav_menus' );
  38. /**
  39. * Register the custom menu locations, if theme has support for them.
  40. *
  41. * Does the `genesis_register_nav_menus` action.
  42. *
  43. * @since 1.8.0
  44. *
  45. * @return void Return early if `genesis-menus` are not supported.
  46. */
  47. function genesis_register_nav_menus() {
  48. if ( ! current_theme_supports( 'genesis-menus' ) ) {
  49. return;
  50. }
  51. $menus = get_theme_support( 'genesis-menus' );
  52. register_nav_menus( (array) $menus[0] );
  53. /**
  54. * Fires after registering custom Genesis navigation menus.
  55. *
  56. * @since 1.8.0
  57. */
  58. do_action( 'genesis_register_nav_menus' );
  59. }
  60. add_action( 'genesis_after_header', 'genesis_do_nav' );
  61. /**
  62. * Echo the "Primary Navigation" menu.
  63. *
  64. * Applies the `genesis_do_nav` filter.
  65. *
  66. * @since 1.0.0
  67. */
  68. function genesis_do_nav() {
  69. // Do nothing if menu not supported.
  70. if ( ! genesis_nav_menu_supported( 'primary' ) || ! has_nav_menu( 'primary' ) ) {
  71. return;
  72. }
  73. $class = 'menu genesis-nav-menu menu-primary';
  74. if ( genesis_superfish_enabled() ) {
  75. $class .= ' js-superfish';
  76. }
  77. genesis_nav_menu( array(
  78. 'theme_location' => 'primary',
  79. 'menu_class' => $class,
  80. ) );
  81. }
  82. add_action( 'genesis_after_header', 'genesis_do_subnav' );
  83. /**
  84. * Echo the "Secondary Navigation" menu.
  85. *
  86. * Applies the `genesis_do_subnav` filter.
  87. *
  88. * @since 1.0.0
  89. */
  90. function genesis_do_subnav() {
  91. // Do nothing if menu not supported.
  92. if ( ! genesis_nav_menu_supported( 'secondary' ) ) {
  93. return;
  94. }
  95. $class = 'menu genesis-nav-menu menu-secondary';
  96. if ( genesis_superfish_enabled() ) {
  97. $class .= ' js-superfish';
  98. }
  99. genesis_nav_menu( array(
  100. 'theme_location' => 'secondary',
  101. 'menu_class' => $class,
  102. ) );
  103. }
  104. add_filter( 'wp_nav_menu_items', 'genesis_nav_right', 10, 2 );
  105. /**
  106. * Filter the Primary Navigation menu items, appending either RSS links, search form, twitter link, or today's date.
  107. *
  108. * @since 1.0.0
  109. *
  110. * @param string $menu HTML string of list items.
  111. * @param stdClass $args Menu arguments.
  112. * @return string HTML string of list items with optional nav extras.
  113. * Return early unmodified if first Genesis version is higher than 2.0.2.
  114. */
  115. function genesis_nav_right( $menu, stdClass $args ) {
  116. // Only allow if using 2.0.2 or lower.
  117. if ( genesis_first_version_compare( '2.0.2', '>' ) ) {
  118. return $menu;
  119. }
  120. if ( 'primary' !== $args->theme_location || ! genesis_get_option( 'nav_extras' ) ) {
  121. return $menu;
  122. }
  123. switch ( genesis_get_option( 'nav_extras' ) ) {
  124. case 'rss':
  125. $rss = '<a rel="nofollow" href="' . get_bloginfo( 'rss2_url' ) . '">' . __( 'Posts', 'genesis' ) . '</a>';
  126. $rss .= '<a rel="nofollow" href="' . get_bloginfo( 'comments_rss2_url' ) . '">' . __( 'Comments', 'genesis' ) . '</a>';
  127. $menu .= '<li class="right rss">' . $rss . '</li>';
  128. break;
  129. case 'search':
  130. $menu .= '<li class="right search">' . get_search_form( false ) . '</li>';
  131. break;
  132. case 'twitter':
  133. $menu .= sprintf( '<li class="right twitter"><a href="%s">%s</a></li>', esc_url( 'https://twitter.com/' . genesis_get_option( 'nav_extras_twitter_id' ) ), esc_html( genesis_get_option( 'nav_extras_twitter_text' ) ) );
  134. break;
  135. case 'date':
  136. $menu .= '<li class="right date">' . date_i18n( get_option( 'date_format' ) ) . '</li>';
  137. break;
  138. }
  139. return $menu;
  140. }