X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/0461a5f2e55c8d5f1fde96ca2e83117152573c7d..9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f:/wp-admin/nav-menus.php diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php index 77a4057a..0dd34cf9 100644 --- a/wp-admin/nav-menus.php +++ b/wp-admin/nav-menus.php @@ -53,7 +53,8 @@ switch ( $action ) { wp_save_nav_menu_items( $nav_menu_selected_id, $_REQUEST['menu-item'] ); break; case 'move-down-menu-item' : - // moving down a menu item is the same as moving up the next in order + + // Moving down a menu item is the same as moving up the next in order. check_admin_referer( 'move-menu_item' ); $menu_item_id = isset( $_REQUEST['menu-item'] ) ? (int) $_REQUEST['menu-item'] : 0; if ( is_nav_menu_item( $menu_item_id ) ) { @@ -63,7 +64,7 @@ switch ( $action ) { $ordered_menu_items = wp_get_nav_menu_items( $menu_id ); $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) ); - // set up the data we need in one pass through the array of menu items + // Set up the data we need in one pass through the array of menu items. $dbids_to_orders = array(); $orders_to_dbids = array(); foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) { @@ -75,14 +76,14 @@ switch ( $action ) { } } - // get next in order + // Get next in order. if ( isset( $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1] ) ) { $next_item_id = $orders_to_dbids[$dbids_to_orders[$menu_item_id] + 1]; $next_item_data = (array) wp_setup_nav_menu_item( get_post( $next_item_id ) ); - // if not siblings of same parent, bubble menu item up but keep order + // If not siblings of same parent, bubble menu item up but keep order. if ( ! empty( $menu_item_data['menu_item_parent'] ) && ( @@ -102,7 +103,7 @@ switch ( $action ) { } - // make menu item a child of its next sibling + // Make menu item a child of its next sibling. } else { $next_item_data['menu_order'] = $next_item_data['menu_order'] - 1; $menu_item_data['menu_order'] = $menu_item_data['menu_order'] + 1; @@ -114,7 +115,7 @@ switch ( $action ) { wp_update_post($next_item_data); } - // the item is last but still has a parent, so bubble up + // The item is last but still has a parent, so bubble up. } elseif ( ! empty( $menu_item_data['menu_item_parent'] ) && in_array( $menu_item_data['menu_item_parent'], $orders_to_dbids ) @@ -136,7 +137,7 @@ switch ( $action ) { $ordered_menu_items = wp_get_nav_menu_items( $menu_id ); $menu_item_data = (array) wp_setup_nav_menu_item( get_post( $menu_item_id ) ); - // set up the data we need in one pass through the array of menu items + // Set up the data we need in one pass through the array of menu items. $dbids_to_orders = array(); $orders_to_dbids = array(); foreach( (array) $ordered_menu_items as $ordered_menu_item_object ) { @@ -148,10 +149,10 @@ switch ( $action ) { } } - // if this menu item is not first + // If this menu item is not first. if ( ! empty( $dbids_to_orders[$menu_item_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) ) { - // if this menu item is a child of the previous + // If this menu item is a child of the previous. if ( ! empty( $menu_item_data['menu_item_parent'] ) && in_array( $menu_item_data['menu_item_parent'], array_keys( $dbids_to_orders ) ) && @@ -164,7 +165,10 @@ switch ( $action ) { if ( ! is_wp_error( $parent_object ) ) { $parent_data = (array) $parent_object; - // if there is something before the parent and parent a child of it, make menu item a child also of it + /* + * If there is something before the parent and parent a child of it, + * make menu item a child also of it. + */ if ( ! empty( $dbids_to_orders[$parent_db_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] ) && @@ -172,7 +176,10 @@ switch ( $action ) { ) { $menu_item_data['menu_item_parent'] = $parent_data['menu_item_parent']; - // else if there is something before parent and parent not a child of it, make menu item a child of that something's parent + /* + * Else if there is something before parent and parent not a child of it, + * make menu item a child of that something's parent + */ } elseif ( ! empty( $dbids_to_orders[$parent_db_id] ) && ! empty( $orders_to_dbids[$dbids_to_orders[$parent_db_id] - 1] ) @@ -183,24 +190,24 @@ switch ( $action ) { else $menu_item_data['menu_item_parent'] = 0; - // else there isn't something before the parent + // Else there isn't something before the parent. } else { $menu_item_data['menu_item_parent'] = 0; } - // set former parent's [menu_order] to that of menu-item's + // Set former parent's [menu_order] to that of menu-item's. $parent_data['menu_order'] = $parent_data['menu_order'] + 1; - // set menu-item's [menu_order] to that of former parent + // Set menu-item's [menu_order] to that of former parent. $menu_item_data['menu_order'] = $menu_item_data['menu_order'] - 1; - // save changes + // Save changes. update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); wp_update_post($menu_item_data); wp_update_post($parent_data); } - // else this menu item is not a child of the previous + // Else this menu item is not a child of the previous. } elseif ( empty( $menu_item_data['menu_order'] ) || empty( $menu_item_data['menu_item_parent'] ) || @@ -208,7 +215,7 @@ switch ( $action ) { empty( $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] ) || $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1] != $menu_item_data['menu_item_parent'] ) { - // just make it a child of the previous; keep the order + // Just make it a child of the previous; keep the order. $menu_item_data['menu_item_parent'] = (int) $orders_to_dbids[$dbids_to_orders[$menu_item_id] - 1]; update_post_meta( $menu_item_data['ID'], '_menu_item_menu_item_parent', (int) $menu_item_data['menu_item_parent'] ); wp_update_post($menu_item_data); @@ -232,7 +239,7 @@ switch ( $action ) { if ( is_nav_menu( $nav_menu_selected_id ) ) { $deletion = wp_delete_nav_menu( $nav_menu_selected_id ); } else { - // Reset the selected menu + // Reset the selected menu. $nav_menu_selected_id = 0; unset( $_REQUEST['menu'] ); } @@ -266,22 +273,22 @@ switch ( $action ) { case 'update': check_admin_referer( 'update-nav_menu', 'update-nav-menu-nonce' ); - // Remove menu locations that have been unchecked + // Remove menu locations that have been unchecked. foreach ( $locations as $location => $description ) { if ( ( empty( $_POST['menu-locations'] ) || empty( $_POST['menu-locations'][ $location ] ) ) && isset( $menu_locations[ $location ] ) && $menu_locations[ $location ] == $nav_menu_selected_id ) unset( $menu_locations[ $location ] ); } - // Merge new and existing menu locations if any new ones are set + // Merge new and existing menu locations if any new ones are set. if ( isset( $_POST['menu-locations'] ) ) { $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] ); $menu_locations = array_merge( $menu_locations, $new_menu_locations ); } - // Set menu locations + // Set menu locations. set_theme_mod( 'nav_menu_locations', $menu_locations ); - // Add Menu + // Add Menu. if ( 0 == $nav_menu_selected_id ) { $new_menu_title = trim( esc_html( $_POST['menu-name'] ) ); @@ -314,6 +321,7 @@ switch ( $action ) { $menu_locations[ $_REQUEST['use-location'] ] = $nav_menu_selected_id; set_theme_mod( 'nav_menu_locations', $menu_locations ); } + // $messages[] = '
' . sprintf( __( '%s has been created.' ), $nav_menu_selected_title ) . '
' . __( 'Please enter a valid menu name.' ) . '
' . __( 'This screen is used for globally assigning menus to locations defined by your theme.' ) . '
'; $locations_overview .= '' . __('Support Forums') . '
' ); -// Get the admin header +// Get the admin header. require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>