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.
Built from https://develop.svn.wordpress.org/trunk@57751


git-svn-id: http://core.svn.wordpress.org/trunk@57252 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Pascal Birchler 2024-03-02 13:41:05 +00:00
parent 02d60b4eb4
commit 2a334ede98
2 changed files with 12 additions and 31 deletions

View File

@ -1065,19 +1065,10 @@ class WP_Theme_JSON {
continue;
}
// Check if the value is an array and requires further processing.
if ( is_array( $value ) && is_array( $schema[ $key ] ) ) {
// Determine if it is an associative or indexed array.
$schema_is_assoc = self::is_assoc( $value );
if ( $schema_is_assoc ) {
// If associative, process as a single object.
$tree[ $key ] = self::remove_keys_not_in_schema( $value, $schema[ $key ] );
if ( empty( $tree[ $key ] ) ) {
unset( $tree[ $key ] );
}
} else {
if ( is_array( $schema[ $key ] ) ) {
if ( ! is_array( $value ) ) {
unset( $tree[ $key ] );
} elseif ( wp_is_numeric_array( $value ) ) {
// If indexed, process each item in the array.
foreach ( $value as $item_key => $item_value ) {
if ( isset( $schema[ $key ][0] ) && is_array( $schema[ $key ][0] ) ) {
@ -1087,29 +1078,19 @@ class WP_Theme_JSON {
$tree[ $key ][ $item_key ] = $item_value;
}
}
} else {
// If associative, process as a single object.
$tree[ $key ] = self::remove_keys_not_in_schema( $value, $schema[ $key ] );
if ( empty( $tree[ $key ] ) ) {
unset( $tree[ $key ] );
}
}
} elseif ( is_array( $schema[ $key ] ) && ! is_array( $tree[ $key ] ) ) {
unset( $tree[ $key ] );
}
}
return $tree;
}
/**
* Checks if the given array is associative.
*
* @since 6.5.0
* @param array $data The array to check.
* @return bool True if the array is associative, false otherwise.
*/
protected static function is_assoc( $data ) {
if ( array() === $data ) {
return false;
}
return array_keys( $data ) !== range( 0, count( $data ) - 1 );
}
/**
* Returns the existing settings for each block.
*

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.5-beta3-57750';
$wp_version = '6.5-beta3-57751';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.