X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/61343b82c4f0da4c68e4c6373daafff4a81efdd1..b22765f41bf0b2021b9beb9120ee0ac91fa89292:/wp-admin/nav-menus.php diff --git a/wp-admin/nav-menus.php b/wp-admin/nav-menus.php index 549d03b5..72de2a92 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' ); @@ -19,8 +19,13 @@ if ( ! current_theme_supports( 'menus' ) && ! current_theme_supports( 'widgets' wp_die( __( 'Your theme does not support navigation menus or widgets.' ) ); // Permissions Check -if ( ! current_user_can('edit_theme_options') ) - wp_die( __( 'Cheatin’ uh?' ) ); +if ( ! current_user_can( 'edit_theme_options' ) ) { + wp_die( + '
' . __( 'Sorry, you are not allowed to edit theme options on this site.' ) . '
', + 403 + ); +} wp_enqueue_script( 'nav-menu' ); @@ -44,6 +49,12 @@ $num_locations = count( array_keys( $locations ) ); // Allowed actions: add, update, delete $action = isset( $_REQUEST['action'] ) ? $_REQUEST['action'] : 'edit'; +/* + * If a JSON blob of navigation menu data is found, expand it and inject it + * into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134. + */ +_wp_expand_nav_menu_post_data(); + switch ( $action ) { case 'add-menu-item': check_admin_referer( 'add-menu_item', 'menu-settings-column-nonce' ); @@ -53,7 +64,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,10 +75,10 @@ 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 ) { + foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) { if ( isset( $ordered_menu_item_object->ID ) ) { if ( isset( $ordered_menu_item_object->menu_order ) ) { $dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order; @@ -75,14 +87,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 +114,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 +126,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,10 +148,10 @@ 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 ) { + foreach ( (array) $ordered_menu_items as $ordered_menu_item_object ) { if ( isset( $ordered_menu_item_object->ID ) ) { if ( isset( $ordered_menu_item_object->menu_order ) ) { $dbids_to_orders[$ordered_menu_item_object->ID] = $ordered_menu_item_object->menu_order; @@ -148,10 +160,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 +176,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 +187,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 +201,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 +226,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); @@ -224,7 +242,7 @@ switch ( $action ) { check_admin_referer( 'delete-menu_item_' . $menu_item_id ); if ( is_nav_menu_item( $menu_item_id ) && wp_delete_post( $menu_item_id, true ) ) - $messages[] = '' . __('The menu item has been successfully deleted.') . '
' . __('The menu item has been successfully deleted.') . '
' . $deletion->get_error_message() . '
' . $deletion->get_error_message() . '
' . __( 'The menu has been successfully deleted.' ) . '
' . __( 'The menu has been successfully deleted.' ) . '
' . $deletion->get_error_message() . '
' . $deletion->get_error_message() . '
' . __( 'Selected menus have been successfully deleted.' ) . '
' . __( 'Selected menus have been successfully deleted.' ) . '
' . $_nav_menu_selected_id->get_error_message() . '
' . $_nav_menu_selected_id->get_error_message() . '
' . sprintf( __( '%s has been created.' ), $nav_menu_selected_title ) . '
' . __( 'Please enter a valid menu name.' ) . '
' . __( 'Please enter a valid menu name.' ) . '
' . __( 'Please enter a valid menu name.' ) . '
' . __( 'Please enter a valid menu name.' ) . '
' . $_nav_menu_selected_id->get_error_message() . '
' . $_nav_menu_selected_id->get_error_message() . '
' . __( 'Menu locations updated.' ) . '
' . __( 'Menu locations updated.' ) . '
' . 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 Fifteen', 'Twenty Fourteen' ) . '
'; $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') . '
' + '' . __('Documentation on Menus') . '
' . + '' . __('Support Forums') . '
' ); -// Get the admin header -require_once( './admin-header.php' ); +// Get the admin header. +require_once( ABSPATH . 'wp-admin/admin-header.php' ); ?>' . __( 'Your theme supports one menu. Select which menu you would like to use.' ) . '
'; + } else { + echo '' . sprintf( _n( 'Your theme supports %s menu. Select which menu appears in each location.', 'Your theme supports %s menus. Select which menu appears in each location.', $num_locations ), number_format_i18n( $num_locations ) ) . '
'; + } ?>