public function test_multidimensional_nested_array_should_expand_and_merge()
 {
     include_once ABSPATH . 'wp-admin/includes/nav-menu.php';
     if (empty($_POST)) {
         $_POST = array();
     }
     $data = array();
     $data[0] = new StdClass();
     $data[0]->name = 'would[1][do][the][trick]';
     $data[0]->value = 'yes';
     $data[1] = new StdClass();
     $data[1]->name = 'would[2][do][the][trick]';
     $data[1]->value = 'yes';
     $data[2] = new StdClass();
     $data[2]->name = 'would[2][do][the][job]';
     $data[2]->value = 'yes';
     $_POST['nav-menu-data'] = addslashes(json_encode($data));
     _wp_expand_nav_menu_post_data();
     $expected = array('nav-menu-data' => $_POST['nav-menu-data'], 'would' => array(1 => array('do' => array('the' => array('trick' => 'yes'))), 2 => array('do' => array('the' => array('trick' => 'yes', 'job' => 'yes')))));
     $this->assertEquals($expected, $_POST);
 }
예제 #2
0
$messages = array();
// Container that stores the name of the active menu
$nav_menu_selected_title = '';
// The menu id of the current menu being edited
$nav_menu_selected_id = isset($_REQUEST['menu']) ? (int) $_REQUEST['menu'] : 0;
// Get existing menu locations assignments
$locations = get_registered_nav_menus();
$menu_locations = get_nav_menu_locations();
$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');
        if (isset($_REQUEST['nav-menu-locations'])) {
            set_theme_mod('nav_menu_locations', array_map('absint', $_REQUEST['menu-locations']));
        } elseif (isset($_REQUEST['menu-item'])) {
            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.
        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)) {
            $menus = isset($_REQUEST['menu']) ? array((int) $_REQUEST['menu']) : wp_get_object_terms($menu_item_id, 'nav_menu', array('fields' => 'ids'));