wp/wp-includes/widgets/class-wp-nav-menu-widget.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
    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 	 *
    57 			echo $args['before_title'] . $title . $args['after_title'];
    57 			echo $args['before_title'] . $title . $args['after_title'];
    58 		}
    58 		}
    59 
    59 
    60 		$nav_menu_args = array(
    60 		$nav_menu_args = array(
    61 			'fallback_cb' => '',
    61 			'fallback_cb' => '',
    62 			'menu'        => $nav_menu
    62 			'menu'        => $nav_menu,
    63 		);
    63 		);
    64 
    64 
    65 		/**
    65 		/**
    66 		 * Filters the arguments for the Navigation Menu widget.
    66 		 * Filters the arguments for the Navigation Menu widget.
    67 		 *
    67 		 *
   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' ); ?>">
   147 						</option>
   159 						</option>
   148 					<?php endforeach; ?>
   160 					<?php endforeach; ?>
   149 				</select>
   161 				</select>
   150 			</p>
   162 			</p>
   151 			<?php if ( $wp_customize instanceof WP_Customize_Manager ) : ?>
   163 			<?php if ( $wp_customize instanceof WP_Customize_Manager ) : ?>
   152 				<p class="edit-selected-nav-menu" style="<?php if ( ! $nav_menu ) { echo 'display: none;'; } ?>">
   164 				<p class="edit-selected-nav-menu" style="<?php echo $nav_menu_style; ?>">
   153 					<button type="button" class="button"><?php _e( 'Edit Menu' ) ?></button>
   165 					<button type="button" class="button"><?php _e( 'Edit Menu' ); ?></button>
   154 				</p>
   166 				</p>
   155 			<?php endif; ?>
   167 			<?php endif; ?>
   156 		</div>
   168 		</div>
   157 		<?php
   169 		<?php
   158 	}
   170 	}