Automattic / Automattic/wordpress-activitypub

Subsystem registration is gated on option reads at plugins_loaded

Closed
#3,767 0 comments 0 reactions 1 assignee Claimed by @pfefferle View on GitHub
Dominant language
PHP
Stars
579
Forks
92
Avg merge
13h 5m
Merged PRs (30d)
85

Description

### Description

`plugin_init()` (`activitypub.php`) decides whether to hook several subsystems by reading options at `plugins_loaded`:

- `get_option( 'activitypub_api', false )` gates `Event_Stream::init()` and `OAuth\Server::init()`
- `get_option( 'activitypub_relay_mode', false )` gates `Relay::init()`

`rest_init()` gates the actor-autocomplete controller and the three OAuth REST controllers on `activitypub_api` the same way.

On a multisite host, plugin code can run before the request has been switched to the site it is serving. In that window these reads hit a different site's options and return `false`. Because the decision is an `add_action( 'init', … )` taken at `plugins_loaded`, a later `switch_to_blog()` cannot retroactively register anything — the subsystems are absent for the whole request even though the target site has the feature enabled. The symptom is silent: no error, the endpoints just aren't there.

More generally this is configuration evaluated at registration time rather than at use time, which also makes the behaviour awkward to change within a request or to set up in tests.

### Suggested change

Register these subsystems unconditionally and move the option check to the point of use — inside the callbacks themselves, or in an `init` callback that runs once the host has settled the site context. `add_action()` is cheap; it is the option read that needs to be late.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.