Changeset 23441 for trunk/wp-admin/includes/nav-menu.php
- Timestamp:
- 02/16/2013 04:53:59 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/includes/nav-menu.php
r22396 r23441 82 82 $title = empty( $item->label ) ? $title : $item->label; 83 83 84 $submenu_text = ''; 85 if ( 0 == $depth ) 86 $submenu_text = 'style="display: none;"'; 87 84 88 ?> 85 89 <li id="menu-item-<?php echo $item_id; ?>" class="<?php echo implode(' ', $classes ); ?>"> 86 90 <dl class="menu-item-bar"> 87 91 <dt class="menu-item-handle"> 88 <span class="item-title"><?php echo esc_html( $title ); ?> </span>92 <span class="item-title"><?php echo esc_html( $title ); ?> <span class="is-submenu" <?php echo $submenu_text; ?>><?php _e( 'sub item' ); ?></span></span> 89 93 <span class="item-controls"> 90 94 <span class="item-type"><?php echo esc_html( $item->type_label ); ?></span> … … 183 187 'menu-item' => $item_id, 184 188 ), 185 remove_query_arg($removed_args, admin_url( 'nav-menus.php' ))189 admin_url( 'nav-menus.php' ) 186 190 ), 187 191 'delete-menu_item_' . $item_id 188 ); ?>"><?php _e( 'Remove'); ?></a> <span class="meta-sep"> | </span> <a class="item-cancel submitcancel" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array('edit-menu-item' => $item_id, 'cancel' => time()), remove_query_arg( $removed_args, admin_url( 'nav-menus.php' )) ) );192 ); ?>"><?php _e( 'Remove' ); ?></a> <span class="meta-sep hide-if-no-js"> | </span> <a class="item-cancel submitcancel hide-if-no-js" id="cancel-<?php echo $item_id; ?>" href="<?php echo esc_url( add_query_arg( array( 'edit-menu-item' => $item_id, 'cancel' => time() ), admin_url( 'nav-menus.php' ) ) ); 189 193 ?>#menu-item-settings-<?php echo $item_id; ?>"><?php _e('Cancel'); ?></a> 190 194 </div> … … 383 387 function wp_nav_menu_setup() { 384 388 // Register meta boxes 385 if ( wp_get_nav_menus() )386 add_meta_box( 'nav-menu-theme-locations', __( 'Theme Locations' ), 'wp_nav_menu_locations_meta_box' , 'nav-menus', 'side', 'default' );387 add_meta_box( 'add-custom-links', __('Custom Links'), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' );388 389 wp_nav_menu_post_type_meta_boxes(); 390 add_meta_box( 'add-custom-links', __( 'Add Links' ), 'wp_nav_menu_item_link_meta_box', 'nav-menus', 'side', 'default' ); 389 391 wp_nav_menu_taxonomy_meta_boxes(); 390 392 … … 412 414 return; 413 415 414 $initial_meta_boxes = array( 'nav-menu-theme-locations', 'add- custom-links', 'add-page', 'add-category' );416 $initial_meta_boxes = array( 'nav-menu-theme-locations', 'add-page', 'add-custom-links', 'add-category' ); 415 417 $hidden_meta_boxes = array(); 416 418 … … 490 492 $num_locations = count( array_keys($locations) ); 491 493 492 echo '<p class="howto">' . sprintf( _n('Your theme supports %s menu. Select which menu you would like to use.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n($num_locations)) . '</p>';494 echo '<p class="howto">' . _n( 'Select a menu to use within your theme.', 'Select the menus you will use in your theme.', $num_locations ) . '</p>'; 493 495 494 496 foreach ( $locations as $location => $description ) { … … 513 515 ?> 514 516 <p class="button-controls"> 515 <?php submit_button( __( 'Save' ), 'primary right', 'nav-menu-locations', false, disabled( $nav_menu_selected_id, 0, false) ); ?>517 <?php submit_button( __( 'Save' ), 'primary right', 'nav-menu-locations', false, wp_nav_menu_disabled_check( $nav_menu_selected_id ) ); ?> 516 518 <span class="spinner"></span> 517 519 </p> 518 520 <?php 521 } 522 523 /** 524 * Check whether to disable the Menu Locations meta box submit button 525 * 526 * @since 3.6.0 527 * 528 * @uses global $one_theme_location_no_menus to determine if no menus exist 529 * @uses disabled() to output the disabled attribute in $other_attributes param in submit_button() 530 * 531 * @param int|string $nav_menu_selected_id (id, name or slug) of the currently-selected menu 532 * @return string Disabled attribute if at least one menu exists, false if not 533 */ 534 function wp_nav_menu_disabled_check( $nav_menu_selected_id ) { 535 global $one_theme_location_no_menus; 536 537 if ( $one_theme_location_no_menus ) 538 return false; 539 540 return disabled( $nav_menu_selected_id, 0 ); 519 541 } 520 542 … … 555 577 <p id="menu-item-name-wrap"> 556 578 <label class="howto" for="custom-menu-item-name"> 557 <span><?php _e( 'Label'); ?></span>579 <span><?php _e( 'Link Text' ); ?></span> 558 580 <input id="custom-menu-item-name" name="menu-item[<?php echo $_nav_menu_placeholder; ?>][menu-item-title]" type="text" class="regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e('Menu Item'); ?>" /> 559 581 </label> … … 562 584 <p class="button-controls"> 563 585 <span class="add-to-menu"> 564 <input type="submit"<?php disabled( $nav_menu_selected_id, 0); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" />586 <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-custom-menu-item" id="submit-customlinkdiv" /> 565 587 <span class="spinner"></span> 566 588 </span> … … 769 791 <span class="list-controls"> 770 792 <a href="<?php 771 echo esc_url( add_query_arg(793 echo esc_url( add_query_arg( 772 794 array( 773 795 $post_type_name . '-tab' => 'all', 774 796 'selectall' => 1, 775 797 ), 776 remove_query_arg( $removed_args)798 remove_query_arg( $removed_args ) 777 799 )); 778 800 ?>#posttype-<?php echo $post_type_name; ?>" class="select-all"><?php _e('Select All'); ?></a> … … 780 802 781 803 <span class="add-to-menu"> 782 <input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-post-type-menu-item" id="submit-posttype-<?php echo $post_type_name; ?>" />804 <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-post-type-menu-item" id="<?php esc_attr_e( 'submit-posttype-' . $post_type_name ); ?>" /> 783 805 <span class="spinner"></span> 784 806 </span> … … 956 978 957 979 <span class="add-to-menu"> 958 <input type="submit"<?php disabled( $nav_menu_selected_id, 0 ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e('Add to Menu'); ?>" name="add-taxonomy-menu-item" id="submit-taxonomy-<?php echo $taxonomy_name; ?>" />980 <input type="submit"<?php wp_nav_menu_disabled_check( $nav_menu_selected_id ); ?> class="button-secondary submit-add-to-menu right" value="<?php esc_attr_e( __( 'Add to Menu' ) ); ?>" name="add-taxonomy-menu-item" id="<?php esc_attr_e( 'submit-taxonomy-' . $taxonomy_name ); ?>" /> 959 981 <span class="spinner"></span> 960 982 </span> … … 1087 1109 $result = '<div id="menu-instructions" class="post-body-plain'; 1088 1110 $result .= ( ! empty($menu_items) ) ? ' menu-instructions-inactive">' : '">'; 1089 $result .= '<p>' . __( 'Select menu items (pages, categories, links) from the boxes at left to begin building your custom menu.') . '</p>';1111 $result .= '<p>' . __( 'Next, add menu items (i.e. pages, links, categories) from the column on the left.' ) . '</p>'; 1090 1112 $result .= '</div>'; 1091 1113 … … 1159 1181 wp_delete_post( $menu_item_id, true ); 1160 1182 } 1161 1162 1183 add_action('admin_head-nav-menus.php', '_wp_delete_orphaned_draft_menu_items'); 1184 1185 /** 1186 * Delete nav menus from the nav menu management screen 1187 * 1188 * @since 3.6.0 1189 * @access private 1190 * 1191 * @param int|string $nav_menu_id The menu to delete (id, slug, or name) 1192 * @return false if Error, otherwise true 1193 */ 1194 function _wp_delete_nav_menu( $nav_menu_id ) { 1195 1196 if ( ! is_nav_menu( $nav_menu_id ) ) 1197 return; 1198 1199 $deleted_nav_menu = wp_get_nav_menu_object( $nav_menu_id ); 1200 $delete_nav_menu = wp_delete_nav_menu( $nav_menu_id ); 1201 1202 if ( is_wp_error( $delete_nav_menu ) ) 1203 return $delete_nav_menu; 1204 1205 // Remove this menu from any locations. 1206 $locations = get_theme_mod( 'nav_menu_locations' ); 1207 foreach ( (array) $locations as $location => $menu_id ) { 1208 if ( $menu_id == $nav_menu_id ) 1209 $locations[ $location ] = 0; 1210 } 1211 set_theme_mod( 'nav_menu_locations', $locations ); 1212 return true; 1213 } 1214 1215 /** 1216 * Saves nav menu items 1217 * 1218 * @since 3.6.0 1219 * 1220 * @uses wp_get_nav_menu_items() to retrieve the nav menu's menu items 1221 * @uses wp_defer_term_counter() to enable then disable term counting 1222 * 1223 * @param int|string $nav_menu_selected_id (id, slug, or name ) of the currently-selected menu 1224 * @param string $nav_menu_selected_title Title of the currently-selected menu 1225 * @return array $messages The menu updated message 1226 */ 1227 function wp_nav_menu_update_menu_items ( $nav_menu_selected_id, $nav_menu_selected_title ) { 1228 $unsorted_menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID', 'post_status' => 'draft,publish' ) ); 1229 1230 $menu_items = array(); 1231 // Index menu items by db ID 1232 foreach ( $unsorted_menu_items as $_item ) 1233 $menu_items[$_item->db_id] = $_item; 1234 1235 $post_fields = array( 1236 'menu-item-db-id', 'menu-item-object-id', 'menu-item-object', 1237 'menu-item-parent-id', 'menu-item-position', 'menu-item-type', 1238 'menu-item-title', 'menu-item-url', 'menu-item-description', 1239 'menu-item-attr-title', 'menu-item-target', 'menu-item-classes', 'menu-item-xfn' 1240 ); 1241 1242 wp_defer_term_counting( true ); 1243 // Loop through all the menu items' POST variables 1244 if ( ! empty( $_POST['menu-item-db-id'] ) ) { 1245 foreach( (array) $_POST['menu-item-db-id'] as $_key => $k ) { 1246 1247 // Menu item title can't be blank 1248 if ( empty( $_POST['menu-item-title'][$_key] ) ) 1249 continue; 1250 1251 $args = array(); 1252 foreach ( $post_fields as $field ) 1253 $args[$field] = isset( $_POST[$field][$_key] ) ? $_POST[$field][$_key] : ''; 1254 1255 $menu_item_db_id = wp_update_nav_menu_item( $nav_menu_selected_id, ( $_POST['menu-item-db-id'][$_key] != $_key ? 0 : $_key ), $args ); 1256 1257 if ( is_wp_error( $menu_item_db_id ) ) 1258 $messages[] = '<div id="message" class="error"><p>' . $menu_item_db_id->get_error_message() . '</p></div>'; 1259 elseif ( isset( $menu_items[$menu_item_db_id] ) ) 1260 unset( $menu_items[$menu_item_db_id] ); 1261 } 1262 } 1263 1264 // Remove menu items from the menu that weren't in $_POST 1265 if ( ! empty( $menu_items ) ) { 1266 foreach ( array_keys( $menu_items ) as $menu_item_id ) { 1267 if ( is_nav_menu_item( $menu_item_id ) ) { 1268 wp_delete_post( $menu_item_id ); 1269 } 1270 } 1271 } 1272 1273 // Store 'auto-add' pages. 1274 $auto_add = ! empty( $_POST['auto-add-pages'] ); 1275 $nav_menu_option = (array) get_option( 'nav_menu_options' ); 1276 if ( ! isset( $nav_menu_option['auto_add'] ) ) 1277 $nav_menu_option['auto_add'] = array(); 1278 if ( $auto_add ) { 1279 if ( ! in_array( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) 1280 $nav_menu_option['auto_add'][] = $nav_menu_selected_id; 1281 } else { 1282 if ( false !== ( $key = array_search( $nav_menu_selected_id, $nav_menu_option['auto_add'] ) ) ) 1283 unset( $nav_menu_option['auto_add'][$key] ); 1284 } 1285 // Remove nonexistent/deleted menus 1286 $nav_menu_option['auto_add'] = array_intersect( $nav_menu_option['auto_add'], wp_get_nav_menus( array( 'fields' => 'ids' ) ) ); 1287 update_option( 'nav_menu_options', $nav_menu_option ); 1288 1289 wp_defer_term_counting( false ); 1290 1291 do_action( 'wp_update_nav_menu', $nav_menu_selected_id ); 1292 1293 $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%1$s</strong> has been updated.' ), $nav_menu_selected_title ) . '</p></div>'; 1294 unset( $menu_items, $unsorted_menu_items ); 1295 1296 return $messages; 1297 }
Note: See TracChangeset
for help on using the changeset viewer.