PageRenderTime 43ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/themes/news/library/classes/widget-nav-menu.php

https://bitbucket.org/lgorence/quickpress
PHP | 205 lines | 134 code | 23 blank | 48 comment | 1 complexity | bd0d3c98d9b9b9ec81434495cd3bc36f MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, AGPL-1.0
  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. * @author Justin Tadlock <justin@justintadlock.com>
  10. * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
  11. * @link http://themehybrid.com/hybrid-core
  12. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  13. */
  14. /**
  15. * Nav Menu Widget Class
  16. *
  17. * @since 0.8.0
  18. */
  19. class Hybrid_Widget_Nav_Menu extends WP_Widget {
  20. /**
  21. * Set up the widget's unique name, ID, class, description, and other options.
  22. *
  23. * @since 1.2.0
  24. */
  25. function __construct() {
  26. /* Set up the widget options. */
  27. $widget_options = array(
  28. 'classname' => 'nav-menu',
  29. 'description' => esc_html__( 'An advanced widget that gives you total control over the output of your menus.', 'hybrid-core' )
  30. );
  31. /* Set up the widget control options. */
  32. $control_options = array(
  33. 'width' => 525,
  34. 'height' => 350
  35. );
  36. /* Create the widget. */
  37. $this->WP_Widget(
  38. 'hybrid-nav-menu', // $this->id_base
  39. __( 'Navigation Menu', 'hybrid-core' ), // $this->name
  40. $widget_options, // $this->widget_options
  41. $control_options // $this->control_options
  42. );
  43. }
  44. /**
  45. * Outputs the widget based on the arguments input through the widget controls.
  46. *
  47. * @since 0.8.0
  48. */
  49. function widget( $sidebar, $instance ) {
  50. extract( $sidebar );
  51. /* Set the $args for wp_nav_menu() to the $instance array. */
  52. $args = $instance;
  53. /* Overwrite the $echo argument and set it to false. */
  54. $args['echo'] = false;
  55. /* Output the theme's widget wrapper. */
  56. echo $before_widget;
  57. /* If a title was input by the user, display it. */
  58. if ( !empty( $instance['title'] ) )
  59. echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
  60. /* Output the nav menu. */
  61. echo str_replace( array( "\r", "\n", "\t" ), '', wp_nav_menu( $args ) );
  62. /* Close the theme's widget wrapper. */
  63. echo $after_widget;
  64. }
  65. /**
  66. * Updates the widget control options for the particular instance of the widget.
  67. *
  68. * @since 0.8.0
  69. */
  70. function update( $new_instance, $old_instance ) {
  71. $instance = $old_instance;
  72. $instance = $new_instance;
  73. $instance['title'] = strip_tags( $new_instance['title'] );
  74. $instance['depth'] = strip_tags( $new_instance['depth'] );
  75. $instance['container_id'] = strip_tags( $new_instance['container_id'] );
  76. $instance['container_class'] = strip_tags( $new_instance['container_class'] );
  77. $instance['menu_id'] = strip_tags( $new_instance['menu_id'] );
  78. $instance['menu_class'] = strip_tags( $new_instance['menu_class'] );
  79. $instance['fallback_cb'] = strip_tags( $new_instance['fallback_cb'] );
  80. $instance['walker'] = strip_tags( $new_instance['walker'] );
  81. return $instance;
  82. }
  83. /**
  84. * Displays the widget control options in the Widgets admin screen.
  85. *
  86. * @since 0.8.0
  87. */
  88. function form( $instance ) {
  89. /* Set up the default form values. */
  90. $defaults = array(
  91. 'title' => esc_attr__( 'Navigation', 'hybrid-core' ),
  92. 'menu' => '',
  93. 'container' => 'div',
  94. 'container_id' => '',
  95. 'container_class' => '',
  96. 'menu_id' => '',
  97. 'menu_class' => 'nav-menu',
  98. 'depth' => 0,
  99. 'before' => '',
  100. 'after' => '',
  101. 'link_before' => '',
  102. 'link_after' => '',
  103. 'fallback_cb' => 'wp_page_menu',
  104. 'walker' => ''
  105. );
  106. /* Merge the user-selected arguments with the defaults. */
  107. $instance = wp_parse_args( (array) $instance, $defaults );
  108. $container = apply_filters( 'wp_nav_menu_container_allowedtags', array( 'div', 'nav' ) );
  109. ?>
  110. <div class="hybrid-widget-controls columns-2">
  111. <p>
  112. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:', 'hybrid-core' ); ?></label>
  113. <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'] ); ?>" />
  114. </p>
  115. <p>
  116. <label for="<?php echo $this->get_field_id( 'menu' ); ?>"><code>menu</code></label>
  117. <select class="widefat" id="<?php echo $this->get_field_id( 'menu' ); ?>" name="<?php echo $this->get_field_name( 'menu' ); ?>">
  118. <?php foreach ( wp_get_nav_menus() as $menu ) { ?>
  119. <option value="<?php echo esc_attr( $menu->term_id ); ?>" <?php selected( $instance['menu'], $menu->term_id ); ?>><?php echo esc_html( $menu->name ); ?></option>
  120. <?php } ?>
  121. </select>
  122. </p>
  123. <p>
  124. <label for="<?php echo $this->get_field_id( 'container' ); ?>"><code>container</code></label>
  125. <select class="smallfat" id="<?php echo $this->get_field_id( 'container' ); ?>" name="<?php echo $this->get_field_name( 'container' ); ?>">
  126. <?php foreach ( $container as $option ) { ?>
  127. <option value="<?php echo esc_attr( $option ); ?>" <?php selected( $instance['container'], $option ); ?>><?php echo esc_html( $option ); ?></option>
  128. <?php } ?>
  129. </select>
  130. </p>
  131. <p>
  132. <label for="<?php echo $this->get_field_id( 'container_id' ); ?>"><code>container_id</code></label>
  133. <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'] ); ?>" />
  134. </p>
  135. <p>
  136. <label for="<?php echo $this->get_field_id( 'container_class' ); ?>"><code>container_class</code></label>
  137. <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'] ); ?>" />
  138. </p>
  139. <p>
  140. <label for="<?php echo $this->get_field_id( 'menu_id' ); ?>"><code>menu_id</code></label>
  141. <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'] ); ?>" />
  142. </p>
  143. <p>
  144. <label for="<?php echo $this->get_field_id( 'menu_class' ); ?>"><code>menu_class</code></label>
  145. <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'] ); ?>" />
  146. </p>
  147. </div>
  148. <div class="hybrid-widget-controls columns-2 column-last">
  149. <p>
  150. <label for="<?php echo $this->get_field_id( 'depth' ); ?>"><code>depth</code></label>
  151. <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'] ); ?>" />
  152. </p>
  153. <p>
  154. <label for="<?php echo $this->get_field_id( 'before' ); ?>"><code>before</code></label>
  155. <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'] ); ?>" />
  156. </p>
  157. <p>
  158. <label for="<?php echo $this->get_field_id( 'after' ); ?>"><code>after</code></label>
  159. <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'] ); ?>" />
  160. </p>
  161. <p>
  162. <label for="<?php echo $this->get_field_id( 'link_before' ); ?>"><code>link_before</code></label>
  163. <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'] ); ?>" />
  164. </p>
  165. <p>
  166. <label for="<?php echo $this->get_field_id( 'link_after' ); ?>"><code>link_after</code></label>
  167. <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'] ); ?>" />
  168. </p>
  169. <p>
  170. <label for="<?php echo $this->get_field_id( 'fallback_cb' ); ?>"><code>fallback_cb</code></label>
  171. <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'] ); ?>" />
  172. </p>
  173. <p>
  174. <label for="<?php echo $this->get_field_id( 'walker' ); ?>"><code>walker</code></label>
  175. <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'] ); ?>" />
  176. </p>
  177. </div>
  178. <div style="clear:both;">&nbsp;</div>
  179. <?php
  180. }
  181. }
  182. ?>