Skip to content

Commit d867a53

Browse files
fix: tweak inline gate styles for block theme (#4445)
1 parent 6e3c3f5 commit d867a53

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

includes/content-gate/trait-content-gate-layout.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,16 @@ protected static function enqueue_block_editor_layout_assets( $post_type ) {
149149
wp_enqueue_style( 'newspack-content-gate', Newspack::plugin_url() . '/dist/content-gate-editor.css', [], $asset['version'] );
150150
}
151151

152+
/**
153+
* Check if the current theme is a block theme.
154+
*
155+
* @return boolean True if the current theme is a block theme.
156+
*/
157+
private static function is_block_theme() {
158+
return function_exists( 'wp_is_block_theme' ) && wp_is_block_theme();
159+
}
160+
161+
152162
/**
153163
* Get the number of visible paragraphs for the gate.
154164
*
@@ -205,11 +215,17 @@ public static function get_inline_gate_content_for_post( $gate_layout_id ) {
205215

206216
// Apply inline fade.
207217
if ( $visible_paragraphs > 0 && $inline_fade ) {
208-
$gate_content = '<div style="pointer-events: none; height: 10em; margin-top: -10em; width: 100%; position: absolute; background: linear-gradient(180deg, rgba(255,255,255,0) 14%, rgba(255,255,255,1) 76%);"></div>' . $gate_content;
218+
$gate_content = '<div style="pointer-events: none; height: 10em; margin-top: -10em; width: 100%; position: absolute; background: linear-gradient(180deg, rgba(255,255,255,0) 14%, rgba(255,255,255,1) 76%); max-width: 100%;"></div>' . $gate_content;
219+
}
220+
221+
$gate_content_classes = [ 'newspack-content-gate__gate', 'newspack-content-gate__inline-gate' ];
222+
// Add a class if the current theme is a block theme.
223+
if ( self::is_block_theme() ) {
224+
$gate_content_classes[] = 'is-layout-constrained';
209225
}
210226

211227
// Wrap gate in a div for styling.
212-
$gate_content = '<div class="newspack-content-gate__gate newspack-content-gate__inline-gate">' . $gate_content . '</div>';
228+
$gate_content = '<div class="' . esc_attr( implode( ' ', $gate_content_classes ) ) . '">' . $gate_content . '</div>';
213229
return $gate_content;
214230
}
215231

src/content-gate/gate.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@
8686
width: 100%;
8787
overflow: clip;
8888
}
89+
&__inline-gate {
90+
max-width: 100%;
91+
}
8992
&__inline-fade {
9093
position: absolute;
9194
bottom: 0;

0 commit comments

Comments
 (0)