Skip to content

Commit

Permalink
Substitute get_from_path by gutenberg_experimental_get
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Nov 12, 2020
1 parent 36d582d commit aee8a21
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions lib/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ public static function get_blocks_metadata() {

$block_supports = array();
foreach ( self::PROPERTIES_METADATA as $key => $metadata ) {
if ( self::get_from_path( $block_type->supports, $metadata['block_json'] ) ) {
if ( gutenberg_experimental_get( $block_type->supports, $metadata['block_json'] ) ) {
$block_supports[] = $key;
}
}
Expand Down Expand Up @@ -581,30 +581,6 @@ private static function flatten_tree( $tree, $prefix = '', $token = '--' ) {
return $result;
}

/**
* Utility to extract a path from an array.
*
* @param array $array Array we want to retrieve data from.
* @param array $path Array containing the path to retrieve.
* @param array $default Value to return if $array doesn't contain the $path.
*
* @return array Data at the given $path or $default.
*/
private static function get_from_path( $array, $path, $default = array() ) {
if ( ! is_array( $array ) || ! is_array( $path ) ) {
return $default;
}

$path_length = count( $path );
for ( $i = 0; $i < $path_length; ++$i ) {
if ( ! isset( $array[ $path[ $i ] ] ) ) {
return $default;
}
$array = $array[ $path[ $i ] ];
}
return $array;
}

/**
* Returns the style property for the given path.
*
Expand All @@ -618,7 +594,7 @@ private static function get_from_path( $array, $path, $default = array() ) {
* @return string Style property value.
*/
private static function get_property_value( $styles, $path ) {
$value = self::get_from_path( $styles, $path, '' );
$value = gutenberg_experimental_get( $styles, $path, '' );

if ( '' === $value ) {
return $value;
Expand Down Expand Up @@ -700,7 +676,7 @@ private static function compute_preset_classes( &$stylesheet, $context ) {
}

foreach ( self::PRESETS_METADATA as $preset ) {
$values = self::get_from_path( $context, $preset['path'], array() );
$values = gutenberg_experimental_get( $context, $preset['path'], array() );
foreach ( $values as $value ) {
foreach ( $preset['classes'] as $class ) {
$stylesheet .= self::to_ruleset(
Expand Down Expand Up @@ -736,7 +712,7 @@ private static function compute_preset_classes( &$stylesheet, $context ) {
*/
private static function compute_preset_vars( &$declarations, $context ) {
foreach ( self::PRESETS_METADATA as $preset ) {
$values = self::get_from_path( $context, $preset['path'], array() );
$values = gutenberg_experimental_get( $context, $preset['path'], array() );
foreach ( $values as $value ) {
$declarations[] = array(
'name' => '--wp--preset--' . $preset['css_var_infix'] . '--' . $value['slug'],
Expand Down Expand Up @@ -764,7 +740,7 @@ private static function compute_preset_vars( &$declarations, $context ) {
* @param array $context Input context to process.
*/
private static function compute_theme_vars( &$declarations, $context ) {
$custom_values = self::get_from_path( $context, array( 'settings', 'custom' ) );
$custom_values = gutenberg_experimental_get( $context, array( 'settings', 'custom' ) );
$css_vars = self::flatten_tree( $custom_values );
foreach ( $css_vars as $key => $value ) {
$declarations[] = array(
Expand Down

0 comments on commit aee8a21

Please sign in to comment.