Skip to content

Commit

Permalink
Add some editor checks: only load if edit-site
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Feb 11, 2020
1 parent cac0947 commit a218643
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions lib/global-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ function gutenberg_experimental_global_styles_resolver( $global_styles ) {
return $css_rule;
}

/**
* Fetches the Global Styles for each level (core, theme, user)
* and enqueues the resulting CSS custom properties for the editor.
*/
function gutenberg_experimental_global_styles_enqueue_assets_editor() {
if ( gutenberg_experimental_global_styles_is_site_editor() ) {
gutenberg_experimental_global_styles_enqueue_assets();
}
}

/**
* Fetches the Global Styles for each level (core, theme, user)
* and enqueues the resulting CSS custom properties.
Expand Down Expand Up @@ -235,14 +245,14 @@ function gutenberg_experimental_global_styles_wp_gs_class_front_end( $classes )
* @return string The filtered string of body classes.
*/
function gutenberg_experimental_global_styles_wp_gs_class_editor( $classes ) {
if ( ! gutenberg_experimental_global_styles_has_theme_support() ) {
if (
! gutenberg_experimental_global_styles_has_theme_support() ||
! gutenberg_experimental_global_styles_is_site_editor()
) {
return $classes;
}

if ( gutenberg_experimental_global_styles_is_site_editor() ) {
return $classes . ' wp-gs';
}
return $classes;
return $classes . ' wp-gs';
}

/**
Expand All @@ -269,7 +279,10 @@ function gutenberg_experimental_global_styles_is_site_editor() {
* @return array New block editor settings
*/
function gutenberg_experimental_global_styles_settings( $settings ) {
if ( ! gutenberg_experimental_global_styles_has_theme_support() ) {
if (
! gutenberg_experimental_global_styles_has_theme_support() ||
! gutenberg_experimental_global_styles_is_site_editor()
) {
return $settings;
}

Expand Down Expand Up @@ -323,7 +336,7 @@ function gutenberg_experimental_global_styles_register_cpt() {
add_filter( 'body_class', 'gutenberg_experimental_global_styles_wp_gs_class_front_end' );
add_filter( 'admin_body_class', 'gutenberg_experimental_global_styles_wp_gs_class_editor' );
add_filter( 'block_editor_settings', 'gutenberg_experimental_global_styles_settings' );
// enqueue_block_assets is not fired in edit-site, so we use back/front hooks instead.
// enqueue_block_assets is not fired in edit-site, so we use separate back/front hooks instead.
add_action( 'wp_enqueue_scripts', 'gutenberg_experimental_global_styles_enqueue_assets' );
add_action( 'admin_enqueue_scripts', 'gutenberg_experimental_global_styles_enqueue_assets' );
add_action( 'admin_enqueue_scripts', 'gutenberg_experimental_global_styles_enqueue_assets_editor' );
}

0 comments on commit a218643

Please sign in to comment.