X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/61343b82c4f0da4c68e4c6373daafff4a81efdd1..9e77185fafaf4e60e2b73821e0e4b9b1a11fb85f:/wp-admin/nav-menus.php diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php index 549d03b5..0dd34cf9 100644 --- a/wp-admin/nav-menus.php +++ b/wp-admin/nav-menus.php @@ -10,7 +10,7 @@ */ /** Load WordPress Administration Bootstrap */ -require_once( './admin.php' ); +require_once( dirname( __FILE__ ) . '/admin.php' ); // Load all the nav menu interface functions require_once( ABSPATH . 'wp-admin/includes/nav-menu.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'] ) ); @@ -300,19 +307,21 @@ switch ( $action ) { // If there are menu items, add them wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ); // Auto-save nav_menu_locations - $locations = get_theme_mod( 'nav_menu_locations' ); - foreach ( (array) $locations as $location => $menu_id ) { + $locations = get_nav_menu_locations(); + foreach ( $locations as $location => $menu_id ) { $locations[ $location ] = $nav_menu_selected_id; break; // There should only be 1 } set_theme_mod( 'nav_menu_locations', $locations ); } if ( isset( $_REQUEST['use-location'] ) ) { - $locations = get_theme_mod( 'nav_menu_locations' ); - if ( isset( $locations[$_REQUEST['use-location']] ) ) - $locations[$_REQUEST['use-location']] = $nav_menu_selected_id; - set_theme_mod( 'nav_menu_locations', $locations ); + $locations = get_registered_nav_menus(); + $menu_locations = get_nav_menu_locations(); + if ( isset( $locations[ $_REQUEST['use-location'] ] ) ) + $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.' ) . '
' . sprintf( __( 'Your theme does not natively support menus, but you can use them in sidebars by adding a “Custom Menus” widget on the Widgets screen.' ), admin_url( 'widgets.php' ) ) . '
' . sprintf( __( 'Your theme does not natively support menus, but you can use them in sidebars by adding a “Custom Menu” widget on the Widgets screen.' ), admin_url( 'widgets.php' ) ) . '
' . __( 'This screen is used for managing your custom navigation menus.' ) . '
'; - $overview .= '' . sprintf( __( 'Menus can be displayed in locations defined by your theme, even used in sidebars by adding a “Custom Menus” widget on the Widgets 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' ) . '
'; + $overview .= '' . sprintf( __( 'Menus can be displayed in locations defined by your theme, even used in sidebars by adding a “Custom Menu” widget on the Widgets 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 Fourteen', 'Twenty Thirteen' ) . '
'; $overview .= '' . __( 'From this screen you can:' ) . '
'; $overview .= '' . __( '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.' ) . '
'; - $editing_menus .= '' . __( 'Clicking the title of any menu item 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.' ) . '
'; + $editing_menus .= '' . __( 'Clicking the arrow to the right of any menu item 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.' ) . '
'; $editing_menus .= '' . __( 'This screen is used for globally assigning menus to locations defined by your theme.' ) . '
'; $locations_overview .= '' . __('For more information:') . '
' . '' . __('Documentation on Menus') . '
' . - '' . __('Support Forums') . '
' + '' . __('Support Forums') . '
' ); -// Get the admin header -require_once( './admin-header.php' ); +// Get the admin header. +require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>' . 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 ) ) . '
'; ?>