PageRenderTime 69ms CodeModel.GetById 41ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/konscript/hybrid-core/classes/widget-nav-menu.php

https://github.com/konscript/schroderpartners
PHP | 224 lines | 148 code | 26 blank | 50 comment | 1 complexity | 4a6dbe4c07e71f2bd05af38f550ef30b MD5 | raw file
  1. <?php
  2. /**
  3. * The nav menu widget was created to give users the ability to show nav menus created from the
  4. * Menus screen, by the theme, or by plugins using the wp_nav_menu() function. It replaces the default
  5. * WordPress navigation menu class.
  6. *
  7. * @package Hybrid
  8. * @subpackage Classes
  9. */
  10. /**
  11. * Nav Menu Widget Class
  12. *
  13. * @since 0.8.0
  14. * @link http://themehybrid.com/themes/hybrid/widgets
  15. */
  16. class Hybrid_Widget_Nav_Menu extends WP_Widget {
  17. /**
  18. * Prefix for the widget.
  19. * @since 0.8.0
  20. */
  21. var $prefix;
  22. /**
  23. * Textdomain for the widget.
  24. * @since 0.8.0
  25. */
  26. var $textdomain;
  27. /**
  28. * Set up the widget's unique name, ID, class, description, and other options.
  29. * @since 0.8.0
  30. */
  31. function Hybrid_Widget_Nav_Menu() {
  32. /* Set the widget prefix. */
  33. $this->prefix = hybrid_get_prefix();
  34. /* Set the widget textdomain. */
  35. $this->textdomain = hybrid_get_textdomain();
  36. /* Set up the widget options. */
  37. $widget_options = array(
  38. 'classname' => 'nav-menu',
  39. 'description' => esc_html__( 'An advanced widget that gives you total control over the output of your menus.', $this->textdomain )
  40. );
  41. /* Set up the widget control options. */
  42. $control_options = array(
  43. 'width' => 525,
  44. 'height' => 350,
  45. 'id_base' => "{$this->prefix}-nav-menu"
  46. );
  47. /* Create the widget. */
  48. $this->WP_Widget( "{$this->prefix}-nav-menu", esc_attr__( 'Navigation Menu', $this->textdomain ), $widget_options, $control_options );
  49. }
  50. /**
  51. * Outputs the widget based on the arguments input through the widget controls.
  52. * @since 0.8.0
  53. */
  54. function widget( $args, $instance ) {
  55. extract( $args );
  56. /* Set up the arguments for the wp_nav_menu() function. */
  57. $args = array(
  58. 'menu' => $instance['menu'],
  59. 'container' => $instance['container'],
  60. 'container_id' => $instance['container_id'],
  61. 'container_class' => $instance['container_class'],
  62. 'menu_id' => $instance['menu_id'],
  63. 'menu_class' => $instance['menu_class'],
  64. 'link_before' => $instance['link_before'],
  65. 'link_after' => $instance['link_after'],
  66. 'before' => $instance['before'],
  67. 'after' => $instance['after'],
  68. 'depth' => intval( $instance['depth'] ),
  69. 'fallback_cb' => $instance['fallback_cb'],
  70. 'walker' => $instance['walker'],
  71. 'echo' => false
  72. );
  73. /* Output the theme's widget wrapper. */
  74. echo $before_widget;
  75. /* If a title was input by the user, display it. */
  76. if ( !empty( $instance['title'] ) )
  77. echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
  78. /* Output the nav menu. */
  79. echo str_replace( array( "\r", "\n", "\t" ), '', wp_nav_menu( $args ) );
  80. /* Close the theme's widget wrapper. */
  81. echo $after_widget;
  82. }
  83. /**
  84. * Updates the widget control options for the particular instance of the widget.
  85. * @since 0.8.0
  86. */
  87. function update( $new_instance, $old_instance ) {
  88. $instance = $old_instance;
  89. $instance = $new_instance;
  90. $instance['title'] = strip_tags( $new_instance['title'] );
  91. $instance['depth'] = strip_tags( $new_instance['depth'] );
  92. $instance['container_id'] = strip_tags( $new_instance['container_id'] );
  93. $instance['container_class'] = strip_tags( $new_instance['container_class'] );
  94. $instance['menu_id'] = strip_tags( $new_instance['menu_id'] );
  95. $instance['menu_class'] = strip_tags( $new_instance['menu_class'] );
  96. $instance['fallback_cb'] = strip_tags( $new_instance['fallback_cb'] );
  97. $instance['walker'] = strip_tags( $new_instance['walker'] );
  98. return $instance;
  99. }
  100. /**
  101. * Displays the widget control options in the Widgets admin screen.
  102. * @since 0.8.0
  103. */
  104. function form( $instance ) {
  105. /* Set up the default form values. */
  106. $defaults = array(
  107. 'title' => esc_attr__( 'Navigation', $this->textdomain ),
  108. 'menu' => '',
  109. 'container' => 'div',
  110. 'container_id' => '',
  111. 'container_class' => '',
  112. 'menu_id' => '',
  113. 'menu_class' => 'nav-menu',
  114. 'depth' => 0,
  115. 'before' => '',
  116. 'after' => '',
  117. 'link_before' => '',
  118. 'link_after' => '',
  119. 'fallback_cb' => 'wp_page_menu',
  120. 'walker' => ''
  121. );
  122. /* Merge the user-selected arguments with the defaults. */
  123. $instance = wp_parse_args( (array) $instance, $defaults );
  124. $container = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
  125. ?>
  126. <div class="hybrid-widget-controls columns-2">
  127. <p>
  128. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', $this->textdomain ); ?></label>
  129. <input type="text" class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" />
  130. </p>
  131. <p>
  132. <label for="<?php echo $this->get_field_id( 'menu' ); ?>"><code>menu</code></label>
  133. <select class="widefat" id="<?php echo $this->get_field_id( 'menu' ); ?>" name="<?php echo $this->get_field_name( 'menu' ); ?>">
  134. <?php foreach ( wp_get_nav_menus() as $menu ) { ?>
  135. <option value="<?php echo esc_attr( $menu->term_id ); ?>" <?php selected( $instance['menu'], $menu->term_id ); ?>><?php echo esc_html( $menu->name ); ?></option>
  136. <?php } ?>
  137. </select>
  138. </p>
  139. <p>
  140. <label for="<?php echo $this->get_field_id( 'container' ); ?>"><code>container</code></label>
  141. <select class="smallfat" id="<?php echo $this->get_field_id( 'container' ); ?>" name="<?php echo $this->get_field_name( 'container' ); ?>">
  142. <?php foreach ( $container as $option ) { ?>
  143. <option value="<?php echo esc_attr( $option ); ?>" <?php selected( $instance['container'], $option ); ?>><?php echo esc_html( $option ); ?></option>
  144. <?php } ?>
  145. </select>
  146. </p>
  147. <p>
  148. <label for="<?php echo $this->get_field_id( 'container_id' ); ?>"><code>container_id</code></label>
  149. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'container_id' ); ?>" name="<?php echo $this->get_field_name( 'container_id' ); ?>" value="<?php echo esc_attr( $instance['container_id'] ); ?>" />
  150. </p>
  151. <p>
  152. <label for="<?php echo $this->get_field_id( 'container_class' ); ?>"><code>container_class</code></label>
  153. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'container_class' ); ?>" name="<?php echo $this->get_field_name( 'container_class' ); ?>" value="<?php echo esc_attr( $instance['container_class'] ); ?>" />
  154. </p>
  155. <p>
  156. <label for="<?php echo $this->get_field_id( 'menu_id' ); ?>"><code>menu_id</code></label>
  157. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'menu_id' ); ?>" name="<?php echo $this->get_field_name( 'menu_id' ); ?>" value="<?php echo esc_attr( $instance['menu_id'] ); ?>" />
  158. </p>
  159. <p>
  160. <label for="<?php echo $this->get_field_id( 'menu_class' ); ?>"><code>menu_class</code></label>
  161. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'menu_class' ); ?>" name="<?php echo $this->get_field_name( 'menu_class' ); ?>" value="<?php echo esc_attr( $instance['menu_class'] ); ?>" />
  162. </p>
  163. </div>
  164. <div class="hybrid-widget-controls columns-2 column-last">
  165. <p>
  166. <label for="<?php echo $this->get_field_id( 'depth' ); ?>"><code>depth</code></label>
  167. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'depth' ); ?>" name="<?php echo $this->get_field_name( 'depth' ); ?>" value="<?php echo esc_attr( $instance['depth'] ); ?>" />
  168. </p>
  169. <p>
  170. <label for="<?php echo $this->get_field_id( 'before' ); ?>"><code>before</code></label>
  171. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'before' ); ?>" name="<?php echo $this->get_field_name( 'before' ); ?>" value="<?php echo esc_attr( $instance['before'] ); ?>" />
  172. </p>
  173. <p>
  174. <label for="<?php echo $this->get_field_id( 'after' ); ?>"><code>after</code></label>
  175. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'after' ); ?>" name="<?php echo $this->get_field_name( 'after' ); ?>" value="<?php echo esc_attr( $instance['after'] ); ?>" />
  176. </p>
  177. <p>
  178. <label for="<?php echo $this->get_field_id( 'link_before' ); ?>"><code>link_before</code></label>
  179. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'link_before' ); ?>" name="<?php echo $this->get_field_name( 'link_before' ); ?>" value="<?php echo esc_attr( $instance['link_before'] ); ?>" />
  180. </p>
  181. <p>
  182. <label for="<?php echo $this->get_field_id( 'link_after' ); ?>"><code>link_after</code></label>
  183. <input type="text" class="smallfat code" id="<?php echo $this->get_field_id( 'link_after' ); ?>" name="<?php echo $this->get_field_name( 'link_after' ); ?>" value="<?php echo esc_attr( $instance['link_after'] ); ?>" />
  184. </p>
  185. <p>
  186. <label for="<?php echo $this->get_field_id( 'fallback_cb' ); ?>"><code>fallback_cb</code></label>
  187. <input type="text" class="widefat code" id="<?php echo $this->get_field_id( 'fallback_cb' ); ?>" name="<?php echo $this->get_field_name( 'fallback_cb' ); ?>" value="<?php echo esc_attr( $instance['fallback_cb'] ); ?>" />
  188. </p>
  189. <p>
  190. <label for="<?php echo $this->get_field_id( 'walker' ); ?>"><code>walker</code></label>
  191. <input type="text" class="widefat code" id="<?php echo $this->get_field_id( 'walker' ); ?>" name="<?php echo $this->get_field_name( 'walker' ); ?>" value="<?php echo esc_attr( $instance['walker'] ); ?>" />
  192. </p>
  193. </div>
  194. <div style="clear:both;">&nbsp;</div>
  195. <?php
  196. }
  197. }
  198. ?>