* @version 1.1.0
*
* @package WordPress
* @subpackage Administration
*/
require_once('admin.php');
wp_admin_css( 'custom-navigation' );
wp_enqueue_script( 'custom-navigation-jquery' );
wp_enqueue_script( 'custom-navigation-ui-custom' );
wp_enqueue_script( 'custom-navigation-dynamic-functions' );
wp_enqueue_script( 'custom-navigation-default-items' );
wp_enqueue_script( 'custom-navigation-autocomplete' );
wp_enqueue_script( 'custom-navigation-php-functions' );
wp_enqueue_script( 'jquery-ui-dialog' );
require_once('admin-header.php');
require_once (ABSPATH . WPINC . '/custom-navigation-functions.php');
wp_custom_navigation();
function wp_custom_nav_reset() {
global $wpdb;
$table_name = $wpdb->prefix . "custom_nav_records";
//DROP existing menu records
$wpdb->query("DELETE FROM ".$table_name);
$table_name_menus = $wpdb->prefix . "custom_nav_menus";
//DELETE existing menus
$wpdb->query("DELETE FROM ".$table_name_menus);
wp_custom_navigation_setup(true);
return true;
}
/*-----------------------------------------------------------------------------------*/
/* Custom Navigation Admin Interface
/* wp_custom_navigation() is the main function for the Custom Navigation
/* See functions in admin-functions.php
/*-----------------------------------------------------------------------------------*/
function wp_custom_navigation() {
global $wpdb, $user_ID;
?>
You do not have JavaScript enabled in your browser. Please enabled it to access the Custom Menu functionality.
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'] ) ) {
update_option( 'wp_custom_nav_menu', $_POST['enable_wp_menu'] );
$messagesdiv = '
'.$themename.'s Custom Menu has been updated!
';
}
if ( isset( $_POST['licount'] ) )
$postCounter = $_POST['licount'];
else
$postCounter = 0;
if ( isset( $_POST['add_menu'] ) ) {
$insert_menu_name = $_POST['add_menu_name'];
if ( $insert_menu_name != '' ) {
$existing_term = get_term_by( 'name', $insert_menu_name, 'menu' );
if ( $existing_term ) {
$messagesdiv = '
'.$insert_menu_name.' Menu has already created - please try another name
';
} else {
$term = wp_insert_term( $insert_menu_name, 'menu' );
if ( $term ) {
$custom_menus[$term['term_id']] = $term;
$menu_selected_id = $term['term_id'];
$menu_id_in_edit = $menu_selected_id;
$messagesdiv = '
'.$insert_menu_name.' Menu has been created!
';
$postCounter = 0;
}
}
} else {
$messagesdiv = '
Please enter a valid Menu name
';
}
}
if (isset($_POST['reset_wp_menu'])) {
$success = wp_custom_nav_reset();
if ($success) {
//DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
$messagesdiv = '
'.$themename.'s Custom Menu has been RESET!
';
//GET reset menu id
$custom_menus = array();
$menu_selected_id = 0;
} else {
//DISPLAY SUCCESS MESSAGE IF Menu Reset Correctly
$messagesdiv = '
'.$themename.'s Custom Menu could not be RESET. Please try again.
';
}
} elseif ( $postCounter > 0 && $menu_selected_id > 0 ) {
$menu_objects = get_objects_in_term( $menu_selected_id, 'menu' );
$menu_items = wp_custom_navigation_get_menu_items( $menu_objects );
$update_fields = array( 'menu_order', 'guid', 'post_content', 'post_title', 'post_excerpt', 'post_content_filtered' );
//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])) { $post_id = $_POST['postmenu'.$k]; } else { $post_id = 0; }
//@todo implement heirarchy
if (isset($_POST['parent'.$k])) { $parent_id = $_POST['parent'.$k]; } else { $parent_id = 0; }
if (isset($_POST['title'.$k])) { $custom_title = stripslashes($_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 = stripslashes($_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 = stripslashes($_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' => 'menu_item', 'post_author' => $user_ID,
'ping_status' => 0, 'post_parent' => $post_id, '`menu_order' => $position,
'guid' => $custom_linkurl, 'post_excerpt' => $custom_anchor_title, 'tax_input' => array( 'menu' => $menu_title ),
'post_content' => $custom_description, 'post_title' => $custom_title );
if ( $new_window )
$post['post_content_filtered'] = '_blank';
else
$post['post_content_filtered'] = '';
//New menu item
if ($db_id == 0) {
$db_id = $post_id = wp_insert_post( $post );
} elseif ( isset( $menu_items[$db_id] ) ) {
foreach( $update_fields as $field ) {
if ( $post[$field] != $menu_items[$db_id]->$field ) {
$post['ID'] = $db_id;
wp_update_post( $post );
break;
}
}
unset( $menu_items[$db_id] );
}
update_post_meta($db_id, 'menu_type', $linktype);
}
if ( !empty( $menu_items ) ) {
foreach( array_keys( $menu_items ) as $menu_id ) {
wp_delete_post( $menu_id );
}
}
//DISPLAY SUCCESS MESSAGE IF POST CORRECT
$messagesdiv = '
'.$themename.'s Custom Menu has been updated!
';
}
//DISPLAY Custom Navigation
?>
Custom Navigation
The Custom Menu has not been Enabled yet. Please enable it in order to use it -------->
';
}
?>