* @version 1.1.0 * * @package WordPress * @subpackage Administration */ require_once('admin.php'); if ( ! current_user_can('switch_themes') ) wp_die( __( 'Cheatin’ uh?' )); wp_admin_css( 'custom-navigation' ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'jquery-ui-draggable' ); wp_enqueue_script( 'jquery-ui-droppable' ); wp_enqueue_script( 'jquery-ui-sortable' ); wp_enqueue_script( 'jquery-ui-dialog' ); wp_enqueue_script( 'custom-navigation-dynamic-functions' ); wp_enqueue_script( 'custom-navigation-default-items' ); wp_enqueue_script( 'jquery-autocomplete' ); wp_enqueue_script( 'custom-navigation-php-functions' ); require_once('admin-header.php'); require_once (ABSPATH . WPINC . '/custom-navigation.php'); function wp_reset_nav_menu() { wp_custom_navigation_setup(true); return true; } $messagesdiv = ''; $menu_id_in_edit = 0; // Check which menu is selected and if menu is in edit already if ( isset( $_POST['switch_menu'] ) ) $menu_selected_id = (int) $_POST['menu_select']; elseif ( isset( $_POST['menu_id_in_edit'] ) ) $menu_selected_id = (int) $_POST['menu_id_in_edit']; else $menu_selected_id = 0; // Default Menu to show $custom_menus = get_terms( 'nav_menu', array( 'hide_empty' => false ) ); if ( !empty( $custom_menus ) ) $menu_selected_id = $custom_menus[0]->term_id; $menu_title = ''; if ( $menu_selected_id > 0 ) { foreach ( $custom_menus as $menu ) { if ( $menu->term_id == $menu_selected_id ) { $menu_title = $menu->name; break; } } } if ( isset( $_POST['set_wp_menu'] ) ) { // @todo validate set_wp_menu update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] ); $messagesdiv = '

' . __('Menu has been updated!') . '

'; } if ( isset( $_POST['licount'] ) ) $postCounter = $_POST['licount']; else $postCounter = 0; // Create a new menu. Menus are stored as terms in the 'menu' taxonomy. if ( isset( $_POST['add_menu'] ) ) { $insert_menu_name = $_POST['add_menu_name']; if ( $insert_menu_name != '' ) { $menu = wp_create_nav_menu($insert_menu_name); if ( is_wp_error($menu) ) { $messagesdiv = '

' . esc_html( $menu->get_error_message() ) . '

'; } else { $custom_menus[$menu->term_id] = $menu; $menu_selected_id = $menu->term_id; $menu_id_in_edit = $menu_selected_id; $messagesdiv = '

' . esc_html( sprintf( __('"%s" menu has been created!'), $menu->name ) ) . '

'; $postCounter = 0; } } else { $messagesdiv = '

' . __('Please enter a valid menu name.') . '

'; } } if ( isset($_POST['reset_wp_menu']) ) { $success = wp_reset_nav_menu(); if ( $success ) { // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly $messagesdiv = '

' . __('The menu has been reset.') . '

'; // GET reset menu id $custom_menus = array(); $menu_selected_id = 0; } else { // DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly $messagesdiv = '

' . __('The menu could not be reset. Please try again.') . '

'; } } elseif ( $postCounter > 0 && $menu_selected_id > 0 ) { $menu_items = wp_get_nav_menu_items( $menu_selected_id, array('orderby' => 'ID', 'output' => ARRAY_A, 'output_key' => 'ID') ); $parent_menu_ids = array(); // Loop through all POST variables for ( $k = 1; $k <= $postCounter; $k++ ) { if (isset($_POST['dbid'.$k])) { $db_id = $_POST['dbid'.$k]; } else { $db_id = 0; } if (isset($_POST['postmenu'.$k])) { $object_id = $_POST['postmenu'.$k]; } else { $object_id = 0; } if (isset($_POST['parent'.$k])) { $parent_id = $_POST['parent'.$k]; } else { $parent_id = 0; } if (isset($_POST['title'.$k])) { $custom_title = $_POST['title'.$k]; } else { $custom_title = ''; } if (isset($_POST['linkurl'.$k])) { $custom_linkurl = $_POST['linkurl'.$k]; } else { $custom_linkurl = ''; } if (isset($_POST['description'.$k])) { $custom_description = $_POST['description'.$k]; } else { $custom_description = ''; } // doesn't seem to be used by UI if (isset($_POST['icon'.$k])) { $icon = $_POST['icon'.$k]; } else { $icon = 0; } if (isset($_POST['position'.$k])) { $position = $_POST['position'.$k]; } else { $position = 0; } if (isset($_POST['linktype'.$k])) { $linktype = $_POST['linktype'.$k]; } else { $linktype = 'custom'; } if (isset($_POST['anchortitle'.$k])) { $custom_anchor_title = $_POST['anchortitle'.$k]; } else { $custom_anchor_title = $custom_title; } if (isset($_POST['newwindow'.$k])) { $new_window = $_POST['newwindow'.$k]; } else { $new_window = 0; } $post = array( 'post_status' => 'publish', 'post_type' => 'nav_menu_item', 'post_author' => $user_ID, 'ping_status' => 0, 'post_parent' => 0, 'menu_order' => $position, 'guid' => $custom_linkurl, 'post_excerpt' => $custom_anchor_title, 'tax_input' => array( 'nav_menu' => $menu_title ), 'post_content' => $custom_description, 'post_title' => $custom_title ); if ( $new_window ) $post['post_content_filtered'] = '_blank'; else $post['post_content_filtered'] = ''; if ( $parent_id > 0 && isset( $parent_menu_ids[ $parent_id ] ) ) $post[ 'post_parent' ] = $parent_menu_ids[ $parent_id ]; // New menu item if ( $db_id == 0 ) { $db_id = wp_insert_post( $post ); } elseif ( isset( $menu_items[$db_id] ) ) { $post['ID'] = $db_id; wp_update_post( $post ); unset( $menu_items[$db_id] ); } $parent_menu_ids[ $k ] = $db_id; update_post_meta($db_id, 'menu_type', $linktype); update_post_meta($db_id, 'object_id', $object_id); } if ( !empty( $menu_items ) ) { foreach ( array_keys( $menu_items ) as $menu_id ) { wp_delete_post( $menu_id ); } } // DISPLAY SUCCESS MESSAGE IF POST CORRECT $messagesdiv = '

' . __('The menu has been updated.') . '

'; } ?>

' . __('Menu editing has not been Enabled yet. Please enable it in order to use it -------->') . '

'; ?>




style="display:none;" />