Skip to content

Add per-block Fediverse visibility toggle#3055

Open
pfefferle wants to merge 4 commits intotrunkfrom
add/block-visibility-fediverse-toggle
Open

Add per-block Fediverse visibility toggle#3055
pfefferle wants to merge 4 commits intotrunkfrom
add/block-visibility-fediverse-toggle

Conversation

@pfefferle
Copy link
Member

@pfefferle pfefferle commented Mar 18, 2026

Fixes #2076

Prepares for Block Visibility in WordPress 7.0.

Proposed changes:

  • Add a "Fediverse ⁂" panel to the block inspector sidebar with a "Share to the Fediverse" toggle for every block
  • When disabled, the block is excluded from federated content but remains visible on the site
  • Store the setting in metadata.blockVisibility.fediverse — piggybacks on the new WordPress 7.0 block visibility metadata structure
  • Filter hidden blocks during ActivityPub content rendering via render_block filter (only active during AP content generation)
  • Also exclude hidden blocks from reply URL extraction and media attachment extraction
  • Disable core block visibility (viewport hiding) on the Federated Reply block since it is semantic

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Install and activate the latest Gutenberg plugin (22.7+)
  • Create or edit a post with multiple blocks (paragraphs, images, etc.)
  • Select any block and open the "Fediverse ⁂" panel in the block inspector sidebar
  • Toggle "Share to the Fediverse" off for one or more blocks
  • Save/publish the post
  • Open the Fediverse preview — the hidden blocks should not appear
  • Verify hidden blocks still appear normally on the site's frontend
  • Test with image blocks: hidden images should not appear as ActivityPub attachments
  • Test with the Federated Reply block: verify the viewport visibility controls (Show/Hide) do not appear in the block toolbar

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Add per-block Fediverse visibility toggle to control which blocks are shared to Mastodon and other Fediverse platforms.

Adds a "Fediverse ⁂" panel to the block inspector sidebar for all
blocks with a "Share to the Fediverse" toggle. When disabled, the
block is excluded from federated content but remains visible on
the site.

- JS: editor.BlockEdit filter adds InspectorControls toggle that
  saves metadata.blockVisibility.fediverse in block markup
- PHP: render_block filter strips hidden blocks during AP content
  generation; also filters get_in_reply_to() and media extraction
- Disables core block visibility (viewport hiding) on the reply
  block since it is semantic and should not be conditionally hidden

Prepares for WordPress 7.0 block visibility feature.
Copilot AI review requested due to automatic review settings March 18, 2026 09:44
@pfefferle pfefferle added the Enhancement New feature or request label Mar 18, 2026
@pfefferle pfefferle self-assigned this Mar 18, 2026
@pfefferle pfefferle requested a review from a team March 18, 2026 09:44
@github-actions github-actions bot added [Block] Federated reply Respond to posts, notes, videos, and other content on the fediverse. [Focus] Editor Changes to the ActivityPub experience in the block editor labels Mar 18, 2026
- filter_blocks_hidden_from_fediverse → maybe_hide_block
- is_block_hidden_from_fediverse → is_federated
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an editor-facing “Share to the Fediverse” per-block toggle and enforces it during ActivityPub rendering so authors can exclude specific blocks from federated content without affecting on-site display.

Changes:

  • Introduces a block editor plugin that writes metadata.blockVisibility.fediverse per block via a new Inspector “Fediverse ⁂” panel.
  • Filters hidden blocks out of ActivityPub-rendered HTML and excludes them from reply URL + media attachment extraction.
  • Disables core visibility UI on the Federated Reply block (supports.visibility: false) and adds the needed JS dependency.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/reply/block.json Disables core visibility controls for the Federated Reply block.
src/block-visibility/plugin.js Adds the Inspector toggle and persists the setting into block metadata.
src/block-visibility/block.json Provides build metadata for the editor plugin bundle.
includes/class-blocks.php Adds render-time filtering for hidden blocks during ActivityPub content generation.
includes/transformer/class-post.php Skips hidden blocks when extracting in-reply-to URLs and media attachments.
package.json Adds @wordpress/hooks for the new editor plugin code.
package-lock.json Locks the new dependency.
.github/changelog/block-visibility-fediverse Changelog entry for the new feature.
build/* Build artifacts (not code-reviewed).
Comments suppressed due to low confidence (2)

includes/class-blocks.php:1016

  • filter_blocks_hidden_from_fediverse() / is_block_hidden_from_fediverse() introduce new filtering logic that affects all ActivityPub content rendering. There are existing PHPUnit tests for Activitypub\Blocks (e.g., reply link generation and import transformations), but no coverage for this new visibility behavior; please add tests for both helper methods (visible by default, hidden when metadata.blockVisibility.fediverse is false, and filtering returns an empty string when hidden).
	/**
	 * Strip blocks not marked for federation during content rendering.
	 *
	 * @since unreleased
	 *
	 * @param string $block_content The rendered block content.
	 * @param array  $block         The parsed block data.
	 *
	 * @return string The block content, or empty string if hidden.
	 */
	public static function maybe_hide_block( $block_content, $block ) {
		if ( ! self::is_federated( $block ) ) {
			return '';
		}

		return $block_content;
	}

	/**
	 * Whether a block should be included in federated content.
	 *
	 * Checks `metadata.blockVisibility.fediverse`. Defaults to true.
	 *
	 * @since unreleased
	 *
	 * @param array $block The parsed block data.
	 *
	 * @return bool True if the block should be federated.
	 */
	public static function is_federated( $block ) {
		$visibility = $block['attrs']['metadata']['blockVisibility']['fediverse'] ?? true;

		return false !== $visibility;
	}

	/**
	 * Generate HTML @ link for reply block.
	 *
	 * @param string $block_content The block content.

includes/class-blocks.php:960

  • In add_post_transformation_callbacks(), generate_reply_link is added whenever the first block is activitypub/reply, even if that reply block is hidden from the Fediverse. In that case the block will be removed later by filter_blocks_hidden_from_fediverse, but generate_reply_link() can still run first and perform remote fetches unnecessarily. Consider skipping the render_block_activitypub/reply filter when the first reply block is hidden (e.g., check self::is_block_hidden_from_fediverse( $blocks[0] ) before adding the filter).
		// Only transform reply link if it's the first block in the post.
		$blocks = \parse_blocks( $post->post_content );
		if ( ! empty( $blocks ) && 'activitypub/reply' === $blocks[0]['blockName'] ) {
			\add_filter( 'render_block_activitypub/reply', array( self::class, 'generate_reply_link' ), 10, 2 );
		}

You can also share your feedback on Copilot code review. Take the survey.

- is_federated: default true, explicit true, missing metadata, false
- maybe_hide_block: keeps visible blocks, strips hidden blocks
- get_media_from_blocks: skips images in hidden blocks
- get_in_reply_to: skips hidden reply blocks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Federated reply Respond to posts, notes, videos, and other content on the fediverse. Enhancement New feature or request [Focus] Editor Changes to the ActivityPub experience in the block editor [Tests] Includes Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hidden and restricted blocks get published

2 participants