wordpress-activitypub: Blocks: only load inline styles when the block is active

Quick summary

After installed, ActivityPub plugin adds a ton of inline CSS on header, in a style tag with the ID activitypub-followers-style-inline-css, even on sites that don’t use blocks (as in, use Classic Editor) or FSE.

Maybe there is a code to declare on functions.php to avoid this behavior? Tbh, it seems like a bug, since it shouldn’t load in sites without Gutenberg or FSE in the first place.

Bug first raised on issue #14.

Steps to reproduce

  1. Just activate and set the plugin up.
  2. Open the site and check its source code. On header, there will be several lines of inline CSS added with activitypub-followers-style-inline-css ID.

What you expected to happen

That inline code didn’t show up in sites that don’t use Gutenberg/Blocks or FSE.

What actually happened

CSS loads anyway, no matter the site’s configuration.

Impact

Some (< 50%)

Available workarounds?

No but the platform is still usable

Logs or notes

No response

About this issue

  • Original URL
  • State: open
  • Created 7 months ago
  • Comments: 18 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I think that the functions.php line that you are looking for is:

function remove_wp_block_library_css(){
  wp_dequeue_style( 'activitypub-followers-style' );
  wp_dequeue_style( 'activitypub-follow-me-style' );
} 
add_action( 'wp_print_styles', 'remove_wp_block_library_css', 100 );

Shoot, I thought that the Gutenberg styles would only load like that when the block was active, it appears not. Retitled the issue to indicate what needs fixing.

We’ll re-open this and see what we can find out

Ouch, false alarm, @mattwiebe. I forgot to activate ActivityPub back, and thought your filter fixed it. In fact, it didn’t, as you can see here.

Sorry about that.

@rghedin I’ve dug into this more and it seems like a simply unfortunate part of how WP Core manages block assets, not very well outside of Block Themes, it would seem.

If you wish to disable the ActivityPub blocks on your site entirely, and with it this problem, you can also add the following to your functions.php:

add_filter( 'activitypub_site_supports_blocks', '__return_false' );

Yeah it shouldn’t be loading that either, it’s a dependency of the block CSS, but if the block’s CSS isn’t loaded, it shouldn’t be either. This is going to be “fun” to fix 😄