wp/wp-admin/nav-menus.php
author ymh <ymh.work@gmail.com>
Thu, 07 Nov 2013 00:08:07 +0000
changeset 1 f6eb5a861d2f
parent 0 d970ebf37754
child 5 5e2f62d02dcd
permissions -rw-r--r--
remove unnessary files. Make timthumb work
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/**
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * WordPress Administration for Navigation Menus
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 * Interface functions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 * @version 2.0.0
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 *
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * @package WordPress
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 * @subpackage Administration
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
 */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
/** Load WordPress Administration Bootstrap */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
require_once( dirname( __FILE__ ) . '/admin.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
// Load all the nav menu interface functions
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
require_once( ABSPATH . 'wp-admin/includes/nav-menu.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
	wp_die( __( 'Your theme does not support navigation menus or widgets.' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
// Permissions Check
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
if ( ! current_user_can('edit_theme_options') )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
	wp_die( __( 'Cheatin&#8217; uh?' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
wp_enqueue_script( 'nav-menu' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
if ( wp_is_mobile() )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
	wp_enqueue_script( 'jquery-touch-punch' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
// Container for any messages displayed to the user
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
$messages = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
// Container that stores the name of the active menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
$nav_menu_selected_title = '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
// The menu id of the current menu being edited
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
$nav_menu_selected_id = isset( $_REQUEST['menu'] ) ? (int) $_REQUEST['menu'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39
// Get existing menu locations assignments
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    40
$locations = get_registered_nav_menus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    41
$menu_locations = get_nav_menu_locations();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    42
$num_locations = count( array_keys( $locations ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    44
// Allowed actions: add, update, delete
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    45
$action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    46
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    47
switch ( $action ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    48
	case 'add-menu-item':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    49
		check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    50
		if ( isset( $_REQUEST['nav-menu-locations'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    51
			set_theme_mod( 'nav_menu_locations', array_map( 'absint', $_REQUEST['menu-locations'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    52
		elseif ( isset( $_REQUEST['menu-item'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    53
			wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    54
		break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    55
	case 'move-down-menu-item' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    56
		// moving down a menu item is the same as moving up the next in order
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    57
		check_admin_referer( 'move-menu_item' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    58
		$menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    59
		if ( is_nav_menu_item( $menu_item_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    60
			$menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    61
			if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    62
				$menu_id = (int) $menus[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    63
				$ordered_menu_items = wp_get_nav_menu_items( $menu_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    64
				$menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    65
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    66
				// set up the data we need in one pass through the array of menu items
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    67
				$dbids_to_orders = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    68
				$orders_to_dbids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    69
				foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    70
					if ( isset( $ordered_menu_item_object->ID ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    71
						if ( isset( $ordered_menu_item_object->menu_order ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    72
							$dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    73
							$orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    74
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    75
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    76
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    77
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    78
				// get next in order
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    79
				if (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    80
					isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    81
				) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    82
					$next_item_id = $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    83
					$next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    84
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    85
					// if not siblings of same parent, bubble menu item up but keep order
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    86
					if (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    87
						! empty( $menu_item_data['menu_item_parent'] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    88
						(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    89
							empty( $next_item_data['menu_item_parent'] ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    90
							$next_item_data['menu_item_parent'] != $menu_item_data['menu_item_parent']
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    91
						)
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    92
					) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    93
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    94
						$parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    95
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    96
						$parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    97
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    98
						if ( ! is_wp_error( $parent_object ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
    99
							$parent_data = (array) $parent_object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   100
							$menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   101
							update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   102
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   103
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   104
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   105
					// make menu item a child of its next sibling
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   106
					} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   107
						$next_item_data['menu_order'] = $next_item_data['menu_order'] - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   108
						$menu_item_data['menu_order'] = $menu_item_data['menu_order'] + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   109
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   110
						$menu_item_data['menu_item_parent'] = $next_item_data['ID'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   111
						update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   112
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   113
						wp_update_post($menu_item_data);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   114
						wp_update_post($next_item_data);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   115
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   116
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   117
				// the item is last but still has a parent, so bubble up
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   118
				} elseif (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   119
					! empty( $menu_item_data['menu_item_parent'] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   120
					in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   121
				) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   122
					$menu_item_data['menu_item_parent'] = (int) get_post_meta( $menu_item_data['menu_item_parent'], '_menu_item_menu_item_parent', true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   123
					update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   124
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   125
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   126
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   127
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   128
		break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   129
	case 'move-up-menu-item' :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   130
		check_admin_referer( 'move-menu_item' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
		$menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   132
		if ( is_nav_menu_item( $menu_item_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   133
			$menus = isset( $_REQUEST['menu'] ) ? array( (int) $_REQUEST['menu'] ) : wp_get_object_terms( $menu_item_id, 'nav_menu', array( 'fields' => 'ids' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   134
			if ( ! is_wp_error( $menus ) && ! empty( $menus[0] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   135
				$menu_id = (int) $menus[0];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   136
				$ordered_menu_items = wp_get_nav_menu_items( $menu_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   137
				$menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   138
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   139
				// set up the data we need in one pass through the array of menu items
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
				$dbids_to_orders = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
				$orders_to_dbids = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
				foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   143
					if ( isset( $ordered_menu_item_object->ID ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   144
						if ( isset( $ordered_menu_item_object->menu_order ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   145
							$dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   146
							$orders_to_dbids[$ordered_menu_item_object->menu_order] = $ordered_menu_item_object->ID;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   147
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   148
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   149
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   151
				// if this menu item is not first
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   152
				if ( ! empty( $dbids_to_orders[$menu_item_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   153
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   154
					// if this menu item is a child of the previous
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   155
					if (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   156
						! empty( $menu_item_data['menu_item_parent'] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   157
						in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
						isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
						( $menu_item_data['menu_item_parent'] == $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   160
					) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   161
						$parent_db_id = in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) ? (int) $menu_item_data['menu_item_parent'] : 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   162
						$parent_object = wp_setup_nav_menu_item( get_post( $parent_db_id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   163
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   164
						if ( ! is_wp_error( $parent_object ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   165
							$parent_data = (array) $parent_object;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   166
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   167
							// if there is something before the parent and parent a child of it, make menu item a child also of it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   168
							if (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   169
								! empty( $dbids_to_orders[$parent_db_id] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   170
								! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   171
								! empty( $parent_data['menu_item_parent'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   172
							) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   173
								$menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   174
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   175
							// else if there is something before parent and parent not a child of it, make menu item a child of that something's parent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   176
							} elseif (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   177
								! empty( $dbids_to_orders[$parent_db_id] ) &&
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
								! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
							) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180
								$_possible_parent_id = (int) get_post_meta( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1], '_menu_item_menu_item_parent', true);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   181
								if ( in_array( $_possible_parent_id, array_keys( $dbids_to_orders ) ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   182
									$menu_item_data['menu_item_parent'] = $_possible_parent_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   183
								else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   184
									$menu_item_data['menu_item_parent'] = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   185
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   186
							// else there isn't something before the parent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   187
							} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   188
								$menu_item_data['menu_item_parent'] = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   189
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   190
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   191
							// set former parent's [menu_order] to that of menu-item's
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   192
							$parent_data['menu_order'] = $parent_data['menu_order'] + 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   193
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   194
							// set menu-item's [menu_order] to that of former parent
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   195
							$menu_item_data['menu_order'] = $menu_item_data['menu_order'] - 1;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   196
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   197
							// save changes
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   198
							update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   199
							wp_update_post($menu_item_data);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   200
							wp_update_post($parent_data);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   201
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   202
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   203
					// else this menu item is not a child of the previous
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   204
					} elseif (
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   205
						empty( $menu_item_data['menu_order'] ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   206
						empty( $menu_item_data['menu_item_parent'] ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   207
						! in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   208
						empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ||
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   209
						$orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] != $menu_item_data['menu_item_parent']
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   210
					) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   211
						// just make it a child of the previous; keep the order
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   212
						$menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   213
						update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   214
						wp_update_post($menu_item_data);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   215
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   216
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   217
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   218
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   219
		break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   220
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   221
	case 'delete-menu-item':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   222
		$menu_item_id = (int) $_REQUEST['menu-item'];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   223
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   224
		check_admin_referer( 'delete-menu_item_' . $menu_item_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   225
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   226
		if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   227
			$messages[] = '<div id="message" class="updated"><p>' . __('The menu item has been successfully deleted.') . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   228
		break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   229
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   230
	case 'delete':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   231
		check_admin_referer( 'delete-nav_menu-' . $nav_menu_selected_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   232
		if ( is_nav_menu( $nav_menu_selected_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   233
			$deletion = wp_delete_nav_menu( $nav_menu_selected_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   234
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   235
			// Reset the selected menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   236
			$nav_menu_selected_id = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   237
			unset( $_REQUEST['menu'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   238
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   239
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   240
		if ( ! isset( $deletion ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   241
			break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   242
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   243
		if ( is_wp_error( $deletion ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   244
			$messages[] = '<div id="message" class="error"><p>' . $deletion->get_error_message() . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   245
		else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   246
			$messages[] = '<div id="message" class="updated"><p>' . __( 'The menu has been successfully deleted.' ) . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   247
		break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   248
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   249
	case 'delete_menus':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   250
		check_admin_referer( 'nav_menus_bulk_actions' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   251
		foreach ( $_REQUEST['delete_menus'] as $menu_id_to_delete ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   252
			if ( ! is_nav_menu( $menu_id_to_delete ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   253
				continue;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   254
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   255
			$deletion = wp_delete_nav_menu( $menu_id_to_delete );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   256
			if ( is_wp_error( $deletion ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   257
				$messages[] = '<div id="message" class="error"><p>' . $deletion->get_error_message() . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   258
				$deletion_error = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   259
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   260
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   261
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   262
		if ( empty( $deletion_error ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   263
			$messages[] = '<div id="message" class="updated"><p>' . __( 'Selected menus have been successfully deleted.' ) . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   264
		break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   265
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   266
	case 'update':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   267
		check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   268
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   269
		// Remove menu locations that have been unchecked
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   270
		foreach ( $locations as $location => $description ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   271
			if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) ) && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   272
				unset( $menu_locations[ $location ] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   273
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   274
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   275
		// Merge new and existing menu locations if any new ones are set
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   276
		if ( isset( $_POST['menu-locations'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   277
			$new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   278
			$menu_locations = array_merge( $menu_locations, $new_menu_locations );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   279
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   280
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   281
		// Set menu locations
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   282
		set_theme_mod( 'nav_menu_locations', $menu_locations );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   283
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   284
		// Add Menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   285
		if ( 0 == $nav_menu_selected_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   286
			$new_menu_title = trim( esc_html( $_POST['menu-name'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   287
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   288
			if ( $new_menu_title ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   289
				$_nav_menu_selected_id = wp_update_nav_menu_object( 0, array('menu-name' => $new_menu_title) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   290
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   291
				if ( is_wp_error( $_nav_menu_selected_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   292
					$messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   293
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   294
					$_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   295
					$nav_menu_selected_id = $_nav_menu_selected_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   296
					$nav_menu_selected_title = $_menu_object->name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   297
					if ( isset( $_REQUEST['menu-item'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   298
						wp_save_nav_menu_items( $nav_menu_selected_id, absint( $_REQUEST['menu-item'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   299
					if ( isset( $_REQUEST['zero-menu-state'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   300
						// If there are menu items, add them
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   301
						wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   302
						// Auto-save nav_menu_locations
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   303
						$locations = get_nav_menu_locations();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   304
						foreach ( $locations as $location => $menu_id ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   305
								$locations[ $location ] = $nav_menu_selected_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   306
								break; // There should only be 1
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   307
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   308
						set_theme_mod( 'nav_menu_locations', $locations );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   309
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   310
					if ( isset( $_REQUEST['use-location'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   311
						$locations = get_registered_nav_menus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   312
						$menu_locations = get_nav_menu_locations();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   313
						if ( isset( $locations[ $_REQUEST['use-location'] ] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   314
							$menu_locations[ $_REQUEST['use-location'] ] = $nav_menu_selected_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   315
						set_theme_mod( 'nav_menu_locations', $menu_locations );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   316
					}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   317
					// $messages[] = '<div id="message" class="updated"><p>' . sprintf( __( '<strong>%s</strong> has been created.' ), $nav_menu_selected_title ) . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   318
					wp_redirect( admin_url( 'nav-menus.php?menu=' . $_nav_menu_selected_id ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   319
					exit();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   320
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   321
			} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   322
				$messages[] = '<div id="message" class="error"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   323
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   324
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   325
		// Update existing menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   326
		} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   327
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   328
			$_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   329
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   330
			$menu_title = trim( esc_html( $_POST['menu-name'] ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   331
			if ( ! $menu_title ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   332
				$messages[] = '<div id="message" class="error"><p>' . __( 'Please enter a valid menu name.' ) . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   333
				$menu_title = $_menu_object->name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   334
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   335
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   336
			if ( ! is_wp_error( $_menu_object ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   337
				$_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   338
				if ( is_wp_error( $_nav_menu_selected_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   339
					$_menu_object = $_nav_menu_selected_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   340
					$messages[] = '<div id="message" class="error"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   341
				} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   342
					$_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   343
					$nav_menu_selected_title = $_menu_object->name;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   344
				}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   345
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   346
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   347
			// Update menu items
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   348
			if ( ! is_wp_error( $_menu_object ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   349
				$messages = array_merge( $messages, wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   350
			}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   351
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   352
		break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   353
	case 'locations':
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   354
		if ( ! $num_locations ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   355
			wp_redirect( admin_url( 'nav-menus.php' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   356
			exit();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   357
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   358
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   359
		add_filter( 'screen_options_show_screen', '__return_false' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   360
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   361
		if ( isset( $_POST['menu-locations'] ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   362
			check_admin_referer( 'save-menu-locations' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   363
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   364
			$new_menu_locations = array_map( 'absint', $_POST['menu-locations'] );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   365
			$menu_locations = array_merge( $menu_locations, $new_menu_locations );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   366
			// Set menu locations
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   367
			set_theme_mod( 'nav_menu_locations', $menu_locations );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   368
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   369
			$messages[] = '<div id="message" class="updated"><p>' . __( 'Menu locations updated.' ) . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   370
		}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   371
		break;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   372
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   373
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   374
// Get all nav menus
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   375
$nav_menus = wp_get_nav_menus( array('orderby' => 'name') );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   376
$menu_count = count( $nav_menus );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   377
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   378
// Are we on the add new screen?
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   379
$add_new_screen = ( isset( $_GET['menu'] ) && 0 == $_GET['menu'] ) ? true : false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   380
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   381
$locations_screen = ( isset( $_GET['action'] ) && 'locations' == $_GET['action'] ) ? true : false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   382
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   383
// If we have one theme location, and zero menus, we take them right into editing their first menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   384
$page_count = wp_count_posts( 'page' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   385
$one_theme_location_no_menus = ( 1 == count( get_registered_nav_menus() ) && ! $add_new_screen && empty( $nav_menus ) && ! empty( $page_count->publish ) ) ? true : false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   386
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   387
$nav_menus_l10n = array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   388
	'oneThemeLocationNoMenus' => $one_theme_location_no_menus,
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   389
	'moveUp'       => __( 'Move up one' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   390
	'moveDown'     => __( 'Move down one' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   391
	'moveToTop'    => __( 'Move to the top' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   392
	/* translators: %s: previous item name */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   393
	'moveUnder'    => __( 'Move under %s' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   394
	/* translators: %s: previous item name */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   395
	'moveOutFrom'  => __( 'Move out from under %s' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   396
	/* translators: %s: previous item name */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   397
	'under'        => __( 'Under %s' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   398
	/* translators: %s: previous item name */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   399
	'outFrom'      => __( 'Out from under %s' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   400
	/* translators: 1: item name, 2: item position, 3: total number of items */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   401
	'menuFocus'    => __( '%1$s. Menu item %2$d of %3$d.' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   402
	/* translators: 1: item name, 2: item position, 3: parent item name */
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   403
	'subMenuFocus' => __( '%1$s. Sub item number %2$d under %3$s.' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   404
);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   405
wp_localize_script( 'nav-menu', 'menus', $nav_menus_l10n );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   406
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   407
// Redirect to add screen if there are no menus and this users has either zero, or more than 1 theme locations
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   408
if ( 0 == $menu_count && ! $add_new_screen && ! $one_theme_location_no_menus )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   409
	wp_redirect( admin_url( 'nav-menus.php?action=edit&menu=0' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   410
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   411
// Get recently edited nav menu
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   412
$recently_edited = absint( get_user_option( 'nav_menu_recently_edited' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   413
if ( empty( $recently_edited ) && is_nav_menu( $nav_menu_selected_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   414
	$recently_edited = $nav_menu_selected_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   415
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   416
// Use $recently_edited if none are selected
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   417
if ( empty( $nav_menu_selected_id ) && ! isset( $_GET['menu'] ) && is_nav_menu( $recently_edited ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   418
	$nav_menu_selected_id = $recently_edited;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   419
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   420
// On deletion of menu, if another menu exists, show it
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   421
if ( ! $add_new_screen && 0 < $menu_count && isset( $_GET['action'] ) && 'delete' == $_GET['action'] )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   422
	$nav_menu_selected_id = $nav_menus[0]->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   423
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   424
// Set $nav_menu_selected_id to 0 if no menus
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   425
if ( $one_theme_location_no_menus ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   426
	$nav_menu_selected_id = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   427
} elseif ( empty( $nav_menu_selected_id ) && ! empty( $nav_menus ) && ! $add_new_screen ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   428
	// if we have no selection yet, and we have menus, set to the first one in the list
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   429
	$nav_menu_selected_id = $nav_menus[0]->term_id;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   430
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   431
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   432
// Update the user's setting
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   433
if ( $nav_menu_selected_id != $recently_edited && is_nav_menu( $nav_menu_selected_id ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   434
	update_user_meta( $current_user->ID, 'nav_menu_recently_edited', $nav_menu_selected_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   435
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   436
// If there's a menu, get its name.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   437
if ( ! $nav_menu_selected_title && is_nav_menu( $nav_menu_selected_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   438
	$_menu_object = wp_get_nav_menu_object( $nav_menu_selected_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   439
	$nav_menu_selected_title = ! is_wp_error( $_menu_object ) ? $_menu_object->name : '';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   440
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   441
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   442
// Generate truncated menu names
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   443
foreach( (array) $nav_menus as $key => $_nav_menu ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   444
	$nav_menus[$key]->truncated_name = wp_html_excerpt( $_nav_menu->name, 40, '&hellip;' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   445
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   446
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   447
// Retrieve menu locations
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   448
if ( current_theme_supports( 'menus' ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   449
	$locations = get_registered_nav_menus();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   450
	$menu_locations = get_nav_menu_locations();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   451
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   452
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   453
// Ensure the user will be able to scroll horizontally
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   454
// by adding a class for the max menu depth.
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   455
global $_wp_nav_menu_max_depth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   456
$_wp_nav_menu_max_depth = 0;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   457
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   458
// Calling wp_get_nav_menu_to_edit generates $_wp_nav_menu_max_depth
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   459
if ( is_nav_menu( $nav_menu_selected_id ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   460
	$menu_items = wp_get_nav_menu_items( $nav_menu_selected_id, array( 'post_status' => 'any' ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   461
	$edit_markup = wp_get_nav_menu_to_edit( $nav_menu_selected_id );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   462
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   463
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   464
function wp_nav_menu_max_depth($classes) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   465
	global $_wp_nav_menu_max_depth;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   466
	return "$classes menu-max-depth-$_wp_nav_menu_max_depth";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   467
}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   468
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   469
add_filter('admin_body_class', 'wp_nav_menu_max_depth');
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   470
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   471
wp_nav_menu_setup();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   472
wp_initial_nav_menu_meta_boxes();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   473
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   474
if ( ! current_theme_supports( 'menus' ) && ! $num_locations )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   475
	$messages[] = '<div id="message" class="updated"><p>' . sprintf( __( 'Your theme does not natively support menus, but you can use them in sidebars by adding a &#8220;Custom Menu&#8221; widget on the <a href="%s">Widgets</a> screen.' ), admin_url( 'widgets.php' ) ) . '</p></div>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   476
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   477
if ( ! $locations_screen ) : // Main tab
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   478
	$overview  = '<p>' . __( 'This screen is used for managing your custom navigation menus.' ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   479
	$overview .= '<p>' . sprintf( __( 'Menus can be displayed in locations defined by your theme, even used in sidebars by adding a &#8220;Custom Menu&#8221; widget on the <a href="%1$s">Widgets</a> screen. If your theme does not support the custom menus feature (the default themes, %2$s and %3$s, do), you can learn about adding this support by following the Documentation link to the side.' ), admin_url( 'widgets.php' ), 'Twenty Thirteen', 'Twenty Twelve' ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   480
	$overview .= '<p>' . __( 'From this screen you can:' ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   481
	$overview .= '<ul><li>' . __( 'Create, edit, and delete menus' ) . '</li>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   482
	$overview .= '<li>' . __( 'Add, organize, and modify individual menu items' ) . '</li></ul>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   483
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   484
	get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   485
		'id'      => 'overview',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   486
		'title'   => __( 'Overview' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   487
		'content' => $overview
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   488
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   489
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   490
	$menu_management  = '<p>' . __( 'The menu management box at the top of the screen is used to control which menu is opened in the editor below.' ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   491
	$menu_management .= '<ul><li>' . __( 'To edit an existing menu, <strong>choose a menu from the drop down and click Select</strong>' ) . '</li>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   492
	$menu_management .= '<li>' . __( 'If you haven&#8217;t yet created any menus, <strong>click the &#8217;create a new menu&#8217; link</strong> to get started' ) . '</li></ul>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   493
	$menu_management .= '<p>' . __( 'You can assign theme locations to individual menus by <strong>selecting the desired settings</strong> at the bottom of the menu editor. To assign menus to all theme locations at once, <strong>visit the Manage Locations tab</strong> at the top of the screen.' ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   494
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   495
	get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   496
		'id'      => 'menu-management',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   497
		'title'   => __( 'Menu Management' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   498
		'content' => $menu_management
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   499
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   500
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   501
	$editing_menus  = '<p>' . __( 'Each custom menu may contain a mix of links to pages, categories, custom URLs or other content types. Menu links are added by selecting items from the expanding boxes in the left-hand column below.' ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   502
	$editing_menus .= '<p>' . __( '<strong>Clicking the arrow to the right of any menu item</strong> in the editor will reveal a standard group of settings. Additional settings such as link target, CSS classes, link relationships, and link descriptions can be enabled and disabled via the Screen Options tab.' ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   503
	$editing_menus .= '<ul><li>' . __( 'Add one or several items at once by <strong>selecting the checkbox next to each item and clicking Add to Menu</strong>' ) . '</li>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   504
	$editing_menus .= '<li>' . __( 'To add a custom link, <strong>expand the Links section, enter a URL and link text, and click Add to Menu</strong>' ) .'</li>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   505
	$editing_menus .= '<li>' . __( 'To reorganize menu items, <strong>drag and drop items with your mouse or use your keyboard</strong>. Drag or move a menu item a little to the right to make it a submenu' ) . '</li>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   506
	$editing_menus .= '<li>' . __( 'Delete a menu item by <strong>expanding it and clicking the Remove link</strong>' ) . '</li></ul>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   507
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   508
	get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   509
		'id'      => 'editing-menus',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   510
		'title'   => __( 'Editing Menus' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   511
		'content' => $editing_menus
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   512
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   513
else : // Locations Tab
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   514
	$locations_overview  = '<p>' . __( 'This screen is used for globally assigning menus to locations defined by your theme.' ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   515
	$locations_overview .= '<ul><li>' . __( 'To assign menus to one or more theme locations, <strong>select a menu from each location&#8217;s drop down.</strong> When you&#8217;re finished, <strong>click Save Changes</strong>' ) . '</li>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   516
	$locations_overview .= '<li>' . __( 'To edit a menu currently assigned to a theme location, <strong>click the adjacent &#8217;Edit&#8217; link</strong>' ) . '</li>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   517
	$locations_overview .= '<li>' . __( 'To add a new menu instead of assigning an existing one, <strong>click the &#8217;Use new menu&#8217; link</strong>. Your new menu will be automatically assigned to that theme location' ) . '</li></ul>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   518
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   519
	get_current_screen()->add_help_tab( array(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   520
		'id'      => 'locations-overview',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   521
		'title'   => __( 'Overview' ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   522
		'content' => $locations_overview
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   523
	) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   524
endif;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   525
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   526
get_current_screen()->set_help_sidebar(
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   527
	'<p><strong>' . __('For more information:') . '</strong></p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   528
	'<p>' . __('<a href="http://codex.wordpress.org/Appearance_Menus_Screen" target="_blank">Documentation on Menus</a>') . '</p>' .
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   529
	'<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   530
);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   531
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   532
// Get the admin header
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   533
require_once( ABSPATH . 'wp-admin/admin-header.php' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   534
?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   535
<div class="wrap">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   536
	<?php screen_icon(); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   537
	<h2 class="nav-tab-wrapper">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   538
		<a href="<?php echo admin_url( 'nav-menus.php' ); ?>" class="nav-tab<?php if ( ! isset( $_GET['action'] ) || isset( $_GET['action'] ) && 'locations' != $_GET['action'] ) echo ' nav-tab-active'; ?>"><?php esc_html_e( 'Edit Menus' ); ?></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   539
		<?php if ( $num_locations && $menu_count ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   540
			<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>" class="nav-tab<?php if ( $locations_screen ) echo ' nav-tab-active'; ?>"><?php esc_html_e( 'Manage Locations' ); ?></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   541
		<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   542
	</h2>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   543
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   544
	foreach( $messages as $message ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   545
		echo $message . "\n";
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   546
	endforeach;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   547
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   548
	<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   549
	if ( $locations_screen ) :
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   550
		echo '<p>' . sprintf( _n( 'Your theme supports %s menu. Select which menu you would like to use.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) ) . '</p>';
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   551
	?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   552
	<div id="menu-locations-wrap">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   553
		<form method="post" action="<?php echo esc_url( add_query_arg( array( 'action' => 'locations' ), admin_url( 'nav-menus.php' ) ) ); ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   554
			<table class="widefat fixed" cellspacing="0" id="menu-locations-table">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   555
				<thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   556
				<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   557
					<th scope="col" class="manage-column column-locations"><?php _e( 'Theme Location' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   558
					<th scope="col" class="manage-column column-menus"><?php _e( 'Assigned Menu' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   559
				</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   560
				</thead>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   561
				<!--<tfoot>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   562
				<tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   563
					<th scope="col" class="manage-column column-locations"><?php _e( 'Theme Location' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   564
					<th scope="col" class="manage-column column-menus"><?php _e( 'Assigned Menu' ); ?></th>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   565
				</tr>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   566
				</tfoot>-->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   567
				<tbody class="menu-locations">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   568
				<?php foreach ( $locations as $_location => $_name ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   569
					<tr id="menu-locations-row">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   570
						<td class="menu-location-title"><strong><?php echo $_name; ?></strong></td>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   571
						<td class="menu-location-menus">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   572
							<select name="menu-locations[<?php echo $_location; ?>]" id="locations-<?php echo $_location; ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   573
								<option value="0"><?php printf( '&mdash; %s &mdash;', esc_html__( 'Select a Menu' ) ); ?></option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   574
								<?php foreach ( $nav_menus as $menu ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   575
									<?php $selected = isset( $menu_locations[$_location] ) && $menu_locations[$_location] == $menu->term_id; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   576
									<option <?php if ( $selected ) echo 'data-orig="true"'; ?> <?php selected( $selected ); ?> value="<?php echo $menu->term_id; ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   577
										<?php echo wp_html_excerpt( $menu->name, 40, '&hellip;' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   578
									</option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   579
								<?php endforeach; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   580
							</select>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   581
							<div class="locations-row-links">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   582
								<?php if ( isset( $menu_locations[ $_location ] ) && 0 != $menu_locations[ $_location ] ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   583
								<span class="locations-edit-menu-link">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   584
									<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => $menu_locations[$_location] ), admin_url( 'nav-menus.php' ) ) ); ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   585
										<?php _ex( 'Edit', 'menu' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   586
									</a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   587
								</span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   588
								<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   589
								<span class="locations-add-menu-link">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   590
									<a href="<?php echo esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0, 'use-location' => $_location ), admin_url( 'nav-menus.php' ) ) ); ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   591
										<?php _ex( 'Use new menu', 'menu' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   592
									</a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   593
								</span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   594
							</div><!-- #locations-row-links -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   595
						</td><!-- .menu-location-menus -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   596
					</tr><!-- #menu-locations-row -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   597
				<?php } // foreach ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   598
				</tbody>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   599
			</table>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   600
			<p class="button-controls"><?php submit_button( __( 'Save Changes' ), 'primary left', 'nav-menu-locations', false ); ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   601
			<?php wp_nonce_field( 'save-menu-locations' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   602
			<input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   603
		</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   604
	</div><!-- #menu-locations-wrap -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   605
	<?php do_action( 'after_menu_locations_table' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   606
	<?php else : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   607
	<div class="manage-menus">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   608
 		<?php if ( $menu_count < 2 ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   609
		<span class="add-edit-menu-action">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   610
			<?php printf( __( 'Edit your menu below, or <a href="%s">create a new menu</a>.' ), esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0 ), admin_url( 'nav-menus.php' ) ) ) ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   611
		</span><!-- /add-edit-menu-action -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   612
		<?php else : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   613
			<form method="get" action="<?php echo admin_url( 'nav-menus.php' ); ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   614
			<input type="hidden" name="action" value="edit" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   615
			<label for="menu" class="selected-menu"><?php _e( 'Select a menu to edit:' ); ?></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   616
			<select name="menu" id="menu">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   617
				<?php if ( $add_new_screen ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   618
					<option value="0" selected="selected"><?php _e( '-- Select --' ); ?></option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   619
				<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   620
				<?php foreach( (array) $nav_menus as $_nav_menu ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   621
					<option value="<?php echo esc_attr( $_nav_menu->term_id ); ?>" <?php selected( $_nav_menu->term_id, $nav_menu_selected_id ); ?>>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   622
						<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   623
						echo esc_html( $_nav_menu->truncated_name ) ;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   624
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   625
						if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   626
							$locations_assigned_to_this_menu = array();
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   627
							foreach ( array_keys( $menu_locations, $_nav_menu->term_id ) as $menu_location_key ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   628
								 $locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   629
							}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   630
							$assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) ) );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   631
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   632
							// Adds ellipses following the number of locations defined in $assigned_locations
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   633
							printf( ' (%1$s%2$s)',
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   634
								implode( ', ', $assigned_locations ),
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   635
								count( $locations_assigned_to_this_menu ) > count( $assigned_locations ) ? ' &hellip;' : ''
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   636
							);
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   637
						}
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   638
						?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   639
					</option>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   640
				<?php endforeach; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   641
			</select>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   642
			<span class="submit-btn"><input type="submit" class="button-secondary" value="<?php _e( 'Select' ); ?>"></span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   643
			<span class="add-new-menu-action">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   644
				<?php printf( __( 'or <a href="%s">create a new menu</a>.' ), esc_url( add_query_arg( array( 'action' => 'edit', 'menu' => 0 ), admin_url( 'nav-menus.php' ) ) ) ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   645
			</span><!-- /add-new-menu-action -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   646
		</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   647
	<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   648
	</div><!-- /manage-menus -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   649
	<div id="nav-menus-frame">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   650
	<div id="menu-settings-column" class="metabox-holder<?php if ( isset( $_GET['menu'] ) && '0' == $_GET['menu'] ) { echo ' metabox-holder-disabled'; } ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   651
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   652
		<div class="clear"></div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   653
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   654
		<form id="nav-menu-meta" action="" class="nav-menu-meta" method="post" enctype="multipart/form-data">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   655
			<input type="hidden" name="menu" id="nav-menu-meta-object-id" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   656
			<input type="hidden" name="action" value="add-menu-item" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   657
			<?php wp_nonce_field( 'add-menu_item', 'menu-settings-column-nonce' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   658
			<?php do_accordion_sections( 'nav-menus', 'side', null ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   659
		</form>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   660
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   661
	</div><!-- /#menu-settings-column -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   662
	<div id="menu-management-liquid">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   663
		<div id="menu-management">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   664
			<form id="update-nav-menu" action="" method="post" enctype="multipart/form-data">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   665
				<div class="menu-edit <?php if ( $add_new_screen ) echo 'blank-slate'; ?>">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   666
					<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   667
					wp_nonce_field( 'closedpostboxes', 'closedpostboxesnonce', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   668
					wp_nonce_field( 'meta-box-order', 'meta-box-order-nonce', false );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   669
					wp_nonce_field( 'update-nav_menu', 'update-nav-menu-nonce' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   670
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   671
					if ( $one_theme_location_no_menus ) { ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   672
						<input type="hidden" name="zero-menu-state" value="true" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   673
					<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   674
 					<input type="hidden" name="action" value="update" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   675
					<input type="hidden" name="menu" id="menu" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   676
					<div id="nav-menu-header">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   677
						<div class="major-publishing-actions">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   678
							<label class="menu-name-label howto open-label" for="menu-name">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   679
								<span><?php _e( 'Menu Name' ); ?></span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   680
								<input name="menu-name" id="menu-name" type="text" class="menu-name regular-text menu-item-textbox input-with-default-title" title="<?php esc_attr_e( 'Enter menu name here' ); ?>" value="<?php if ( $one_theme_location_no_menus ) _e( 'Menu 1' ); else echo esc_attr( $nav_menu_selected_title ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   681
							</label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   682
							<div class="publishing-action">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   683
								<?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'button-primary menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   684
							</div><!-- END .publishing-action -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   685
						</div><!-- END .major-publishing-actions -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   686
					</div><!-- END .nav-menu-header -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   687
					<div id="post-body">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   688
						<div id="post-body-content">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   689
							<?php if ( ! $add_new_screen ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   690
							<h3><?php _e( 'Menu Structure' ); ?></h3>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   691
							<?php $starter_copy = ( $one_theme_location_no_menus ) ? __( 'Edit your default menu by adding or removing items. Drag each item into the order you prefer. Click Create Menu to save your changes.' ) : __( 'Drag each item into the order you prefer. Click the arrow on the right of the item to reveal additional configuration options.' ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   692
							<div class="drag-instructions post-body-plain" <?php if ( isset( $menu_items ) && 0 == count( $menu_items ) ) { ?>style="display: none;"<?php } ?>>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   693
								<p><?php echo $starter_copy; ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   694
							</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   695
							<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   696
							if ( isset( $edit_markup ) && ! is_wp_error( $edit_markup ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   697
								echo $edit_markup;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   698
							} else {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   699
							?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   700
							<ul class="menu" id="menu-to-edit"></ul>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   701
							<?php } ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   702
							<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   703
							<?php if ( $add_new_screen ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   704
								<p class="post-body-plain"><?php _e( 'Give your menu a name above, then click Create Menu.' ); ?></p>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   705
								<?php if ( isset( $_GET['use-location'] ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   706
									<input type="hidden" name="use-location" value="<?php echo esc_attr( $_GET['use-location'] ); ?>" />
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   707
								<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   708
							<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   709
							<div class="menu-settings" <?php if ( $one_theme_location_no_menus ) { ?>style="display: none;"<?php } ?>>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   710
								<h3><?php _e( 'Menu Settings' ); ?></h3>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   711
								<?php
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   712
								if ( ! isset( $auto_add ) ) {
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   713
									$auto_add = get_option( 'nav_menu_options' );
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   714
									if ( ! isset( $auto_add['auto_add'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   715
										$auto_add = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   716
									elseif ( false !== array_search( $nav_menu_selected_id, $auto_add['auto_add'] ) )
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   717
										$auto_add = true;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   718
									else
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   719
										$auto_add = false;
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   720
								} ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   721
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   722
								<dl class="auto-add-pages">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   723
									<dt class="howto"><?php _e( 'Auto add pages' ); ?></dt>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   724
									<dd class="checkbox-input"><input type="checkbox"<?php checked( $auto_add ); ?> name="auto-add-pages" id="auto-add-pages" value="1" /> <label for="auto-add-pages"><?php printf( __('Automatically add new top-level pages to this menu' ), esc_url( admin_url( 'edit.php?post_type=page' ) ) ); ?></label></dd>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   725
								</dl>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   726
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   727
								<?php if ( current_theme_supports( 'menus' ) ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   728
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   729
									<dl class="menu-theme-locations">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   730
										<dt class="howto"><?php _e( 'Theme locations' ); ?></dt>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   731
										<?php foreach ( $locations as $location => $description ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   732
										<dd class="checkbox-input">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   733
											<input type="checkbox"<?php checked( isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id ); ?> name="menu-locations[<?php echo esc_attr( $location ); ?>]" id="locations-<?php echo esc_attr( $location ); ?>" value="<?php echo esc_attr( $nav_menu_selected_id ); ?>" /> <label for="locations-<?php echo esc_attr( $location ); ?>"><?php echo $description; ?></label>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   734
											<?php if ( ! empty( $menu_locations[ $location ] ) && $menu_locations[ $location ] != $nav_menu_selected_id ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   735
											<span class="theme-location-set"> <?php printf( __( "(Currently set to: %s)" ), wp_get_nav_menu_object( $menu_locations[ $location ] )->name ); ?> </span>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   736
											<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   737
										</dd>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   738
										<?php endforeach; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   739
									</dl>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   740
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   741
								<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   742
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   743
							</div>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   744
						</div><!-- /#post-body-content -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   745
					</div><!-- /#post-body -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   746
					<div id="nav-menu-footer">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   747
						<div class="major-publishing-actions">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   748
							<?php if ( 0 != $menu_count && ! $add_new_screen ) : ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   749
							<span class="delete-action">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   750
								<a class="submitdelete deletion menu-delete" href="<?php echo esc_url( wp_nonce_url( add_query_arg( array( 'action' => 'delete', 'menu' => $nav_menu_selected_id, admin_url() ) ), 'delete-nav_menu-' . $nav_menu_selected_id) ); ?>"><?php _e('Delete Menu'); ?></a>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   751
							</span><!-- END .delete-action -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   752
							<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   753
							<div class="publishing-action">
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   754
								<?php submit_button( empty( $nav_menu_selected_id ) ? __( 'Create Menu' ) : __( 'Save Menu' ), 'button-primary menu-save', 'save_menu', false, array( 'id' => 'save_menu_header' ) ); ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   755
							</div><!-- END .publishing-action -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   756
						</div><!-- END .major-publishing-actions -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   757
					</div><!-- /#nav-menu-footer -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   758
				</div><!-- /.menu-edit -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   759
			</form><!-- /#update-nav-menu -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   760
		</div><!-- /#menu-management -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   761
	</div><!-- /#menu-management-liquid -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   762
	</div><!-- /#nav-menus-frame -->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   763
	<?php endif; ?>
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   764
</div><!-- /.wrap-->
d970ebf37754 first import
ymh <ymh.work@gmail.com>
parents:
diff changeset
   765
<?php include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>