Skip to content

Commit 850a565

Browse files
move generation of block style inheritance only when needed
1 parent e9d69d8 commit 850a565

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

src/init.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,6 @@ public function register_frontend_assets() {
130130
}
131131
}
132132

133-
// Register inline frontend styles for theme.json block style inheritance
134-
wp_register_style( 'ugb-block-style-inheritance-nodep', false );
135-
$block_style_inline_css = apply_filters( 'stackable_block_style_inheritance_inline_styles_nodep', '' );
136-
if ( ! empty( $block_style_inline_css ) ) {
137-
wp_add_inline_style( 'ugb-block-style-inheritance-nodep', $block_style_inline_css );
138-
}
139-
140133
// This is needed for the translation strings in our UI.
141134
if ( is_admin() ) {
142135
stackable_load_js_translations();
@@ -250,6 +243,16 @@ public function load_frontend_scripts_conditionally( $block_content, $block ) {
250243
return $block_content;
251244
}
252245

246+
// Register inline frontend styles for theme.json block style inheritance
247+
public function enqueue_inline_block_style_inheritance() {
248+
$block_style_inline_css = apply_filters( 'stackable_block_style_inheritance_inline_styles_nodep', '' );
249+
if ( ! empty( $block_style_inline_css ) ) {
250+
wp_register_style( 'ugb-block-style-inheritance-nodep', false );
251+
wp_add_inline_style( 'ugb-block-style-inheritance-nodep', $block_style_inline_css );
252+
wp_enqueue_style( 'ugb-block-style-inheritance-nodep' );
253+
}
254+
}
255+
253256
/**
254257
* Enqueue frontend scripts and styles.
255258
*
@@ -259,7 +262,7 @@ public function block_enqueue_frontend_assets() {
259262
$this->register_frontend_assets();
260263
wp_enqueue_style( 'ugb-style-css' );
261264
if ( is_frontend() ) {
262-
wp_enqueue_style( 'ugb-block-style-inheritance-nodep' );
265+
$this->enqueue_inline_block_style_inheritance();
263266
}
264267
wp_enqueue_style( 'ugb-style-css-nodep' );
265268
wp_enqueue_script( 'ugb-block-frontend-js' );
@@ -382,7 +385,7 @@ public function register_block_editor_assets() {
382385
// Ensure that block style inheritance styles comes after the editor block styles.
383386
function enqueue_style_in_editor() {
384387
wp_enqueue_style( 'ugb-block-editor-css' );
385-
wp_enqueue_style( 'ugb-block-style-inheritance-nodep' );
388+
$this->enqueue_inline_block_style_inheritance();
386389
}
387390

388391
/**

0 commit comments

Comments
 (0)