Skip to content

Commit

Permalink
Switch to using CSS to avoid o2 script tags from affecting layout
Browse files Browse the repository at this point in the history
Hide empty p tags and remove margin from second to last element if there is an o2-data script tag.
  • Loading branch information
adamwoodnz committed Oct 23, 2024
1 parent dd135e7 commit 1833e3a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions mu-plugins/blocks/notice/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ function render_callout_as_notice( $attr, $content, $tag ) {

// Sanitize message content.
$content = wp_kses_post( $content );
// Temporarily disable o2 processing while formatting content.
add_filter( 'o2_process_the_content', '__return_false', 1 );
$content = apply_filters( 'the_content', $content );
remove_filter( 'o2_process_the_content', '__return_false', 1 );

// Create a unique placeholder for the content.
// Directly processing `$content` with `do_blocks` can lead to buggy layouts on make.wp.org.
Expand Down
11 changes: 10 additions & 1 deletion mu-plugins/blocks/notice/postcss/style.pcss
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,20 @@
align-self: start;
}

& p:empty {
display: none;
}

& p:first-child {
margin-block-start: 0;
}

& p:last-child {
/* o2 adds a data script tag to the notice content on some Make blogs.
* In this case we need to remove bottom margin from the second to last element instead.
*/

& p:last-child,
&:has(.o2-data) :nth-last-child(2) {
margin-block-end: 0;
}

Expand Down

0 comments on commit 1833e3a

Please sign in to comment.