Skip to content

Commit aee8a21

Browse files
committed
Substitute get_from_path by gutenberg_experimental_get
1 parent 36d582d commit aee8a21

File tree

1 file changed

+5
-29
lines changed

1 file changed

+5
-29
lines changed

lib/class-wp-theme-json.php

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ public static function get_blocks_metadata() {
415415

416416
$block_supports = array();
417417
foreach ( self::PROPERTIES_METADATA as $key => $metadata ) {
418-
if ( self::get_from_path( $block_type->supports, $metadata['block_json'] ) ) {
418+
if ( gutenberg_experimental_get( $block_type->supports, $metadata['block_json'] ) ) {
419419
$block_supports[] = $key;
420420
}
421421
}
@@ -581,30 +581,6 @@ private static function flatten_tree( $tree, $prefix = '', $token = '--' ) {
581581
return $result;
582582
}
583583

584-
/**
585-
* Utility to extract a path from an array.
586-
*
587-
* @param array $array Array we want to retrieve data from.
588-
* @param array $path Array containing the path to retrieve.
589-
* @param array $default Value to return if $array doesn't contain the $path.
590-
*
591-
* @return array Data at the given $path or $default.
592-
*/
593-
private static function get_from_path( $array, $path, $default = array() ) {
594-
if ( ! is_array( $array ) || ! is_array( $path ) ) {
595-
return $default;
596-
}
597-
598-
$path_length = count( $path );
599-
for ( $i = 0; $i < $path_length; ++$i ) {
600-
if ( ! isset( $array[ $path[ $i ] ] ) ) {
601-
return $default;
602-
}
603-
$array = $array[ $path[ $i ] ];
604-
}
605-
return $array;
606-
}
607-
608584
/**
609585
* Returns the style property for the given path.
610586
*
@@ -618,7 +594,7 @@ private static function get_from_path( $array, $path, $default = array() ) {
618594
* @return string Style property value.
619595
*/
620596
private static function get_property_value( $styles, $path ) {
621-
$value = self::get_from_path( $styles, $path, '' );
597+
$value = gutenberg_experimental_get( $styles, $path, '' );
622598

623599
if ( '' === $value ) {
624600
return $value;
@@ -700,7 +676,7 @@ private static function compute_preset_classes( &$stylesheet, $context ) {
700676
}
701677

702678
foreach ( self::PRESETS_METADATA as $preset ) {
703-
$values = self::get_from_path( $context, $preset['path'], array() );
679+
$values = gutenberg_experimental_get( $context, $preset['path'], array() );
704680
foreach ( $values as $value ) {
705681
foreach ( $preset['classes'] as $class ) {
706682
$stylesheet .= self::to_ruleset(
@@ -736,7 +712,7 @@ private static function compute_preset_classes( &$stylesheet, $context ) {
736712
*/
737713
private static function compute_preset_vars( &$declarations, $context ) {
738714
foreach ( self::PRESETS_METADATA as $preset ) {
739-
$values = self::get_from_path( $context, $preset['path'], array() );
715+
$values = gutenberg_experimental_get( $context, $preset['path'], array() );
740716
foreach ( $values as $value ) {
741717
$declarations[] = array(
742718
'name' => '--wp--preset--' . $preset['css_var_infix'] . '--' . $value['slug'],
@@ -764,7 +740,7 @@ private static function compute_preset_vars( &$declarations, $context ) {
764740
* @param array $context Input context to process.
765741
*/
766742
private static function compute_theme_vars( &$declarations, $context ) {
767-
$custom_values = self::get_from_path( $context, array( 'settings', 'custom' ) );
743+
$custom_values = gutenberg_experimental_get( $context, array( 'settings', 'custom' ) );
768744
$css_vars = self::flatten_tree( $custom_values );
769745
foreach ( $css_vars as $key => $value ) {
770746
$declarations[] = array(

0 commit comments

Comments
 (0)