WP_Theme_JSON::get_property_value() – Returns the style property for the given path.

You appear to be a bot. Output may be restricted

Description

Returns the style property for the given path.

It also converts CSS Custom Property stored as "var:preset|color|secondary" to the form "–wp–preset–color–secondary".

Usage

$string|array = WP_Theme_JSON::get_property_value( $styles, $path );

Parameters

$styles
( array ) required – Styles subtree.
$path
( array ) required – Which property to process.

Returns

string|array Style property value.

Source

File name: wordpress/wp-includes/class-wp-theme-json.php
Lines:

1 to 22 of 22
  protected static function get_property_value( $styles, $path ) {
    $value = _wp_array_get( $styles, $path, '' );

    if ( '' === $value || is_array( $value ) ) {
      return $value;
    }

    $prefix     = 'var:';
    $prefix_len = strlen( $prefix );
    $token_in   = '|';
    $token_out  = '--';
    if ( 0 === strncmp( $value, $prefix, $prefix_len ) ) {
      $unwrapped_name = str_replace(
        $token_in,
        $token_out,
        substr( $value, $prefix_len )
      );
      $value          = "var(--wp--$unwrapped_name)";
    }

    return $value;
  }
 

 View on GitHub View on Trac