Make WordPress Core

Changeset 37748

Timestamp:
06/19/2016 12:24:23 PM (8 years ago)
Author:
swissspidy
Message:

Menus: Support nested array variables in POST data when saving menus.

[36510] allowed larger menus to be created in the Edit Menu screen by JSON-encoding the entire form into a single input field. However, it did not correctly handle nested arrays.

This introduces a new _wp_expand_nav_menu_post_data() helper function to handle this POST data which uses array_replace_recursive() internally. Since the latter is only available on PHP 5.3+, we add a compatibility function to ensure PHP 5.2 support.

Props ericlewis, neverything, swissspidy.
Fixes #36590 for trunk. See #14134.

Location:
trunk
Files:
2 added
3 edited

Legend:

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

    r37529 r37748  
    10601060    return $messages;
    10611061}
     1062
     1063
     1064
     1065
     1066
     1067
     1068
     1069
     1070
     1071
     1072
     1073
     1074
     1075
     1076
     1077
     1078
     1079
     1080
     1081
     1082
     1083
     1084
     1085
     1086
     1087
     1088
     1089
     1090
     1091
     1092
     1093
     1094
     1095
     1096
     1097
     1098
     1099
     1100
     1101
     1102
     1103
     1104
  • trunk/src/wp-admin/nav-menus.php

    r37488 r37748  
    5454 * into `$_POST` to avoid PHP `max_input_vars` limitations. See #14134.
    5555 */
    56 if ( isset( $_POST['nav-menu-data'] ) ) {
    57     $data = json_decode( stripslashes( $_POST['nav-menu-data'] ) );
    58     if ( ! is_null( $data ) && $data ) {
    59         foreach ( $data as $post_input_data ) {
    60             // For input names that are arrays (e.g. `menu-item-db-id[3]`), derive the array path keys via regex.
    61             if ( preg_match( '#(.*)\[(\w+)\]#', $post_input_data->name, $matches ) ) {
    62                 if ( empty( $_POST[ $matches[1] ] ) ) {
    63                     $_POST[ $matches[1] ] = array();
    64                 }
    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 );
    70             } else {
    71                 $_POST[ $post_input_data->name ] = wp_slash( $post_input_data->value );
    72             }
    73         }
    74     }
    75 }
     56_wp_expand_nav_menu_post_data();
     57
    7658switch ( $action ) {
    7759    case 'add-menu-item':
  • trunk/src/wp-includes/compat.php

    r37674 r37748  
    436436}
    437437
     438
     439
     440
     441
     442
     443
     444
     445
     446
     447
     448
     449
     450
     451
     452
     453
     454
     455
     456
     457
     458
     459
     460
     461
     462
     463
     464
     465
     466
     467
     468
     469
     470
     471
     472
     473
     474
     475
     476
     477
     478
     479
     480
     481
     482
     483
     484
     485
     486
     487
    438488// SPL can be disabled on PHP 5.2
    439489if ( ! function_exists( 'spl_autoload_register' ) ):
Note: See TracChangeset for help on using the changeset viewer.