Skip to content

Commit

Permalink
Clean up logic to retrieve GS settings depending on context (#35437)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Oct 11, 2021
1 parent 4b1baf5 commit 4f3fb2b
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,11 @@ function gutenberg_experimental_global_styles_enqueue_assets() {
*/
function gutenberg_experimental_global_styles_settings( $settings ) {
// Set what is the context for this data request.
$context = 'all';
$context = 'other';
if (
is_callable( 'get_current_screen' ) &&
function_exists( 'gutenberg_is_edit_site_page' ) &&
gutenberg_is_edit_site_page( get_current_screen()->id ) &&
gutenberg_experimental_is_site_editor_available()
gutenberg_is_edit_site_page( get_current_screen()->id )
) {
$context = 'site-editor';
}
Expand All @@ -111,35 +110,26 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&
defined( 'REST_REQUEST' ) &&
REST_REQUEST &&
isset( $_GET['context'] ) &&
'mobile' === $_GET['context'] &&
WP_Theme_JSON_Resolver_Gutenberg::theme_has_support()
'mobile' === $_GET['context']
) {
$context = 'mobile';
}

$origin = 'theme';
if (
WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() &&
gutenberg_supports_block_templates()
) {
// Only lookup for the user data if we need it.
$origin = 'user';
}
$consolidated = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $settings, $origin );
$consolidated = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $settings );

if ( 'mobile' === $context ) {
if ( 'mobile' === $context && WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) {
$settings['__experimentalStyles'] = $consolidated->get_raw_data()['styles'];
}

if ( 'site-editor' === $context ) {
if ( 'site-editor' === $context && gutenberg_experimental_is_site_editor_available() ) {
$theme = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data( $settings, 'theme' );
$user_cpt_id = WP_Theme_JSON_Resolver_Gutenberg::get_user_custom_post_type_id();

$settings['__experimentalGlobalStylesUserEntityId'] = $user_cpt_id;
$settings['__experimentalGlobalStylesBaseStyles'] = $theme->get_raw_data();
}

if ( 'all' === $context ) {
if ( 'other' === $context ) {
$block_styles = array( 'css' => gutenberg_experimental_global_styles_get_stylesheet( $consolidated, 'block_styles' ) );
$css_variables = array(
'css' => gutenberg_experimental_global_styles_get_stylesheet( $consolidated, 'css_variables' ),
Expand Down

0 comments on commit 4f3fb2b

Please sign in to comment.