WordPress.org

Make WordPress Core

Changeset 36852


Ignore:
Timestamp:
03/05/2016 12:46:45 AM (5 years ago)
Author:
ericlewis
Message:

Menus: Ensure theme location setting data is saved with a large menu.

[36510] introduced a fix to allow users to save large menus on the Edit Menu screen (70+ menu items). The form data is stored as JSON which is used to inject the $_POST variable in the form submission handler. This injection was not setting form items with named array elements properly (e.g. menu-locations[primary]), which did not save theme location data in a large form.

Props keraweb.
See #14134.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/nav-menus.php

    r36613 r36852  
    5252/*
    5353 * If a JSON blob of navigation menu data is found, expand it and inject it
    54  * into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134. 
     54 * into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134.
    5555 */
    5656if ( isset( $_POST['nav-menu-data'] ) ) {
     
    5959        foreach ( $data as $post_input_data ) {
    6060            // For input names that are arrays (e.g. `menu-item-db-id[3]`), derive the array path keys via regex.
    61             if ( preg_match( '#(.*)(?:\[(\d+)\])#', $post_input_data->name, $matches ) ) {
     61            if ( preg_match( '#(.*)\[(\w+)\]#', $post_input_data->name, $matches ) ) {
    6262                if ( empty( $_POST[ $matches[1] ] ) ) {
    6363                    $_POST[ $matches[1] ] = array();
    6464                }
    65                 $_POST[ $matches[1] ][ (int) $matches[2] ] = wp_slash( $post_input_data->value );
     65                // Cast input elements with a numeric array index to integers.
     66                if ( is_numeric( $matches[2] ) ) {
     67                    $matches[2] = (int) $matches[2];
     68                }
     69                $_POST[ $matches[1] ][ $matches[2] ] = wp_slash( $post_input_data->value );
    6670            } else {
    6771                $_POST[ $post_input_data->name ] = wp_slash( $post_input_data->value );
Note: See TracChangeset for help on using the changeset viewer.