Make WordPress Core

#56812 closed defect (bug) (invalid)

`wp_get_global_settings` returns default color.palette.theme colors with style variation applied in Version 6.1-RC1-54506

Reported by: dufresnesteven's profile dufresnesteven Owned by:
Milestone: 6.1 Priority: normal
Severity: normal Version: 6.1
Component: Editor Keywords:
Focuses: Cc:

Description

On wp.org, we are launching a feature that allows us to show style variations for themes. We built the style variation card (similar to the <StylePreview /> in the site editor) by retrieving the global styles palette via:

$global_settings = wp_get_global_settings();
$palette         = $global_settings['color']['palette']['theme'];

Up to and including Version 6.1-beta3-54468 the theme array was returning the applied style variations styles (if a style variation was applied).

In Version 6.1-RC1-54506 the theme array contains the default colors regardless of whether a style variation is applied.

Now the enviroment in which this is running in is somewhat unique (wp-themes.com), but the fact that the change happened between beta3 and RC1 makes this feel unintentional.

Does anyone have any leads as to why this could be the case? Additionally, if there is a better way to retrieve that information, I am more than happy to make the change.

Thanks.

Example of the style variation cards:
https://wordpress.org/themes/twentytwentytwo/?beta=style_variations

Attachments (2)

Screen Shot 2022-10-13 at 8.53.05 AM.png (72.5 KB) - added by dufresnesteven 21 months ago.
beta3
Screen Shot 2022-10-13 at 8.53.21 AM.png (26.6 KB) - added by dufresnesteven 21 months ago.
rc1

Download all attachments as: .zip

Change History (8)

#1 @dufresnesteven
21 months ago

More information:

  1. We apply the style variation using the theme_json_user filter. Something that looks like:
 function filter_theme_json_user() {

    $variations = \WP_Theme_JSON_Resolver::get_style_variations();

    $variation_details = someFunctionThatReturnsOneVariation()

    $new_data = array();

    if ( ! empty( $variation_details['settings'] ) ) {
    	$new_data['settings'] = $variation_details['settings'];
    }

    if ( ! empty( $variation_details['styles'] ) ) {
    	$new_data['styles'] = $variation_details['styles'];
    }

    return $theme_json->update_with( $new_data );
}

add_filter( 'theme_json_user', __NAMESPACE__ . '\filter_theme_json_user' );

When you load any default theme page, the styles are applied as expected. However, we use template_redirect to inject our own page:

function redirect_to_style_page() {
	...some criteria

	include dirname( __DIR__ ) . '/views/our-template.php';
	die;

}

add_action( 'template_redirect', __NAMESPACE__ . '\redirect_to_style_page' );

This used to work, accessing wp_get_global_settings in our template would return the settings with style variations applied. In addition, the style variation would also change the background and add the appropriate fonts, etc... It no longer does so... hmmm.

Last edited 21 months ago by dufresnesteven (previous) (diff)

#2 @audrasjb
21 months ago

  • Component changed from General to Editor
  • Milestone changed from Awaiting Review to 6.1
  • Version set to trunk

Hello and thank you for the detailed report!

Moving for 6.1 consideration.

#3 @kebbet
21 months ago

The filter was renamed in [54501]. Have you updated your code to reflect that?

This ticket was mentioned in Slack in #core by audrasjb. View the logs.


21 months ago

#5 @dufresnesteven
21 months ago

Nope, haven't. Fixed.

Noting the filter still exists on Gutenberg's side and is being called when the plugin is activated:
https://github.com/WordPress/gutenberg/blob/trunk/lib/compat/wordpress-6.1/class-wp-theme-json-resolver-6-1.php

I'm unsure how that is to be managed, but feel free to close this ticket since it's now working for me.

Thanks.

#6 @Bernhard Reiter
21 months ago

  • Resolution set to invalid
  • Status changed from new to closed

To close the loop, Gutenberg has now been updated to use the new names: https://github.com/WordPress/gutenberg/pull/44940

Note: See TracTickets for help on using tickets.