Make WordPress Core


Ignore:
Timestamp:
02/28/2010 08:00:49 PM (17 years ago)
Author:
ryan
Message:

Menu enhancements. Props ptahdunbar. fixes #11817

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/default-widgets.php

    r13473 r13512  
    10451045
    10461046        function WP_Nav_Menu_Widget() {
    1047                 $widget_ops = array('description' => __('Use this widget to add one of your navigation menus as a widget.') );
    1048                 parent::WP_Widget( false, __('Navigation Menu'), $widget_ops );
    1049         }
    1050 
     1047                $widget_ops = array( 'description' => __('Use this widget to add one of your navigation menus as a widget.') );
     1048                parent::WP_Widget( 'nav_menu', __('Navigation Menu'), $widget_ops );
     1049        }
     1050       
    10511051        function widget($args, $instance) {
    1052                 $navmenu = $instance['navmenu'];
    1053                 $navtitle = $instance['navtitle'];
    1054                 $navdeveloper = strtolower($instance['navdeveloper']);
    1055                 $navdiv = strtolower($instance['navdiv']);
    1056                 $navul = strtolower($instance['navul']);
    1057                 $navdivid = $instance['navdivid'];
    1058                 $navdivclass = $instance['navdivclass'];
    1059                 $navulid = $instance['navulid'];
    1060                 $navulclass = $instance['navulclass'];
    1061 
    1062                 // Override for menu descriptions
    1063                 $advanced_option_descriptions = get_option('wp_settings_nav_menu_advanced_options');
    1064                 if ( $advanced_option_descriptions == 'no' ) {
    1065                         $navwidgetdescription = 2;
    1066                 } else {
    1067                         $navwidgetdescription = $instance['navwidgetdescription'];
    1068                 }
    1069 
    10701052                // Get menu
    1071                 if ( $navmenu > 0 ) {
    1072                         $custom_menu = get_term( (int) $nav_menu, 'nav_menu' );
    1073                         $wp_custom_nav_menu_name = $custom_menu->name;
    1074                         $menuexists = true;
    1075                 } else {
    1076                         $menuexists = false;
    1077                 }
    1078 
    1079                 if ( $navdeveloper == 'yes' ) {
    1080                         // DISPLAY Custom DIV
    1081                         if ( $navdiv == 'yes' ) {
    1082                         ?>
    1083                                 <div id="<?php echo $navdivid;  ?>" class="<?php echo $navdivclass; ?>">
    1084                         <?php
    1085                                 }
    1086                         } else {
    1087                                 //DISPLAY default DIV
    1088                                 ?>
    1089                                 <div class="widget">
    1090                                 <?php
     1053                $nav_menu = wp_get_nav_menu_object( $instance['nav_menu'] );
     1054               
     1055                if ( !$nav_menu )
     1056                        return;         
     1057               
     1058                echo $args['before_widget'];
     1059               
     1060                if ( isset($instance['title']) )
     1061                        echo $args['before_title'] . $instance['title'] . $args['after_title'];
     1062               
     1063                wp_nav_menu( array( 'menu' => $nav_menu ) );
     1064               
     1065                echo $args['after_widget'];
     1066        }
     1067
     1068        function update( $new_instance, $old_instance ) {
     1069                $instance['title'] = strip_tags( stripslashes($new_instance['title']) );
     1070                $instance['nav_menu'] = (int) $new_instance['nav_menu'];
     1071                return $instance;
     1072        }
     1073
     1074        function form( $instance ) {
     1075                $title = isset( $instance['title'] ) ? $instance['title'] : '';
     1076                $nav_menu = isset( $instance['nav_menu'] ) ? $instance['nav_menu'] : '';
     1077               
     1078                // Get menus
     1079                $menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
     1080               
     1081                // If no menus exists, direct the user to go and create some.
     1082                if ( !$menus ) {
     1083                        echo '<p>'. sprintf( __('No menus have been created yet. <a href="%s">Creat some</a>.'), admin_url('nav-menus.php') ) .'</p>';
     1084                        return;
     1085                }
     1086                ?>
     1087                <p>
     1088                        <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:') ?></label>
     1089                        <input type="text" class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $title; ?>" />
     1090                </p>
     1091                <p>
     1092                        <label for="<?php echo $this->get_field_id('nav_menu'); ?>"><?php _e('Select Menu:'); ?></label>
     1093                        <select id="<?php echo $this->get_field_id('nav_menu'); ?>" name="<?php echo $this->get_field_name('nav_menu'); ?>">
     1094                <?php
     1095                        foreach ( $menus as $menu ) {
     1096                                $selected = $nav_menu == $menu->term_id ? ' selected="selected"' : '';
     1097                                echo '<option'. $selected .' value="'. $menu->term_id .'">'. $menu->name .'</option>';
    10911098                        }
    10921099                ?>
    1093 
    1094                 <h3><?php echo $navtitle; ?></h3>
    1095                 <?php
    1096                 if ( $menuexists ) {
    1097                         if ( $navdeveloper == 'yes' ) {
    1098                                 //DISPLAY Custom UL
    1099                                 if ( $navul == 'yes' ) {
    1100                                         ?>
    1101                                         <ul id="<?php echo $navulid;  ?>" class="<?php echo $navulclass; ?>">
    1102                                         <?php
    1103                                 }
    1104                         } else {
    1105                                 // DISPLAY default UL
    1106                                 ?>
    1107                                 <ul class="menu">
    1108                                 <?php
    1109                         }
    1110                         wp_nav_menu( array('id' => $navmenu, 'name' => $wp_custom_nav_menu_name, 'desc' => $navwidgetdescription, 'format' => 'widget') );
    1111                         if ( $navdeveloper == 'yes' ) {
    1112                                 // DISPLAY Custom UL
    1113                                 if ( $navul == 'yes' ) {
    1114                                         ?>
    1115                                         </ul>
    1116                                         <?php
    1117                                 }
    1118                         } else {
    1119                                 // DISPLAY default UL
    1120                                 ?>
    1121                                 </ul>
    1122                                 <?php
    1123                         }
    1124                 } else {
    1125                         _e('You have not setup the custom navigation widget correctly, please check your settings in the backend.');
    1126                 }
    1127 
    1128                 //DEVELOPER settings enabled
    1129                 if ($navdeveloper == 'yes') {
    1130                         // DISPLAY Custom DIV
    1131                         if ( $navdiv == 'yes' ) {
    1132                                 ?>
    1133                                 </div>
    1134                                 <?php
    1135                         }
    1136                 } else {
    1137                         // DISPLAY default DIV
    1138                         ?>
    1139                         </div>
    1140                         <?php
    1141                 }
    1142                 ?><!-- /#nav-container -->
    1143                 <?php
    1144         }
    1145 
    1146         function update($new_instance, $old_instance) {
    1147                 return $new_instance;
    1148         }
    1149 
    1150         function form($instance) {
    1151                 $navmenu = esc_attr($instance['navmenu']);
    1152                 $navtitle = esc_attr($instance['navtitle']);
    1153                 $navdeveloper = esc_attr($instance['navdeveloper']);
    1154                 $navdiv = esc_attr($instance['navdiv']);
    1155                 $navul = esc_attr($instance['navul']);
    1156                 $navdivid = esc_attr($instance['navdivid']);
    1157                 $navdivclass = esc_attr($instance['navdivclass']);
    1158                 $navulid = esc_attr($instance['navulid']);
    1159                 $navulclass = esc_attr($instance['navulclass']);
    1160                 $navwidgetdescription = esc_attr($instance['navwidgetdescription']);
    1161 
    1162                 global $wpdb;
    1163 
    1164                 // Get menus
    1165                 $custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) );
    1166 
    1167                 if ( !$custom_menus) {
    1168                 ?>
    1169                         <p>
    1170                         <label><?php printf(__('No menus have been created yet.  <a href="%s">Creat some</a>.'), admin_url('nav-menus.php')); ?></label>
    1171                         </p>
    1172                 <?php
    1173                         return;
    1174                 }
    1175                 ?>
    1176 
    1177                 <p>
    1178                         <label for="<?php echo $this->get_field_id('navmenu'); ?>"><?php _e('Select Menu:'); ?></label>
    1179 
    1180                         <select id="<?php echo $this->get_field_id('navmenu'); ?>" name="<?php echo $this->get_field_name('navmenu'); ?>">
    1181                                 <?php
    1182                                 foreach ( $custom_menus as $menu ) {
    1183                                         if ( $navmenu == $menu->term_id )
    1184                                                 $selected_option = 'selected="selected"';
    1185                                         else
    1186                                                 $selected_option = '';
    1187                                         ?>
    1188                                         <option value="<?php echo $menu->term_id; ?>" <?php echo $selected_option; ?>><?php echo $menu->name; ?></option>
    1189                                         <?php
    1190                                 }
    1191                                 ?>
    11921100                        </select>
    11931101                </p>
    1194 
    1195                 <p>
    1196                         <label for="<?php echo $this->get_field_id('navtitle'); ?>"><?php _e('Title:'); ?></label>
    1197                         <input type="text" name="<?php echo $this->get_field_name('navtitle'); ?>" value="<?php echo $navtitle; ?>" class="widefat" id="<?php echo $this->get_field_id('navtitle'); ?>" />
    1198                 </p>
    1199 
    1200                 <?php $checked = strtolower($navdeveloper); ?>
    1201                 <p>
    1202                         <label for="<?php echo $this->get_field_id('navdeveloper'); ?>"><?php _e('Advanced Options:'); ?></label><br />
    1203                         <span class="checkboxes">
    1204                                 <label>Yes</label><input type="radio" id="<?php echo $this->get_field_name('navdeveloper'); ?>" name="<?php echo $this->get_field_name('navdeveloper'); ?>" value="yes" <?php if ($checked=='yes') { echo 'checked="checked"'; } ?> />
    1205                                 <label>No</label><input type="radio" id="<?php echo $this->get_field_name('navdeveloper'); ?>" name="<?php echo $this->get_field_name('navdeveloper'); ?>" value="no" <?php if ($checked=='yes') { } else { echo 'checked="checked"'; } ?> />
    1206                         </span><!-- /.checkboxes -->
    1207                 </p>
    1208 
    12091102                <?php
    1210                 // Advanced settings
    1211                 if ( $checked == 'yes' ) :
    1212                 ?>
    1213                 <p>
    1214                 <?php $checked = strtolower($navdiv); ?>
    1215                         <label for="<?php echo $this->get_field_id('navdiv'); ?>"><?php _e('Wrap in container DIV:'); ?></label><br />
    1216                         <span class="checkboxes">
    1217                                 <label>Yes</label><input type="radio" id="<?php echo $this->get_field_name('navdiv'); ?>" name="<?php echo $this->get_field_name('navdiv'); ?>" value="yes" <?php if ($checked=='yes') { echo 'checked="checked"'; } ?> />
    1218                                 <label>No</label><input type="radio" id="<?php echo $this->get_field_name('navdiv'); ?>" name="<?php echo $this->get_field_name('navdiv'); ?>" value="no" <?php if ($checked=='yes') { } else { echo 'checked="checked"'; } ?> />
    1219                         </span><!-- /.checkboxes -->
    1220                 </p>
    1221                 <?php
    1222                 if ( $checked == 'yes' ) {
    1223                 ?>
    1224 
    1225                         <p>
    1226                                 <label for="<?php echo $this->get_field_id('navdivid'); ?>"><?php _e('DIV id:'); ?></label>
    1227                                 <input type="text" name="<?php echo $this->get_field_name('navdivid'); ?>" value="<?php echo $navdivid; ?>" class="widefat" id="<?php echo $this->get_field_id('navdivid'); ?>" />
    1228                         </p>
    1229                         <p>
    1230                                 <label for="<?php echo $this->get_field_id('navdivclass'); ?>"><?php _e('DIV class:'); ?></label>
    1231                                 <input type="text" name="<?php echo $this->get_field_name('navdivclass'); ?>" value="<?php echo $navdivclass; ?>" class="widefat" id="<?php echo $this->get_field_id('navdivclass'); ?>" />
    1232                         </p>
    1233                 <?php
    1234                 }
    1235                
    1236                 $checked = strtolower($navul);
    1237                 ?>
    1238 
    1239                 <p>
    1240                         <label for="<?php echo $this->get_field_id('navul'); ?>"><?php _e('Wrap in container UL:'); ?></label><br />
    1241                         <span class="checkboxes">
    1242                                 <label>Yes</label><input type="radio" id="<?php echo $this->get_field_name('navul'); ?>" name="<?php echo $this->get_field_name('navul'); ?>" value="yes" <?php if ($checked=='yes') { echo 'checked="checked"'; } ?> />
    1243                                 <label>No</label><input type="radio" id="<?php echo $this->get_field_name('navul'); ?>" name="<?php echo $this->get_field_name('navul'); ?>" value="no" <?php if ($checked=='yes') { } else { echo 'checked="checked"'; } ?> />
    1244                         </span><!-- /.checkboxes -->
    1245                 </p>
    1246 
    1247                 <?php
    1248                 if ( $checked == 'yes' ) {
    1249                 ?>
    1250                         <p>
    1251                                 <label for="<?php echo $this->get_field_id('navulid'); ?>"><?php _e('UL id:'); ?></label>
    1252                                 <input type="text" name="<?php echo $this->get_field_name('navulid'); ?>" value="<?php echo $navulid; ?>" class="widefat" id="<?php echo $this->get_field_id('navulid'); ?>" />
    1253                         </p>
    1254                         <p>
    1255                                 <label for="<?php echo $this->get_field_id('navulclass'); ?>"><?php _e('UL class:'); ?></label>
    1256                                 <input type="text" name="<?php echo $this->get_field_name('navulclass'); ?>" value="<?php echo $navulclass; ?>" class="widefat" id="<?php echo $this->get_field_id('navulclass'); ?>" />
    1257                         </p>
    1258                 <?php
    1259                 }
    1260                 $advanced_option_descriptions = get_option('wp_settings_nav_menu_advanced_options');
    1261                 ?>
    1262                 <p <?php if ($advanced_option_descriptions == 'no') { ?>style="display:none;"<?php } ?>>
    1263                    <?php $checked = strtolower($navwidgetdescription); ?>
    1264                         <label for="<?php echo $this->get_field_id('navwidgetdescription'); ?>"><?php _e('Show Top Level Descriptions:'); ?></label><br />
    1265                         <span class="checkboxes">
    1266                                 <label>Yes</label><input type="radio" id="<?php echo $this->get_field_name('navwidgetdescription'); ?>" name="<?php echo $this->get_field_name('navwidgetdescription'); ?>" value="1" <?php if ($checked=='1') { echo 'checked="checked"'; } ?> />
    1267                                 <label>No</label><input type="radio" id="<?php echo $this->get_field_name('navwidgetdescription'); ?>" name="<?php echo $this->get_field_name('navwidgetdescription'); ?>" value="2" <?php if ($checked=='1') { } else { echo 'checked="checked"'; } ?> />
    1268                         </span><!-- /.checkboxes -->
    1269                 </p>
    1270                 <?php
    1271                 endif;
    12721103        }
    12731104}
Note: See TracChangeset for help on using the changeset viewer.