Skip to content

Conversation

@pfefferle
Copy link
Member

@pfefferle pfefferle commented Nov 28, 2025

if all you have is a hammer, everything looks like a nail

so how would a WordPress plugin dev implement a relay? 😉

Proposed changes:

This PR adds relay mode functionality to the ActivityPub plugin. When enabled, the blog actor automatically forwards all public activities it receives to all its followers, functioning as an ActivityPub relay server.

  • Add relay mode setting in advanced settings page with warning about resource usage
  • Implement automatic forwarding of public activities using action hooks
  • Change blog actor type to 'Service' when relay mode is active
  • Automatically manage related options (blog identifier, actor mode) when toggling relay mode

Other information:

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

Testing instructions:

  1. Go to 'Settings > ActivityPub > Advanced'
  2. Enable the "Relay Mode" checkbox
  3. Save settings
  4. Verify that:
    • The blog actor identifier changes to 'relay'
    • The blog actor type changes to 'Service' when viewing the actor endpoint
    • Actor mode is set to blog-only
  5. Send a public activity to the blog actor from another ActivityPub server
  6. Verify that the activity is forwarded (announced) to all followers of the blog actor
  7. Disable relay mode
  8. Verify that previous settings are restored

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 relay mode to forward public activities to all followers.

pfefferle and others added 4 commits November 28, 2025 10:27
Refactors the relay mode implementation for better code organization:
- Moves relay_mode_changed() method from Relay class to Options class where other option-related hooks are handled
- Removes Relay::init() method as it's no longer needed
- Removes Relay::init() call from activitypub.php
- Reorganizes tests: relay mode option tests moved to Test_Options, Blog actor type test moved to Test_Blog
- Keeps only core relay functionality tests (should_relay, forward_activity) in Test_Relay

This follows the existing pattern where Options class handles option change hooks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
…tion

Changes the relay implementation to hook into activitypub_handled_* actions
rather than modifying handlers directly:
- Adds Relay::init() method that hooks into handled_create, handled_update,
  handled_delete, and handled_announce actions
- Adds Relay::handle_activity() method that checks conditions and relays
- Uses existing is_activity_public() function instead of custom implementation
- Removes forwarding code from individual handlers
- Updates tests to test handle_activity method instead of should_relay
Improvements to the relay implementation:
- Check relay mode in init() to only add hooks when relay is enabled
- Pass activity array directly to forward_activity instead of converting to object
- Remove manual ID generation for Announce, let outbox handle it
- Update tests to match new implementation
Copilot finished reviewing on behalf of pfefferle November 28, 2025 10:07
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

This PR adds relay mode functionality to enable the ActivityPub blog actor to forward public activities to all followers. However, the implementation has critical bugs that will cause fatal errors when the handlers execute. The handlers attempt to call Relay::should_relay() and Relay::forward_activity() methods that don't exist in the Relay class.

Key Changes

  • Add relay mode toggle in advanced settings with comprehensive warnings about resource usage
  • Implement relay functionality using action hooks that fire after activities are handled
  • Change blog actor type from Group/Person to Service when relay mode is enabled
  • Automatic option management: sets blog-only mode and 'relay' identifier when enabled, restores on disable

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
includes/class-relay.php NEW - Implements relay functionality by hooking into activitypub_handled_* actions to wrap and forward public activities as Announce activities
includes/class-options.php Adds relay_mode_changed() hook handler to automatically configure blog-only mode and relay identifier when relay mode is toggled
includes/model/class-blog.php Changes blog actor type to 'Service' when relay mode is enabled (before Person/Group logic)
includes/handler/class-create.php BROKEN - Calls non-existent Relay::should_relay() and Relay::forward_activity() methods
includes/handler/class-update.php BROKEN - Calls non-existent Relay::should_relay() and Relay::forward_activity() methods
includes/handler/class-delete.php BROKEN - Calls non-existent Relay::should_relay() and Relay::forward_activity() methods
includes/handler/class-announce.php BROKEN - Calls non-existent Relay::should_relay() and Relay::forward_activity() methods
includes/wp-admin/class-settings.php Registers the activitypub_relay_mode boolean setting
includes/wp-admin/class-advanced-settings-fields.php Adds UI field for relay mode with detailed warnings about implications
activitypub.php Adds Relay::init() to initialization sequence
tests/phpunit/tests/includes/class-test-relay.php NEW - Comprehensive test coverage for relay functionality (6 test cases)
tests/phpunit/tests/includes/class-test-options.php Tests for automatic option management when relay mode is toggled
tests/phpunit/tests/includes/model/class-test-blog.php Tests that blog actor type changes to Service in relay mode

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

@pfefferle pfefferle requested a review from obenland November 28, 2025 10:20
The activitypub_relay_mode setting was registered with the 'activitypub'
option group, but the advanced settings form uses 'activitypub_advanced'.
This caused the setting to not be saved when the form was submitted.
- Hide 'Change Profile ID' field from Blog Profile settings when relay mode is active
- Prevent blog identifier from being changed via sanitize callback when relay mode is enabled
- Ensures the identifier stays as 'relay' when relay mode is on
Changed 'activitypub_relay_mode' option to use string values ('0' and '1') instead of booleans in both the settings field and related tests. This ensures consistent handling and comparison of the option throughout the codebase.
When relay mode is active, remove all settings sections and fields except
moderation from the Settings page using WordPress globals to simplify the
interface and prevent changes to incompatible options.
Use fully qualified class name for @Covers annotations.
Use fully qualified class name for @Covers annotations.
@pfefferle
Copy link
Member Author

@obenland the idea was, to use the plugin, to run a WordPress (or Full-Article) relay, that can be added as default for at least WordPress.com blogs. The question is how well that scales on high load.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants