Changeset 13342
- Timestamp:
- 02/23/2010 08:48:50 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-admin/custom-navigation.php
r13340 r13342 13 13 require_once('admin.php'); 14 14 15 if ( ! current_user_can('switch_themes') ) 16 wp_die( __( 'Cheatin’ uh?' )); 17 15 18 wp_admin_css( 'custom-navigation' ); 16 19 wp_enqueue_script( 'jquery' ); … … 27 30 require_once (ABSPATH . WPINC . '/custom-navigation.php'); 28 31 29 wp_custom_navigation();30 31 32 function wp_custom_nav_reset() { 32 33 wp_custom_navigation_setup(true); 33 34 34 35 return true; 35 36 36 } 37 37 38 /*-----------------------------------------------------------------------------------*/ 39 /* Custom Navigation Admin Interface 40 /* wp_custom_navigation() is the main function for the Custom Navigation 41 /* See functions in admin-functions.php 42 /*-----------------------------------------------------------------------------------*/ 43 44 function wp_custom_navigation() { 45 global $wpdb, $user_ID; 46 ?> 47 48 <div class="wrap"> 49 <div id="no-js"><h3><?php _e('You do not have JavaScript enabled in your browser. Please enable it to access the Menus functionality.'); ?></h3></div> 50 51 <?php 52 $messagesdiv = ''; 53 $menu_id_in_edit = 0; 54 55 // Get the theme name 56 $themename = get_current_theme(); 57 58 // Check which menu is selected and if menu is in edit already 59 if ( isset( $_POST['switch_menu'] ) ) 60 $menu_selected_id = (int) $_POST['menu_select']; 61 elseif ( isset( $_POST['menu_id_in_edit'] ) ) 62 $menu_selected_id = (int) $_POST['menu_id_in_edit']; 63 else 64 $menu_selected_id = 0; 65 66 // Default Menu to show 67 $custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) ); 68 if ( !empty( $custom_menus ) ) 69 $menu_selected_id = $custom_menus[0]->term_id; 70 71 $menu_title = ''; 72 if ( $menu_selected_id > 0 ) { 73 foreach ( $custom_menus as $menu ) { 74 if ( $menu->term_id == $menu_selected_id ) { 75 $menu_title = $menu->name; 76 break; 38 $messagesdiv = ''; 39 $menu_id_in_edit = 0; 40 41 // Check which menu is selected and if menu is in edit already 42 if ( isset( $_POST['switch_menu'] ) ) 43 $menu_selected_id = (int) $_POST['menu_select']; 44 elseif ( isset( $_POST['menu_id_in_edit'] ) ) 45 $menu_selected_id = (int) $_POST['menu_id_in_edit']; 46 else 47 $menu_selected_id = 0; 48 49 // Default Menu to show 50 $custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) ); 51 if ( !empty( $custom_menus ) ) 52 $menu_selected_id = $custom_menus[0]->term_id; 53 54 $menu_title = ''; 55 if ( $menu_selected_id > 0 ) { 56 foreach ( $custom_menus as $menu ) { 57 if ( $menu->term_id == $menu_selected_id ) { 58 $menu_title = $menu->name; 59 break; 60 } 61 } 62 } 63 64 if ( isset( $_POST['set_wp_menu'] ) ) { 65 // @todo validate set_wp_menu 66 update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] ); 67 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __('Menu has been updated!') . '</p></div>'; 68 } 69 70 if ( isset( $_POST['licount'] ) ) 71 $postCounter = $_POST['licount']; 72 else 73 $postCounter = 0; 74 75 // Create a new menu. Menus are stored as terms in the 'menu' taxonomy. 76 if ( isset( $_POST['add_menu'] ) ) { 77 $insert_menu_name = $_POST['add_menu_name']; 78 79 if ( $insert_menu_name != '' ) { 80 $existing_term = get_term_by( 'name', $insert_menu_name, 'nav_menu' ); 81 if ( $existing_term ) { 82 $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . esc_html( sprintf( e__('A menu named "%s" already exists; please try another name.'), $existing_term->name ) ) . '</p></div>'; 83 } else { 84 $term = wp_insert_term( $insert_menu_name, 'nav_menu' ); 85 if ( !is_wp_error($term) ) { 86 $term = get_term($term['term_id'], 'nav_menu'); 87 $custom_menus[$term->term_id] = $term; 88 $menu_selected_id = $term->term_id; 89 $menu_id_in_edit = $menu_selected_id; 90 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . esc_html( sprintf( __('"%s" menu has been created!'), $term->name ) ) . '</p></div>'; 91 92 $postCounter = 0; 77 93 } 78 94 } 95 } else { 96 $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . __('Please enter a valid menu name.') . '</p></div>'; 79 97 } 80 81 if ( isset( $_POST['set_wp_menu'] ) ) { 82 // @todo validate set_wp_menu 83 update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] ); 84 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __('Menu has been updated!') . '</p></div>'; 98 } 99 100 if ( isset($_POST['reset_wp_menu']) ) { 101 $success = wp_custom_nav_reset(); 102 if ( $success ) { 103 // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly 104 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been reset.') . '</p></div>'; 105 // GET reset menu id 106 $custom_menus = array(); 107 $menu_selected_id = 0; 108 } else { 109 // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly 110 $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . __('The menu could not be reset. Please try again.') . '</p></div>'; 85 111 } 86 87 if ( isset( $_POST['licount'] ) ) 88 $postCounter = $_POST['licount']; 89 else 90 $postCounter = 0; 91 92 // Create a new menu. Menus are stored as terms in the 'menu' taxonomy. 93 if ( isset( $_POST['add_menu'] ) ) { 94 $insert_menu_name = $_POST['add_menu_name']; 95 96 if ( $insert_menu_name != '' ) { 97 $existing_term = get_term_by( 'name', $insert_menu_name, 'nav_menu' ); 98 if ( $existing_term ) { 99 $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . esc_html( sprintf( e__('A menu named "%s" already exists; please try another name.'), $existing_term->name ) ) . '</p></div>'; 100 } else { 101 $term = wp_insert_term( $insert_menu_name, 'nav_menu' ); 102 if ( !is_wp_error($term) ) { 103 $term = get_term($term['term_id'], 'nav_menu'); 104 $custom_menus[$term->term_id] = $term; 105 $menu_selected_id = $term->term_id; 106 $menu_id_in_edit = $menu_selected_id; 107 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . esc_html( sprintf( __('"%s" menu has been created!'), $term->name ) ) . '</p></div>'; 108 109 $postCounter = 0; 110 } 111 } 112 } else { 113 $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . __('Please enter a valid menu name.') . '</p></div>'; 114 } 112 } elseif ( $postCounter > 0 && $menu_selected_id > 0 ) { 113 $menu_objects = get_objects_in_term( $menu_selected_id, 'nav_menu' ); 114 $menu_items = wp_custom_navigation_get_menu_items( $menu_objects ); 115 116 // Loop through all POST variables 117 for ( $k = 1; $k <= $postCounter; $k++ ) { 118 if (isset($_POST['dbid'.$k])) { $db_id = $_POST['dbid'.$k]; } else { $db_id = 0; } 119 if (isset($_POST['postmenu'.$k])) { $object_id = $_POST['postmenu'.$k]; } else { $object_id = 0; } 120 if (isset($_POST['parent'.$k])) { $parent_id = $_POST['parent'.$k]; } else { $parent_id = 0; } 121 if (isset($_POST['title'.$k])) { $custom_title = $_POST['title'.$k]; } else { $custom_title = ''; } 122 if (isset($_POST['linkurl'.$k])) { $custom_linkurl = $_POST['linkurl'.$k]; } else { $custom_linkurl = ''; } 123 if (isset($_POST['description'.$k])) { $custom_description = $_POST['description'.$k]; } else { $custom_description = ''; } 124 // doesn't seem to be used by UI 125 if (isset($_POST['icon'.$k])) { $icon = $_POST['icon'.$k]; } else { $icon = 0; } 126 if (isset($_POST['position'.$k])) { $position = $_POST['position'.$k]; } else { $position = 0; } 127 if (isset($_POST['linktype'.$k])) { $linktype = $_POST['linktype'.$k]; } else { $linktype = 'custom'; } 128 if (isset($_POST['anchortitle'.$k])) { $custom_anchor_title = $_POST['anchortitle'.$k]; } else { $custom_anchor_title = $custom_title; } 129 if (isset($_POST['newwindow'.$k])) { $new_window = $_POST['newwindow'.$k]; } else { $new_window = 0; } 130 131 $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID, 132 'ping_status' => 0, 'post_parent' => 0, 'menu_order' => $position, 133 'guid' => $custom_linkurl, 'post_excerpt' => $custom_anchor_title, 'tax_input' => array( 'nav_menu' => $menu_title ), 134 'post_content' => $custom_description, 'post_title' => $custom_title ); 135 if ( $new_window ) 136 $post['post_content_filtered'] = '_blank'; 137 else 138 $post['post_content_filtered'] = ''; 139 if ( $parent_id > 0 && isset( $_POST[ 'dbid' . $parent_id ] ) ) 140 $post[ 'post_parent' ] = (int) $_POST[ 'dbid' . $parent_id ]; 141 142 // New menu item 143 if ( $db_id == 0 ) { 144 $db_id = wp_insert_post( $post ); 145 } elseif ( isset( $menu_items[$db_id] ) ) { 146 $post['ID'] = $db_id; 147 wp_update_post( $post ); 148 unset( $menu_items[$db_id] ); 149 } 150 update_post_meta($db_id, 'menu_type', $linktype); 151 update_post_meta($db_id, 'object_id', $object_id); 115 152 } 116 117 if ( isset($_POST['reset_wp_menu']) ) { 118 $success = wp_custom_nav_reset(); 119 if ( $success ) { 120 // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly 121 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been reset.') . '</p></div>'; 122 // GET reset menu id 123 $custom_menus = array(); 124 $menu_selected_id = 0; 125 } else { 126 // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly 127 $messagesdiv = '<div id="message" class="error fade below-h2"><p>' . __('The menu could not be reset. Please try again.') . '</p></div>'; 128 } 129 } elseif ( $postCounter > 0 && $menu_selected_id > 0 ) { 130 $menu_objects = get_objects_in_term( $menu_selected_id, 'nav_menu' ); 131 $menu_items = wp_custom_navigation_get_menu_items( $menu_objects ); 132 133 // Loop through all POST variables 134 for ( $k = 1; $k <= $postCounter; $k++ ) { 135 if (isset($_POST['dbid'.$k])) { $db_id = $_POST['dbid'.$k]; } else { $db_id = 0; } 136 if (isset($_POST['postmenu'.$k])) { $object_id = $_POST['postmenu'.$k]; } else { $object_id = 0; } 137 if (isset($_POST['parent'.$k])) { $parent_id = $_POST['parent'.$k]; } else { $parent_id = 0; } 138 if (isset($_POST['title'.$k])) { $custom_title = $_POST['title'.$k]; } else { $custom_title = ''; } 139 if (isset($_POST['linkurl'.$k])) { $custom_linkurl = $_POST['linkurl'.$k]; } else { $custom_linkurl = ''; } 140 if (isset($_POST['description'.$k])) { $custom_description = $_POST['description'.$k]; } else { $custom_description = ''; } 141 // doesn't seem to be used by UI 142 if (isset($_POST['icon'.$k])) { $icon = $_POST['icon'.$k]; } else { $icon = 0; } 143 if (isset($_POST['position'.$k])) { $position = $_POST['position'.$k]; } else { $position = 0; } 144 if (isset($_POST['linktype'.$k])) { $linktype = $_POST['linktype'.$k]; } else { $linktype = 'custom'; } 145 if (isset($_POST['anchortitle'.$k])) { $custom_anchor_title = $_POST['anchortitle'.$k]; } else { $custom_anchor_title = $custom_title; } 146 if (isset($_POST['newwindow'.$k])) { $new_window = $_POST['newwindow'.$k]; } else { $new_window = 0; } 147 148 $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID, 149 'ping_status' => 0, 'post_parent' => 0, 'menu_order' => $position, 150 'guid' => $custom_linkurl, 'post_excerpt' => $custom_anchor_title, 'tax_input' => array( 'nav_menu' => $menu_title ), 151 'post_content' => $custom_description, 'post_title' => $custom_title ); 152 if ( $new_window ) 153 $post['post_content_filtered'] = '_blank'; 154 else 155 $post['post_content_filtered'] = ''; 156 if ( $parent_id > 0 && isset( $_POST[ 'dbid' . $parent_id ] ) ) 157 $post[ 'post_parent' ] = (int) $_POST[ 'dbid' . $parent_id ]; 158 159 // New menu item 160 if ( $db_id == 0 ) { 161 $db_id = wp_insert_post( $post ); 162 } elseif ( isset( $menu_items[$db_id] ) ) { 163 $post['ID'] = $db_id; 164 wp_update_post( $post ); 165 unset( $menu_items[$db_id] ); 166 } 167 update_post_meta($db_id, 'menu_type', $linktype); 168 update_post_meta($db_id, 'object_id', $object_id); 153 if ( !empty( $menu_items ) ) { 154 foreach ( array_keys( $menu_items ) as $menu_id ) { 155 wp_delete_post( $menu_id ); 169 156 } 170 if ( !empty( $menu_items ) ) { 171 foreach ( array_keys( $menu_items ) as $menu_id ) { 172 wp_delete_post( $menu_id ); 173 } 157 } 158 // DISPLAY SUCCESS MESSAGE IF POST CORRECT 159 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been updated.') . '</p></div>'; 160 } 161 162 ?> 163 <div class="wrap"> 164 <?php screen_icon(); ?> 165 <h2 class="maintitle"><?php esc_html_e('Menus') ?></h2> 166 167 <div id="no-js"><h3><?php _e('You do not have JavaScript enabled in your browser. Please enable it to access the Menus functionality.'); ?></h3></div> 168 <div id="pages-left"> 169 <div class="inside"> 170 <?php 171 // CHECK if custom menu has been enabled 172 $enabled_menu = get_option('wp_custom_nav_menu'); 173 $checked = strtolower($enabled_menu); 174 175 if ( $checked != 'true' ) 176 echo '<div id="message-enabled" class="error fade below-h2"><p><strong>' . __('Menu editing has not been Enabled yet. Please enable it in order to use it -------->') . '</strong></p></div>'; 177 ?> 178 <?php echo $messagesdiv; ?> 179 <form onsubmit="updatepostdata()" action="custom-navigation.php" method="post" enctype="multipart/form-data"> 180 181 <input type="hidden" name="licount" id="licount" value="0" /> 182 <input type="hidden" name="menu_id_in_edit" id="menu_id_in_edit" value="<?php echo esc_attr($menu_selected_id); ?>" /> 183 184 <div class="sidebar-name"> 185 186 <div class="sidebar-name-arrow"> 187 <br/> 188 </div> 189 <h3><?php echo esc_html($menu_title); ?></h3> 190 191 </div> 192 193 <div id="nav-container"> 194 <ul id="custom-nav"> 195 196 <?php 197 //DISPLAY existing menu 198 if ( $menu_selected_id > 0 ) { 199 // SET output type 200 $output_type = "backend"; 201 // MAIN OUTPUT FUNCTION 202 wp_custom_navigation_output( 'type='.$output_type.'&name='.$menu_title.'&id='.$menu_selected_id ); 174 203 } 175 // DISPLAY SUCCESS MESSAGE IF POST CORRECT 176 $messagesdiv = '<div id="message" class="updated fade below-h2"><p>' . __('The menu has been updated.') . '</p></div>'; 177 } 178 179 // DISPLAY Custom Navigation 180 ?> 181 <?php screen_icon(); ?> 182 <h2 class="maintitle"><?php esc_html_e('Menus') ?></h2> 183 <div id="pages-left"> 184 <div class="inside"> 185 <?php 186 187 // CHECK if custom menu has been enabled 204 ?> 205 206 </ul> 207 </div><!-- /#nav-container --> 208 209 <p class="submit"> 210 211 <script type="text/javascript"> 212 updatepostdata(); 213 </script> 214 215 <input id="save_bottom" name="save_bottom" type="submit" value="<?php esc_attr_e('Save All Changes'); ?>" /></p> 216 </div><!-- /.inside --> 217 </div> 218 219 <div id="menu-right"> 220 <div class="widgets-holder-wrap"> 221 <div class="sidebar-name"> 222 <div class="sidebar-name-arrow"></div> 223 <h3><?php esc_html_e('Setup Menus'); ?></h3> 224 </div> 225 <div class="widget-holder"> 226 227 <?php 228 // Setup custom menu 188 229 $enabled_menu = get_option('wp_custom_nav_menu'); 189 $checked = strtolower($enabled_menu); 190 191 if ( $checked != 'true' ) 192 echo '<div id="message-enabled" class="error fade below-h2"><p><strong>' . __('Menu editing has not been Enabled yet. Please enable it in order to use it -------->') . '</strong></p></div>'; 193 194 ?> 195 <?php echo $messagesdiv; ?> 196 <form onsubmit="updatepostdata()" action="custom-navigation.php" method="post" enctype="multipart/form-data"> 197 198 <input type="hidden" name="licount" id="licount" value="0" /> 199 <input type="hidden" name="menu_id_in_edit" id="menu_id_in_edit" value="<?php echo esc_attr($menu_selected_id); ?>" /> 200 230 $checked = strtolower($enabled_menu); 231 ?> 232 233 <span > 234 <label><?php _e('Enable'); ?></label><input type="radio" name="enable_wp_menu" value="true" <?php if ($checked=='true') { echo 'checked="checked"'; } ?> /> 235 <label><?php _e('Disable'); ?></label><input type="radio" name="enable_wp_menu" value="false" <?php if ($checked=='true') { } else { echo 'checked="checked"'; } ?> /> 236 </span><!-- /.checkboxes --> 237 238 <input id="set_wp_menu" type="submit" value="<?php esc_attr_e('Set Menu'); ?>" name="set_wp_menu" class="button" /><br /> 239 240 <span> 241 <label><?php _e('Reset Menu to Default'); ?></label> 242 <input id="reset_wp_menu" type="submit" value="Reset" name="reset_wp_menu" class="button" onclick="return confirm('<?php _e('Are you sure you want to reset the menu to its default settings?'); ?>');" /> 243 </span> 244 245 <div class="fix"></div> 246 </div> 247 </div><!-- /.widgets-holder-wrap --> 248 249 <div class="widgets-holder-wrap"> 201 250 <div class="sidebar-name"> 202 203 <div class="sidebar-name-arrow"> 204 <br/> 205 </div> 206 <h3><?php echo esc_html($menu_title); ?></h3> 207 208 </div> 209 210 <div id="nav-container"> 211 <ul id="custom-nav"> 212 213 <?php 214 //DISPLAY existing menu 215 if ( $menu_selected_id > 0 ) { 216 // SET output type 217 $output_type = "backend"; 218 // MAIN OUTPUT FUNCTION 219 wp_custom_navigation_output( 'type='.$output_type.'&name='.$menu_title.'&id='.$menu_selected_id ); 220 } 221 ?> 222 251 <div class="sidebar-name-arrow"></div> 252 <h3><?php esc_html_e('Menu Selector'); ?></h3> 253 </div> 254 <div class="widget-holder"> 255 <select id="menu_select" name="menu_select"> 256 <?php 257 // Display select options 258 foreach ( $custom_menus as $menu ) { 259 $menu_term = get_term( $menu, 'nav_menu' ); 260 if ( ( $menu_id_in_edit == $menu->term_id ) || ( $menu_selected_id == $menu->term_id ) ) 261 $selected_option = 'selected="selected"'; 262 else 263 $selected_option = ''; 264 ?> 265 <option value="<?php echo esc_attr($menu_term->term_id); ?>" <?php echo $selected_option; ?>><?php echo $menu_term->name; ?></option> 266 <?php 267 } 268 ?> 269 </select> 270 271 <input id="switch_menu" type="submit" value="<?php esc_attr_e('Switch'); ?>" name="switch_menu" class="button" /> 272 <input id="add_menu_name" name="add_menu_name" type="text" value="" /> 273 <input id="add_menu" type="submit" value="<?php esc_attr_e('Add Menu'); ?>" name="add_menu" class="button" /> 274 275 <div class="fix"></div> 276 </div> 277 </div><!-- /.widgets-holder-wrap --> 278 <?php $advanced_option_descriptions = get_option('wp_settings_custom_nav_advanced_options'); ?> 279 <div class="widgets-holder-wrap" style="display:none;"> 280 <div class="sidebar-name"> 281 <div class="sidebar-name-arrow"></div> 282 <h3><?php esc_html_e('Top Level Menu Descriptions'); ?></h3> 283 </div> 284 <div class="widget-holder"> 285 <span><?php _e('Display Descriptions in Top Level Menu?'); ?></span> 286 287 <?php 288 // UPDATE and DISPLAY Menu Description Option 289 if ( isset($_POST['menu-descriptions']) ) { 290 if ( !isset($_POST['switch_menu']) ) { 291 $menu_options_to_edit = $_POST['menu_id_in_edit']; 292 update_option('wp_settings_custom_nav_'.$menu_options_to_edit.'_descriptions',$_POST['menu-descriptions']); 293 } 294 } 295 296 if ( $menu_id_in_edit > 0 ) 297 $checkedraw = get_option('wp_settings_custom_nav_'.$menu_id_in_edit.'_descriptions'); 298 else 299 $checkedraw = get_option('wp_settings_custom_nav_'.$menu_selected_id.'_descriptions'); 300 301 $checked = strtolower($checkedraw); 302 303 if ( $advanced_option_descriptions == 'no' ) 304 $checked = 'no'; 305 ?> 306 307 <span class="checkboxes"> 308 <label><?php _e('Yes'); ?></label><input type="radio" name="menu-descriptions" value="yes" <?php if ($checked=='yes') { echo 'checked="checked"'; } ?> /> 309 <label><?php _e('No'); ?></label><input type="radio" name="menu-descriptions" value="no" <?php if ($checked=='yes') { } else { echo 'checked="checked"'; } ?> /> 310 </span><!-- /.checkboxes --> 311 </form> 312 <div class="fix"></div> 313 </div> 314 </div><!-- /.widgets-holder-wrap --> 315 316 <div class="widgets-holder-wrap"> 317 <div class="sidebar-name"> 318 <div class="sidebar-name-arrow"></div> 319 <h3><?php esc_html_e('Add an Existing Page'); ?></h3> 320 </div> 321 <div class="widget-holder"> 322 323 <?php 324 $pages_args = array( 325 'child_of' => 0, 326 'sort_order' => 'ASC', 327 'sort_column' => 'post_title', 328 'hierarchical' => 1, 329 'exclude' => '', 330 'include' => '', 331 'meta_key' => '', 332 'meta_value' => '', 333 'authors' => '', 334 'parent' => -1, 335 'exclude_tree' => '', 336 'number' => '', 337 'offset' => 0 ); 338 339 //GET all pages 340 $pages_array = get_pages($pages_args); 341 $page_name = ''; 342 //CHECK if pages exist 343 if ( $pages_array ) { 344 foreach ( $pages_array as $post ) { 345 //Add page name to 346 $page_name .= htmlentities($post->post_title).'|'; 347 } 348 } else { 349 $page_name = __('No pages available'); 350 } 351 ?> 352 353 <script> 354 jQuery(document).ready(function(){ 355 356 //GET PHP pages 357 var dataposts = "<?php echo esc_js($page_name); ?>".split("|"); 358 359 //Set autocomplete 360 jQuery("#page-search").autocomplete(dataposts); 361 362 //Handle autocomplete result 363 jQuery("#page-search").result(function(event, data, formatted) { 364 jQuery('#existing-pages').css('display','block'); 365 jQuery("#existing-pages dt:contains('" + data + "')").css("display", "block"); 366 367 jQuery('#show-pages').hide(); 368 jQuery('#hide-pages').show(); 369 370 }); 371 jQuery('#existing-pages').css('display','none'); 372 }); 373 </script> 374 375 <input type="text" onfocus="jQuery('#page-search').attr('value','');" id="page-search" value="<?php esc_attr_e('Search Pages'); ?>" /> 376 377 <a id="show-pages" style="cursor:pointer;" onclick="jQuery('#existing-pages').css('display','block');jQuery('#page-search').attr('value','');jQuery('#existing-pages dt').css('display','block');jQuery('#show-pages').hide();jQuery('#hide-pages').show();">View All</a> 378 <a id="hide-pages" style="cursor:pointer;" onclick="jQuery('#existing-pages').css('display','none');jQuery('#page-search').attr('value','Search Pages');jQuery('#existing-pages dt').css('display','none');jQuery('#show-pages').show();jQuery('#hide-pages').hide();">Hide All</a> 379 380 <script type="text/javascript"> 381 jQuery('#hide-pages').hide(); 382 </script> 383 384 <ul id="existing-pages" class="list"> 385 <?php 386 $intCounter = 0; 387 //Get default Pages 388 $intCounter = wp_custom_nav_get_pages($intCounter,'default'); 389 ?> 223 390 </ul> 224 </div><!-- /#nav-container --> 225 226 <p class="submit"> 227 228 <script type="text/javascript"> 229 updatepostdata(); 230 </script> 231 232 <input id="save_bottom" name="save_bottom" type="submit" value="<?php esc_attr_e('Save All Changes'); ?>" /></p> 233 </div><!-- /.inside --> 234 </div> 235 236 <div id="menu-right"> 237 <div class="widgets-holder-wrap"> 238 <div class="sidebar-name"> 239 <div class="sidebar-name-arrow"></div> 240 <h3><?php esc_html_e('Setup Menus'); ?></h3> 241 </div> 242 <div class="widget-holder"> 243 391 392 <div class="fix"></div> 393 394 </div> 395 </div><!-- /.widgets-holder-wrap --> 396 397 <div class="widgets-holder-wrap"> 398 <div class="sidebar-name"> 399 <div class="sidebar-name-arrow"></div> 400 <h3><?php esc_html_e('Add an Existing Category'); ?></h3> 401 </div> 402 <div class="widget-holder"> 403 404 <?php 405 // Custom GET categories query 406 // @todo Use API 407 $categories = $wpdb->get_results("SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'category' ORDER BY term_id ASC"); 408 $cat_name = ''; 409 //CHECK for results 410 if ( $categories ) { 411 foreach ( $categories as $category ) { 412 $cat_id = $category->term_id; 413 414 $cat_args = array( 415 'orderby' => 'name', 416 'include' => $cat_id, 417 'hierarchical' => 1, 418 'order' => 'ASC' 419 ); 420 421 $category_names=get_categories($cat_args); 422 423 if ( isset($category_names[0]->name) ) { 424 // Add category name to data string 425 $cat_name .= htmlentities($category_names[0]->name).'|'; 426 } 427 } 428 } else { 429 $cat_name = __('No categories available'); 430 } 431 ?> 432 433 <script> 434 jQuery(document).ready(function(){ 435 436 //GET PHP categories 437 var datacats = "<?php echo esc_js($cat_name); ?>".split("|"); 438 439 //Set autocomplete 440 jQuery("#cat-search").autocomplete(datacats); 441 442 //Handle autocomplete result 443 jQuery("#cat-search").result(function(event, data, formatted) { 444 jQuery('#existing-categories').css('display','block'); 445 jQuery("#existing-categories dt:contains('" + data + "')").css("display", "block"); 446 447 jQuery('#show-cats').hide(); 448 jQuery('#hide-cats').show(); 449 450 }); 451 jQuery('#existing-categories').css('display','none'); 452 453 }); 454 </script> 455 456 <input type="text" onfocus="jQuery('#cat-search').attr('value','');" id="cat-search" value="<?php esc_attr_e('Search Categories'); ?>" /> 457 458 <a id="show-cats" style="cursor:pointer;" onclick="jQuery('#existing-categories').css('display','block');jQuery('#cat-search').attr('value','');jQuery('#existing-categories dt').css('display','block');jQuery('#show-cats').hide();jQuery('#hide-cats').show();">View All</a> 459 <a id="hide-cats" style="cursor:pointer;" onclick="jQuery('#existing-categories').css('display','none');jQuery('#cat-search').attr('value','Search Categories');jQuery('#existing-categories dt').css('display','none');jQuery('#show-cats').show();jQuery('#hide-cats').hide();">Hide All</a> 460 461 <script type="text/javascript"> 462 jQuery('#hide-cats').hide(); 463 </script> 464 465 <ul id="existing-categories" class="list"> 244 466 <?php 245 246 // Setup custom menu 247 248 $enabled_menu = get_option('wp_custom_nav_menu'); 249 250 $checked = strtolower($enabled_menu); 251 252 ?> 253 254 <span > 255 <label><?php _e('Enable'); ?></label><input type="radio" name="enable_wp_menu" value="true" <?php if ($checked=='true') { echo 'checked="checked"'; } ?> /> 256 <label><?php _e('Disable'); ?></label><input type="radio" name="enable_wp_menu" value="false" <?php if ($checked=='true') { } else { echo 'checked="checked"'; } ?> /> 257 </span><!-- /.checkboxes --> 258 259 <input id="set_wp_menu" type="submit" value="<?php esc_attr_e('Set Menu'); ?>" name="set_wp_menu" class="button" /><br /> 260 261 <span> 262 <label><?php _e('Reset Menu to Default'); ?></label> 263 <input id="reset_wp_menu" type="submit" value="Reset" name="reset_wp_menu" class="button" onclick="return confirm('<?php _e('Are you sure you want to reset the menu to its default settings?'); ?>');" /> 264 </span> 265 266 <div class="fix"></div> 267 </div> 268 </div><!-- /.widgets-holder-wrap --> 269 270 <div class="widgets-holder-wrap"> 271 <div class="sidebar-name"> 272 <div class="sidebar-name-arrow"></div> 273 <h3><?php esc_html_e('Menu Selector'); ?></h3> 274 </div> 275 <div class="widget-holder"> 276 <select id="menu_select" name="menu_select"> 277 <?php 278 279 // Display select options 280 foreach ( $custom_menus as $menu ) { 281 $menu_term = get_term( $menu, 'nav_menu' ); 282 if ( ( $menu_id_in_edit == $menu->term_id ) || ( $menu_selected_id == $menu->term_id ) ) 283 $selected_option = 'selected="selected"'; 284 else 285 $selected_option = ''; 286 ?> 287 <option value="<?php echo esc_attr($menu_term->term_id); ?>" <?php echo $selected_option; ?>><?php echo $menu_term->name; ?></option> 288 <?php 289 290 } 291 ?> 292 </select> 293 294 <input id="switch_menu" type="submit" value="<?php esc_attr_e('Switch'); ?>" name="switch_menu" class="button" /> 295 <input id="add_menu_name" name="add_menu_name" type="text" value="" /> 296 <input id="add_menu" type="submit" value="<?php esc_attr_e('Add Menu'); ?>" name="add_menu" class="button" /> 297 298 <div class="fix"></div> 299 </div> 300 </div><!-- /.widgets-holder-wrap --> 301 <?php $advanced_option_descriptions = get_option('wp_settings_custom_nav_advanced_options'); ?> 302 <div class="widgets-holder-wrap" style="display:none;"> 303 <div class="sidebar-name"> 304 <div class="sidebar-name-arrow"></div> 305 <h3><?php esc_html_e('Top Level Menu Descriptions'); ?></h3> 306 </div> 307 <div class="widget-holder"> 308 <span><?php _e('Display Descriptions in Top Level Menu?'); ?></span> 309 310 <?php 311 312 // UPDATE and DISPLAY Menu Description Option 313 if ( isset($_POST['menu-descriptions']) ) { 314 if ( !isset($_POST['switch_menu']) ) { 315 $menu_options_to_edit = $_POST['menu_id_in_edit']; 316 update_option('wp_settings_custom_nav_'.$menu_options_to_edit.'_descriptions',$_POST['menu-descriptions']); 317 } 318 } 319 320 if ( $menu_id_in_edit > 0 ) 321 $checkedraw = get_option('wp_settings_custom_nav_'.$menu_id_in_edit.'_descriptions'); 322 else 323 $checkedraw = get_option('wp_settings_custom_nav_'.$menu_selected_id.'_descriptions'); 324 325 $checked = strtolower($checkedraw); 326 327 if ( $advanced_option_descriptions == 'no' ) 328 $checked = 'no'; 329 330 ?> 331 332 <span class="checkboxes"> 333 <label><?php _e('Yes'); ?></label><input type="radio" name="menu-descriptions" value="yes" <?php if ($checked=='yes') { echo 'checked="checked"'; } ?> /> 334 <label><?php _e('No'); ?></label><input type="radio" name="menu-descriptions" value="no" <?php if ($checked=='yes') { } else { echo 'checked="checked"'; } ?> /> 335 </span><!-- /.checkboxes --> 336 </form> 337 <div class="fix"></div> 338 </div> 339 </div><!-- /.widgets-holder-wrap --> 340 341 <div class="widgets-holder-wrap"> 342 <div class="sidebar-name"> 343 <div class="sidebar-name-arrow"></div> 344 <h3><?php esc_html_e('Add an Existing Page'); ?></h3> 345 </div> 346 <div class="widget-holder"> 347 348 <?php 349 350 $pages_args = array( 351 'child_of' => 0, 352 'sort_order' => 'ASC', 353 'sort_column' => 'post_title', 354 'hierarchical' => 1, 355 'exclude' => '', 356 'include' => '', 357 'meta_key' => '', 358 'meta_value' => '', 359 'authors' => '', 360 'parent' => -1, 361 'exclude_tree' => '', 362 'number' => '', 363 'offset' => 0 ); 364 365 //GET all pages 366 $pages_array = get_pages($pages_args); 367 $page_name = ''; 368 //CHECK if pages exist 369 if ( $pages_array ) { 370 foreach ( $pages_array as $post ) { 371 //Add page name to 372 $page_name .= htmlentities($post->post_title).'|'; 373 } 374 } else { 375 $page_name = __('No pages available'); 376 } 377 467 // Get default Categories 468 $intCounter = wp_custom_nav_get_categories($intCounter, 'default'); 378 469 ?> 379 380 <script> 381 jQuery(document).ready(function(){ 382 383 //GET PHP pages 384 var dataposts = "<?php echo esc_js($page_name); ?>".split("|"); 385 386 //Set autocomplete 387 jQuery("#page-search").autocomplete(dataposts); 388 389 //Handle autocomplete result 390 jQuery("#page-search").result(function(event, data, formatted) { 391 jQuery('#existing-pages').css('display','block'); 392 jQuery("#existing-pages dt:contains('" + data + "')").css("display", "block"); 393 394 jQuery('#show-pages').hide(); 395 jQuery('#hide-pages').show(); 396 397 }); 398 jQuery('#existing-pages').css('display','none'); 399 }); 400 </script> 401 402 403 <input type="text" onfocus="jQuery('#page-search').attr('value','');" id="page-search" value="<?php esc_attr_e('Search Pages'); ?>" /> 404 405 <a id="show-pages" style="cursor:pointer;" onclick="jQuery('#existing-pages').css('display','block');jQuery('#page-search').attr('value','');jQuery('#existing-pages dt').css('display','block');jQuery('#show-pages').hide();jQuery('#hide-pages').show();">View All</a> 406 <a id="hide-pages" style="cursor:pointer;" onclick="jQuery('#existing-pages').css('display','none');jQuery('#page-search').attr('value','Search Pages');jQuery('#existing-pages dt').css('display','none');jQuery('#show-pages').show();jQuery('#hide-pages').hide();">Hide All</a> 407 408 <script type="text/javascript"> 409 410 jQuery('#hide-pages').hide(); 411 412 </script> 413 414 <ul id="existing-pages" class="list"> 415 <?php 416 $intCounter = 0; 417 //Get default Pages 418 $intCounter = wp_custom_nav_get_pages($intCounter,'default'); 419 ?> 420 </ul> 421 422 <div class="fix"></div> 423 424 </div> 425 </div><!-- /.widgets-holder-wrap --> 426 427 <div class="widgets-holder-wrap"> 428 <div class="sidebar-name"> 429 <div class="sidebar-name-arrow"></div> 430 <h3><?php esc_html_e('Add an Existing Category'); ?></h3> 431 </div> 432 <div class="widget-holder"> 433 434 <?php 435 436 // Custom GET categories query 437 // @todo Use API 438 $categories = $wpdb->get_results("SELECT term_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'category' ORDER BY term_id ASC"); 439 $cat_name = ''; 440 //CHECK for results 441 if ( $categories ) { 442 foreach ( $categories as $category ) { 443 $cat_id = $category->term_id; 444 445 $cat_args = array( 446 'orderby' => 'name', 447 'include' => $cat_id, 448 'hierarchical' => 1, 449 'order' => 'ASC' 450 ); 451 452 $category_names=get_categories($cat_args); 453 454 if ( isset($category_names[0]->name) ) { 455 // Add category name to data string 456 $cat_name .= htmlentities($category_names[0]->name).'|'; 457 } 458 } 459 } else { 460 $cat_name = __('No categories available'); 461 } 462 463 ?> 464 465 <script> 466 jQuery(document).ready(function(){ 467 468 //GET PHP categories 469 var datacats = "<?php echo esc_js($cat_name); ?>".split("|"); 470 471 //Set autocomplete 472 jQuery("#cat-search").autocomplete(datacats); 473 474 //Handle autocomplete result 475 jQuery("#cat-search").result(function(event, data, formatted) { 476 jQuery('#existing-categories').css('display','block'); 477 jQuery("#existing-categories dt:contains('" + data + "')").css("display", "block"); 478 479 jQuery('#show-cats').hide(); 480 jQuery('#hide-cats').show(); 481 482 }); 483 jQuery('#existing-categories').css('display','none'); 484 485 }); 486 </script> 487 488 <input type="text" onfocus="jQuery('#cat-search').attr('value','');" id="cat-search" value="<?php esc_attr_e('Search Categories'); ?>" /> 489 490 <a id="show-cats" style="cursor:pointer;" onclick="jQuery('#existing-categories').css('display','block');jQuery('#cat-search').attr('value','');jQuery('#existing-categories dt').css('display','block');jQuery('#show-cats').hide();jQuery('#hide-cats').show();">View All</a> 491 <a id="hide-cats" style="cursor:pointer;" onclick="jQuery('#existing-categories').css('display','none');jQuery('#cat-search').attr('value','Search Categories');jQuery('#existing-categories dt').css('display','none');jQuery('#show-cats').show();jQuery('#hide-cats').hide();">Hide All</a> 492 493 <script type="text/javascript"> 494 495 jQuery('#hide-cats').hide(); 496 497 </script> 498 499 <ul id="existing-categories" class="list"> 500 <?php 501 // Get default Categories 502 $intCounter = wp_custom_nav_get_categories($intCounter, 'default'); 503 ?> 504 </ul> 505 506 <div class="fix"></div> 507 508 </div> 509 </div><!-- /.widgets-holder-wrap --> 510 511 <div class="widgets-holder-wrap"> 512 <div class="sidebar-name"> 513 <div class="sidebar-name-arrow"></div> 514 <h3><?php esc_html_e('Add a Custom Url'); ?></h3> 515 </div> 516 <div class="widget-holder"> 517 <input id="custom_menu_item_url" type="text" value="http://" /> 518 <label><?php _e('URL'); ?></label><br /> 519 <?php $templatedir = get_bloginfo('url'); ?> 520 <input type="hidden" id="templatedir" value="<?php echo esc_attr($templatedir); ?>" /> 521 <input id="custom_menu_item_name" type="text" value="Menu Item" onfocus="jQuery('#custom_menu_item_name').attr('value','');" /> 522 <label><?php _e('Menu Text'); ?></label><br /> 523 <input id="custom_menu_item_description" type="text" value="<?php esc_attr_e('A description'); ?>" <?php if ($advanced_option_descriptions == 'no') { ?>style="display:none;"<?php } ?> onfocus="jQuery('#custom_menu_item_description').attr('value','');" /> 524 <label <?php if ($advanced_option_descriptions == 'no') { ?>style="display:none;"<?php } ?> ><?php _e('Description'); ?></label> 525 <a class="addtomenu" onclick="appendToList('<?php echo $templatedir; ?>','Custom','','','','0','');jQuery('#custom_menu_item_name').attr('value','Menu Item');jQuery('#custom_menu_item_description').attr('value','A description');"><?php _e('Add to menu'); ?></a> 526 <div class="fix"></div> 527 </div> 528 </div><!-- /.widgets-holder-wrap --> 529 530 </div> 531 </div> 532 533 <script type="text/javascript"> 534 document.getElementById('pages-left').style.display='block'; 535 document.getElementById('menu-right').style.display='block'; 536 document.getElementById('no-js').style.display='none'; 537 </script> 538 539 <div id="dialog-confirm" title="<?php esc_attr_e('Edit Menu Item'); ?>"> 540 </label><input id="edittitle" type="text" name="edittitle" value="" /><label class="editlabel" for="edittitle"><?php _e('Menu Title'); ?></label><br /> 541 <input id="editlink" type="text" name="editlink" value="" /><label class="editlabel" for="editlink"><?php _e('URL'); ?></label><br /> 542 <input id="editanchortitle" type="text" name="editanchortitle" value="" /><label class="editlabel" for="editanchortitle"><?php _e('Link Title'); ?></label><br /> 543 <select id="editnewwindow" name="editnewwindow"> 544 <option value="1"><?php _e('Yes'); ?></option> 545 <option value="0"><?php _e('No'); ?></option> 546 </select><label class="editlabel" for="editnewwindow"><?php _e('Open Link in a new window'); ?></label> 547 <input id="editdescription" type="text" name="editdescription" value="" <?php if ($advanced_option_descriptions == 'no') { ?>style="display:none;"<?php } ?> /><label class="editlabel" for="editdescription" <?php if ($advanced_option_descriptions == 'no') { ?>style="display:none;"<?php } ?> ><?php _e('Description'); ?></label><br /> 548 </div> 470 </ul> 471 472 <div class="fix"></div> 473 474 </div> 475 </div><!-- /.widgets-holder-wrap --> 476 477 <div class="widgets-holder-wrap"> 478 <div class="sidebar-name"> 479 <div class="sidebar-name-arrow"></div> 480 <h3><?php esc_html_e('Add a Custom Url'); ?></h3> 481 </div> 482 <div class="widget-holder"> 483 <input id="custom_menu_item_url" type="text" value="http://" /> 484 <label><?php _e('URL'); ?></label><br /> 485 <?php $templatedir = get_bloginfo('url'); ?> 486 <input type="hidden" id="templatedir" value="<?php echo esc_attr($templatedir); ?>" /> 487 <input id="custom_menu_item_name" type="text" value="Menu Item" onfocus="jQuery('#custom_menu_item_name').attr('value','');" /> 488 <label><?php _e('Menu Text'); ?></label><br /> 489 <input id="custom_menu_item_description" type="text" value="<?php esc_attr_e('A description'); ?>" <?php if ($advanced_option_descriptions == 'no') { ?>style="display:none;"<?php } ?> onfocus="jQuery('#custom_menu_item_description').attr('value','');" /> 490 <label <?php if ($advanced_option_descriptions == 'no') { ?>style="display:none;"<?php } ?> ><?php _e('Description'); ?></label> 491 <a class="addtomenu" onclick="appendToList('<?php echo $templatedir; ?>','Custom','','','','0','');jQuery('#custom_menu_item_name').attr('value','Menu Item');jQuery('#custom_menu_item_description').attr('value','A description');"><?php _e('Add to menu'); ?></a> 492 <div class="fix"></div> 493 </div> 494 </div><!-- /.widgets-holder-wrap --> 495 496 </div> 497 </div> 498 499 <script type="text/javascript"> 500 document.getElementById('pages-left').style.display='block'; 501 document.getElementById('menu-right').style.display='block'; 502 document.getElementById('no-js').style.display='none'; 503 </script> 504 505 <div id="dialog-confirm" title="<?php esc_attr_e('Edit Menu Item'); ?>"> 506 </label><input id="edittitle" type="text" name="edittitle" value="" /><label class="editlabel" for="edittitle"><?php _e('Menu Title'); ?></label><br /> 507 <input id="editlink" type="text" name="editlink" value="" /><label class="editlabel" for="editlink"><?php _e('URL'); ?></label><br /> 508 <input id="editanchortitle" type="text" name="editanchortitle" value="" /><label class="editlabel" for="editanchortitle"><?php _e('Link Title'); ?></label><br /> 509 <select id="editnewwindow" name="editnewwindow"> 510 <option value="1"><?php _e('Yes'); ?></option> 511 <option value="0"><?php _e('No'); ?></option> 512 </select><label class="editlabel" for="editnewwindow"><?php _e('Open Link in a new window'); ?></label> 513 <input id="editdescription" type="text" name="editdescription" value="" <?php if ($advanced_option_descriptions == 'no') { ?>style="display:none;"<?php } ?> /><label class="editlabel" for="editdescription" <?php if ($advanced_option_descriptions == 'no') { ?>style="display:none;"<?php } ?> ><?php _e('Description'); ?></label><br /> 514 </div> 549 515 550 516 <?php 551 }552 517 553 518 include("admin-footer.php");
Note: See TracChangeset
for help on using the changeset viewer.