Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wp_get_global_styles: for custom props, it should return the CSS format not the shortened internal one #49693

Closed
oandregal opened this issue Apr 10, 2023 · 2 comments · Fixed by #50366
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended

Comments

@oandregal
Copy link
Member

oandregal commented Apr 10, 2023

Related #45171

Description

The wp_get_global_styles functions returns an internal format for CSS Custom Properties instead of the proper CSS format.

Step-by-step reproduction instructions

  • Use a theme that has a theme.json.
  • Paste the following under styles.blocks:
"core/post-terms": {
    "typography": { "fontSize": "var(--wp--preset--font-size--small)" },
    "color":{ "background": "var:preset|color|secondary" }
}
  • Use the wp_get_global_styles functions to retrieve those styles. For example, paste the following in functions.php of the theme:
add_action( 'init', function(){
        error_log( print_r( wp_get_global_styles( array(), array('block_name'=>'core/post-terms') ), true ) );
} );

The result will be:

(
    [typography] => Array( [fontSize] => var(--wp--preset--font-size--small) )
    [color] => Array( [background] => var:preset|color|secondary )
)

when it should have been

(
    [typography] => Array( [fontSize] => var(--wp--preset--font-size--small) )
    [color] => Array( [background] => var(--wp--preset--color--secondary) )
)

Note the color.background value. It should return the value in a valid CSS value, not the shortened internal format.

@oandregal oandregal changed the title wp_get_global_styles returns internal format wp_get_global_styles: for custom props, it should return the CSS format not the shortened internal one Apr 10, 2023
@oandregal oandregal added [Type] Bug An existing feature does not function as intended Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels Apr 10, 2023
@oandregal
Copy link
Member Author

oandregal commented Apr 14, 2023

One option to fix this is by making the conversion part of WP_Theme_JSON::sanitize method, so any code dealing with the internal representation of a theme.json dataset only needs to be aware of one format (var(--wp--preset--font-size--small)).

oandregal pushed a commit that referenced this issue May 10, 2023
Co-authored-by: André <[email protected]>

This PR addresses #49693 so the return value for `wp_get_global_styles` given the following theme.json dataset

```
"core/post-terms": {
    "typography": { "fontSize": "var(--wp--preset--font-size--small)" },
    "color":{ "background": "var:preset|color|secondary" }
}
```

is:

```
(
    [typography] => Array( [fontSize] => var(--wp--preset--font-size--small) )
    [color] => Array( [background] => var(--wp--preset--color--secondary) )
)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant