Changeset 13271
- Timestamp:
- 02/21/2010 12:34:44 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/custom-navigation.php
r13269 r13271 24 24 wp_enqueue_script( 'custom-navigation-php-functions' ); 25 25 26 27 26 require_once('admin-header.php'); 28 27 require_once (ABSPATH . WPINC . '/custom-navigation.php'); … … 36 35 37 36 } 38 39 37 40 38 /*-----------------------------------------------------------------------------------*/ … … 56 54 57 55 // Get the theme name 58 $themename = 56 $themename = get_current_theme(); 59 57 60 58 // Check which menu is selected and if menu is in edit already 61 59 if ( isset( $_POST['switch_menu'] ) ) 62 $menu_selected_id = $_POST['menu_select'];60 $menu_selected_id = (int) $_POST['menu_select']; 63 61 elseif ( isset( $_POST['menu_id_in_edit'] ) ) 64 $menu_selected_id = $_POST['menu_id_in_edit']; 62 $menu_selected_id = (int) $_POST['menu_id_in_edit']; 63 else 64 $menu_selected_id = 0; 65 65 66 66 // Default Menu to show … … 71 71 $menu_title = ''; 72 72 if ( $menu_selected_id > 0 ) { 73 foreach ( $custom_menus as $menu ) {73 foreach ( $custom_menus as $menu ) { 74 74 if ( $menu->term_id == $menu_selected_id ) { 75 75 $menu_title = $menu->name; … … 80 80 81 81 if ( isset( $_POST['set_wp_menu'] ) ) { 82 update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] ); 82 // @todo validate set_wp_menu 83 update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] ); 83 84 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>'.$themename.'s Custom Menu has been updated!</p></div>'; 84 85 } … … 87 88 $postCounter = $_POST['licount']; 88 89 else 89 90 $postCounter = 0; 90 91 91 92 // Create a new menu. Menus are stored as terms in the 'menu' taxonomy. … … 103 104 $menu_selected_id = $term['term_id']; 104 105 $menu_id_in_edit = $menu_selected_id; 105 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>'.$ insert_menu_name.' Menu has been created!</p></div>';106 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>'.$term['name'].' Menu has been created!</p></div>'; 106 107 107 108 $postCounter = 0; … … 114 115 115 116 if ( isset($_POST['reset_wp_menu']) ) { 116 117 if ($success) {118 119 120 121 122 123 124 125 126 117 $success = wp_custom_nav_reset(); 118 if ( $success ) { 119 // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly 120 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>'.$themename.'s Custom Menu has been RESET!</p></div>'; 121 // GET reset menu id 122 $custom_menus = array(); 123 $menu_selected_id = 0; 124 } else { 125 // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly 126 $messagesdiv = '<div id="message" class="error fade below-h2"><p>'.$themename.'s Custom Menu could not be RESET. Please try again.</p></div>'; 127 } 127 128 } elseif ( $postCounter > 0 && $menu_selected_id > 0 ) { 128 129 $menu_objects = get_objects_in_term( $menu_selected_id, 'menu' ); 129 130 $menu_items = wp_custom_navigation_get_menu_items( $menu_objects ); 130 131 131 $update_fields = array( 'menu_order', 'guid', 'post_content', 'post_title', 'post_excerpt', 'post_content_filtered' ); 132 //Loop through all POST variables 133 for ($k = 1;$k<= $postCounter; $k++) { 134 132 // Loop through all POST variables 133 for ( $k = 1; $k <= $postCounter; $k++ ) { 135 134 if (isset($_POST['dbid'.$k])) { $db_id = $_POST['dbid'.$k]; } else { $db_id = 0; } 136 135 if (isset($_POST['postmenu'.$k])) { $post_id = $_POST['postmenu'.$k]; } else { $post_id = 0; } 137 //@todo implement heirarchy136 //@todo implement heirarchy 138 137 if (isset($_POST['parent'.$k])) { $parent_id = $_POST['parent'.$k]; } else { $parent_id = 0; } 139 if (isset($_POST['title'.$k])) { $custom_title = stripslashes($_POST['title'.$k]); } else { $custom_title = ''; }138 if (isset($_POST['title'.$k])) { $custom_title = $_POST['title'.$k]; } else { $custom_title = ''; } 140 139 if (isset($_POST['linkurl'.$k])) { $custom_linkurl = $_POST['linkurl'.$k]; } else { $custom_linkurl = ''; } 141 if (isset($_POST['description'.$k])) { $custom_description = stripslashes($_POST['description'.$k]); } else { $custom_description = ''; }142 // doesn't seem to be used by UI140 if (isset($_POST['description'.$k])) { $custom_description = $_POST['description'.$k]; } else { $custom_description = ''; } 141 // doesn't seem to be used by UI 143 142 if (isset($_POST['icon'.$k])) { $icon = $_POST['icon'.$k]; } else { $icon = 0; } 144 143 if (isset($_POST['position'.$k])) { $position = $_POST['position'.$k]; } else { $position = 0; } 145 144 if (isset($_POST['linktype'.$k])) { $linktype = $_POST['linktype'.$k]; } else { $linktype = 'custom'; } 146 if (isset($_POST['anchortitle'.$k])) { $custom_anchor_title = stripslashes($_POST['anchortitle'.$k]); } else { $custom_anchor_title = $custom_title; }145 if (isset($_POST['anchortitle'.$k])) { $custom_anchor_title = $_POST['anchortitle'.$k]; } else { $custom_anchor_title = $custom_title; } 147 146 if (isset($_POST['newwindow'.$k])) { $new_window = $_POST['newwindow'.$k]; } else { $new_window = 0; } 148 147 … … 156 155 $post['post_content_filtered'] = ''; 157 156 158 // New menu item159 if ( $db_id == 0) {157 // New menu item 158 if ( $db_id == 0 ) { 160 159 $db_id = $post_id = wp_insert_post( $post ); 161 160 } elseif ( isset( $menu_items[$db_id] ) ) { 162 foreach( $update_fields as $field ) { 163 if ( $post[$field] != $menu_items[$db_id]->$field ) { 164 $post['ID'] = $db_id; 165 wp_update_post( $post ); 166 break; 167 } 168 } 161 $post['ID'] = $db_id; 162 wp_update_post( $post ); 169 163 unset( $menu_items[$db_id] ); 170 164 } … … 172 166 } 173 167 if ( !empty( $menu_items ) ) { 174 foreach ( array_keys( $menu_items ) as $menu_id ) {168 foreach ( array_keys( $menu_items ) as $menu_id ) { 175 169 wp_delete_post( $menu_id ); 176 170 } 177 171 } 178 // DISPLAY SUCCESS MESSAGE IF POST CORRECT172 // DISPLAY SUCCESS MESSAGE IF POST CORRECT 179 173 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>'.$themename.'s Custom Menu has been updated!</p></div>'; 180 174 }
Note: See TracChangeset
for help on using the changeset viewer.