21 * |
21 * |
22 * @since 3.0.0 |
22 * @since 3.0.0 |
23 */ |
23 */ |
24 public function __construct() { |
24 public function __construct() { |
25 $widget_ops = array( |
25 $widget_ops = array( |
26 'description' => __( 'Add a navigation menu to your sidebar.' ), |
26 'description' => __( 'Add a navigation menu to your sidebar.' ), |
27 'customize_selective_refresh' => true, |
27 'customize_selective_refresh' => true, |
28 ); |
28 ); |
29 parent::__construct( 'nav_menu', __('Navigation Menu'), $widget_ops ); |
29 parent::__construct( 'nav_menu', __( 'Navigation Menu' ), $widget_ops ); |
30 } |
30 } |
31 |
31 |
32 /** |
32 /** |
33 * Outputs the content for the current Navigation Menu widget instance. |
33 * Outputs the content for the current Navigation Menu widget instance. |
34 * |
34 * |
112 * @param array $instance Current settings. |
112 * @param array $instance Current settings. |
113 * @global WP_Customize_Manager $wp_customize |
113 * @global WP_Customize_Manager $wp_customize |
114 */ |
114 */ |
115 public function form( $instance ) { |
115 public function form( $instance ) { |
116 global $wp_customize; |
116 global $wp_customize; |
117 $title = isset( $instance['title'] ) ? $instance['title'] : ''; |
117 $title = isset( $instance['title'] ) ? $instance['title'] : ''; |
118 $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : ''; |
118 $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : ''; |
119 |
119 |
120 // Get menus |
120 // Get menus |
121 $menus = wp_get_nav_menus(); |
121 $menus = wp_get_nav_menus(); |
122 |
122 |
|
123 $empty_menus_style = $not_empty_menus_style = ''; |
|
124 if ( empty( $menus ) ) { |
|
125 $empty_menus_style = ' style="display:none" '; |
|
126 } else { |
|
127 $not_empty_menus_style = ' style="display:none" '; |
|
128 } |
|
129 |
|
130 $nav_menu_style = ''; |
|
131 if ( ! $nav_menu ) { |
|
132 $nav_menu_style = 'display: none;'; |
|
133 } |
|
134 |
123 // If no menus exists, direct the user to go and create some. |
135 // If no menus exists, direct the user to go and create some. |
124 ?> |
136 ?> |
125 <p class="nav-menu-widget-no-menus-message" <?php if ( ! empty( $menus ) ) { echo ' style="display:none" '; } ?>> |
137 <p class="nav-menu-widget-no-menus-message" <?php echo $not_empty_menus_style; ?>> |
126 <?php |
138 <?php |
127 if ( $wp_customize instanceof WP_Customize_Manager ) { |
139 if ( $wp_customize instanceof WP_Customize_Manager ) { |
128 $url = 'javascript: wp.customize.panel( "nav_menus" ).focus();'; |
140 $url = 'javascript: wp.customize.panel( "nav_menus" ).focus();'; |
129 } else { |
141 } else { |
130 $url = admin_url( 'nav-menus.php' ); |
142 $url = admin_url( 'nav-menus.php' ); |
131 } |
143 } |
132 ?> |
144 ?> |
133 <?php echo sprintf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) ); ?> |
145 <?php echo sprintf( __( 'No menus have been created yet. <a href="%s">Create some</a>.' ), esc_attr( $url ) ); ?> |
134 </p> |
146 </p> |
135 <div class="nav-menu-widget-form-controls" <?php if ( empty( $menus ) ) { echo ' style="display:none" '; } ?>> |
147 <div class="nav-menu-widget-form-controls" <?php echo $empty_menus_style; ?>> |
136 <p> |
148 <p> |
137 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ) ?></label> |
149 <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> |
138 <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( $title ); ?>"/> |
150 <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( $title ); ?>"/> |
139 </p> |
151 </p> |
140 <p> |
152 <p> |
141 <label for="<?php echo $this->get_field_id( 'nav_menu' ); ?>"><?php _e( 'Select Menu:' ); ?></label> |
153 <label for="<?php echo $this->get_field_id( 'nav_menu' ); ?>"><?php _e( 'Select Menu:' ); ?></label> |
142 <select id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>"> |
154 <select id="<?php echo $this->get_field_id( 'nav_menu' ); ?>" name="<?php echo $this->get_field_name( 'nav_menu' ); ?>"> |