Make WordPress Core


Ignore:
Timestamp:
06/22/2023 08:42:42 AM (3 years ago)
Author:
oandregal
Message:

wp_get_global_styles: allow transforming the CSS Custom Properties into the values they represent.

Props samnajian, ramonopoly, isabel_brison.
Fixes #58588.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/global-styles-and-settings.php

    r55983 r55986  
    9393 *
    9494 * @since 5.9.0
    95  * @since 6.3.0 the internal format "var:preset|color|secondary" is always resolved
    96  *              to the standard form "var(--wp--preset--font-size--small)".
     95 * @since 6.3.0 the internal link format "var:preset|color|secondary" is resolved
     96 *              to "var(--wp--preset--font-size--small)" so consumers don't have to.
     97 * @since 6.3.0 `transforms` is now usable in the `context` parameter. In case [`transforms`]['resolve_variables']
     98 *              is defined, variables are resolved to their value in the styles.
    9799 *
    98100 * @param array $path    Path to the specific style to retrieve. Optional.
     
    106108 *                              Valid values are 'all' (core, theme, and user) or 'base' (core and theme).
    107109 *                              If empty or unknown, 'all' is used.
     110 *     @type array $transforms Which transformation(s) to apply.
     111 *                              Valid value is array( 'resolve-variables' ).
     112 *                              If defined, variables are resolved to their value in the styles.
    108113 * }
    109114 * @return mixed The styles array or individual style value to retrieve.
     
    118123        $origin = 'theme';
    119124    }
    120     $styles = WP_Theme_JSON_Resolver::get_merged_data( $origin )->get_raw_data()['styles'];
    121 
     125
     126    $resolve_variables = isset( $context['transforms'] )
     127    && is_array( $context['transforms'] )
     128    && in_array( 'resolve-variables', $context['transforms'], true );
     129
     130    $merged_data = WP_Theme_JSON_Resolver::get_merged_data( $origin );
     131    if ( $resolve_variables ) {
     132        $merged_data = WP_Theme_JSON::resolve_variables( $merged_data );
     133    }
     134    $styles = $merged_data->get_raw_data()['styles'];
    122135    return _wp_array_get( $styles, $path, $styles );
    123136}
     137
    124138
    125139/**
Note: See TracChangeset for help on using the changeset viewer.