* @version 1.1.0
*
* @package WordPress
* @subpackage Administration
*/
require_once('admin.php');
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');
wp_custom_navigation();
function wp_custom_nav_reset() {
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;
?>
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 = '
' . __('Custom 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 != '' ) {
$existing_term = get_term_by( 'name', $insert_menu_name, 'nav_menu' );
if ( $existing_term ) {
$messagesdiv = '
' . esc_html( sprintf( e__('A menu named "%s" already exists; please try another name.'), $existing_term->name ) ) . '
';
} else {
$term = wp_insert_term( $insert_menu_name, 'nav_menu' );
if ( !is_wp_error($term) ) {
$term = get_term($term['term_id'], 'nav_menu');
$custom_menus[$term->term_id] = $term;
$menu_selected_id = $term->term_id;
$menu_id_in_edit = $menu_selected_id;
$messagesdiv = '
' . esc_html( sprintf( __('"%s" menu has been created!'), $term->name ) ) . '
';
$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 = '
' . __('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_objects = get_objects_in_term( $menu_selected_id, 'nav_menu' );
$menu_items = wp_custom_navigation_get_menu_items( $menu_objects );
// 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( $_POST[ 'dbid' . $parent_id ] ) )
$post[ 'post_parent' ] = (int) $_POST[ 'dbid' . $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] );
}
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.') . '
';
}
// DISPLAY Custom Navigation
?>
' . __('The Custom Menu has not been Enabled yet. Please enable it in order to use it -------->') . '
';
?>