Skip to content

Commit d1fafd8

Browse files
committed
Editor: Simplify sanitization code path in WP_Theme_JSON after [57496]
Removes the custom `WP_Theme_JSON::is_assoc()` method again in favor of the existing `wp_is_numeric_array()` helper function. Props mmaattiiaass, costdev, swissspidy, spacedmonkey. Fixes #60360. git-svn-id: https://develop.svn.wordpress.org/trunk@57751 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 919b833 commit d1fafd8

File tree

1 file changed

+11
-30
lines changed

1 file changed

+11
-30
lines changed

src/wp-includes/class-wp-theme-json.php

Lines changed: 11 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,19 +1065,10 @@ protected static function remove_keys_not_in_schema( $tree, $schema ) {
10651065
continue;
10661066
}
10671067

1068-
// Check if the value is an array and requires further processing.
1069-
if ( is_array( $value ) && is_array( $schema[ $key ] ) ) {
1070-
// Determine if it is an associative or indexed array.
1071-
$schema_is_assoc = self::is_assoc( $value );
1072-
1073-
if ( $schema_is_assoc ) {
1074-
// If associative, process as a single object.
1075-
$tree[ $key ] = self::remove_keys_not_in_schema( $value, $schema[ $key ] );
1076-
1077-
if ( empty( $tree[ $key ] ) ) {
1078-
unset( $tree[ $key ] );
1079-
}
1080-
} else {
1068+
if ( is_array( $schema[ $key ] ) ) {
1069+
if ( ! is_array( $value ) ) {
1070+
unset( $tree[ $key ] );
1071+
} elseif ( wp_is_numeric_array( $value ) ) {
10811072
// If indexed, process each item in the array.
10821073
foreach ( $value as $item_key => $item_value ) {
10831074
if ( isset( $schema[ $key ][0] ) && is_array( $schema[ $key ][0] ) ) {
@@ -1087,29 +1078,19 @@ protected static function remove_keys_not_in_schema( $tree, $schema ) {
10871078
$tree[ $key ][ $item_key ] = $item_value;
10881079
}
10891080
}
1081+
} else {
1082+
// If associative, process as a single object.
1083+
$tree[ $key ] = self::remove_keys_not_in_schema( $value, $schema[ $key ] );
1084+
1085+
if ( empty( $tree[ $key ] ) ) {
1086+
unset( $tree[ $key ] );
1087+
}
10901088
}
1091-
} elseif ( is_array( $schema[ $key ] ) && ! is_array( $tree[ $key ] ) ) {
1092-
unset( $tree[ $key ] );
10931089
}
10941090
}
1095-
10961091
return $tree;
10971092
}
10981093

1099-
/**
1100-
* Checks if the given array is associative.
1101-
*
1102-
* @since 6.5.0
1103-
* @param array $data The array to check.
1104-
* @return bool True if the array is associative, false otherwise.
1105-
*/
1106-
protected static function is_assoc( $data ) {
1107-
if ( array() === $data ) {
1108-
return false;
1109-
}
1110-
return array_keys( $data ) !== range( 0, count( $data ) - 1 );
1111-
}
1112-
11131094
/**
11141095
* Returns the existing settings for each block.
11151096
*

0 commit comments

Comments
 (0)