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:
parent
02d60b4eb4
commit
2a334ede98
|
@ -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 ] ) ) {
|
||||
if ( is_array( $schema[ $key ] ) ) {
|
||||
if ( ! is_array( $value ) ) {
|
||||
unset( $tree[ $key ] );
|
||||
}
|
||||
} else {
|
||||
} 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ( is_array( $schema[ $key ] ) && ! is_array( $tree[ $key ] ) ) {
|
||||
} 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 ] );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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.
|
||||
*
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue