-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfosse.php
More file actions
314 lines (290 loc) · 11.7 KB
/
fosse.php
File metadata and controls
314 lines (290 loc) · 11.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
<?php
/**
* Plugin Name: FOSSE
* Plugin URI: https://github.com/Automattic/fosse
* Description: Social Web
* Version: 0.0.1
* Requires at least: 6.9
* Tested up to: 7.0
* Requires PHP: 8.2
* Author: Automattic, kraftbj, ryancowles
* Author URI: https://automattic.com
* License: GPL-2.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: fosse
*
* @package Fosse
*/
defined( 'ABSPATH' ) || exit;
if ( file_exists( __DIR__ . '/vendor/autoload_packages.php' ) ) {
require_once __DIR__ . '/vendor/autoload_packages.php';
}
/*
* wp.com Simple load contract.
*
* On wp.com Simple, FOSSE is included by `wp-content/mu-plugins/fosse-loader.php`
* at `plugins_loaded` priority 8 — one tick before the platform's
* `wpcom-activitypub-load.php` (priority 9). Bundled ActivityPub defines
* `ACTIVITYPUB_PLUGIN_DIR` during its own boot, which trips the
* `wpcom_activitypub_is_loaded()` early-bail and suppresses the platform AP load.
*
* The skip-when-standalone checks below (`ACTIVITYPUB_PLUGIN_VERSION` /
* `ATMOSPHERE_VERSION`) MUST stay intact: if the wp.com loader ever defined
* those constants itself, FOSSE would silently skip its own bundle and the
* rollout would no-op. See DOTCOM-16981.
*/
/*
* Bundled federation backends.
*
* FOSSE ships release-build copies of wordpress-activitypub and
* wordpress-atmosphere so users get Mastodon + Bluesky federation out
* of the box. We skip the bundled copy when the standalone plugin is
* either already loaded (its constants are defined) OR present on
* disk at the canonical plugin path — so if the user activates the
* standalone later in the same request, WP's plugin_sandbox_scrape
* doesn't redeclare classes we already loaded.
*
* This is a short-term bootstrap; FOSSE's own UI will replace the
* bundled plugins' admin surface in a later iteration.
*/
$fosse_loaded_bundled_ap = false;
$fosse_loaded_bundled_atmo = false;
$fosse_standalone_ap_present = defined( 'ACTIVITYPUB_PLUGIN_VERSION' )
|| ( defined( 'WP_PLUGIN_DIR' ) && file_exists( WP_PLUGIN_DIR . '/activitypub/activitypub.php' ) );
if ( ! $fosse_standalone_ap_present && file_exists( __DIR__ . '/bundled/activitypub/activitypub.php' ) ) {
require_once __DIR__ . '/bundled/activitypub/activitypub.php';
$fosse_loaded_bundled_ap = true;
}
$fosse_standalone_atmo_present = defined( 'ATMOSPHERE_VERSION' )
|| ( defined( 'WP_PLUGIN_DIR' ) && file_exists( WP_PLUGIN_DIR . '/atmosphere/atmosphere.php' ) );
if ( ! $fosse_standalone_atmo_present && file_exists( __DIR__ . '/bundled/atmosphere/atmosphere.php' ) ) {
require_once __DIR__ . '/bundled/atmosphere/atmosphere.php';
$fosse_loaded_bundled_atmo = true;
}
unset( $fosse_standalone_ap_present, $fosse_standalone_atmo_present );
/*
* First-load bootstrap for the bundled backends.
*
* Bundled plugins never go through the WP plugins screen, so their
* register_activation_hook callbacks never fire. Run the upstream
* activate() routines once per distinct upstream version to seed
* options, flush rewrites, and generate any needed identifiers.
*
* Hooked on `init` (priority 20) rather than `plugins_loaded` because
* AP's activate() calls flush_rewrite_rules(), which requires the
* $wp_rewrite global — initialized on `init`.
*/
add_action(
'init',
static function () use ( $fosse_loaded_bundled_ap, $fosse_loaded_bundled_atmo ) {
// Degrade cleanly if FOSSE's own composer autoload is missing (e.g.
// a bare clone without vendor/); bundled plugins still load, just
// without the first-run activation shim.
if ( ! class_exists( \Automattic\Fosse\Bundled\Bootstrap::class ) ) {
return;
}
if ( $fosse_loaded_bundled_ap && class_exists( '\Activitypub\Activitypub' ) && defined( 'ACTIVITYPUB_PLUGIN_VERSION' ) ) {
\Automattic\Fosse\Bundled\Bootstrap::maybe_run(
'fosse_bundled_ap_bootstrapped',
ACTIVITYPUB_PLUGIN_VERSION,
static function () {
\Activitypub\Activitypub::activate( false );
}
);
}
if ( $fosse_loaded_bundled_atmo && function_exists( '\Atmosphere\activate' ) && defined( 'ATMOSPHERE_VERSION' ) ) {
\Automattic\Fosse\Bundled\Bootstrap::maybe_run(
'fosse_bundled_atmosphere_bootstrapped',
ATMOSPHERE_VERSION,
'\Atmosphere\activate'
);
}
},
20
);
/*
* ActivityPub actor-mode lock enforcement.
*
* When the host defines `ACTIVITYPUB_SINGLE_USER_MODE`,
* `ACTIVITYPUB_DISABLE_USER`, or `ACTIVITYPUB_DISABLE_BLOG_USER`, any
* write to `activitypub_actor_mode` (admin form, REST `/wp/v2/settings`,
* or direct options.php POST) is coerced to the forced mode, and an
* `admin_init` repair pass rewrites the stored value when it disagrees
* with the forced mode. The repair runs on admin requests only — not
* on frontend page views — so a high-traffic spike on a corrupted
* install doesn't multiply into write attempts on every request.
* Together these keep what bundled AP serves on read aligned with
* what's actually in the database, so removing the lock later never
* surfaces a stale value as the new active mode. Degrades cleanly if
* FOSSE's own composer autoload is missing — the `class_exists` guard
* skips registration entirely.
*/
if ( class_exists( \Automattic\Fosse\Admin\Actor_Mode_Lock::class ) ) {
\Automattic\Fosse\Admin\Actor_Mode_Lock::register_hooks();
}
/*
* Cross-network object-type bridge.
*
* Bridges ActivityPub's `activitypub_object_type` option onto Atmosphere's
* `atmosphere_is_short_form_post` filter so a `'note'` choice in AP's
* settings also forces Atmosphere short-form. The option is owned by
* ActivityPub end-to-end; FOSSE no longer keeps a parallel option (see
* `sdd/canonical-upstream-options/`). Registered on `init` so the filter
* is in place before Atmosphere queries it during `transition_post_status`
* later in the request lifecycle. Degrades cleanly if FOSSE's own
* composer autoload is missing — same posture as the bundled-bootstrap
* shim above.
*/
add_action(
'init',
static function () {
if ( ! class_exists( \Automattic\Fosse\Object_Type::class ) ) {
return;
}
\Automattic\Fosse\Object_Type::register();
}
);
/*
* Cross-network post-type projector.
*
* Feeds ActivityPub's stored `activitypub_support_post_types` option into
* Atmosphere's `atmosphere_syncable_post_types` filter so the post types a
* user selects in AP's settings also federate via Atmosphere. Intentionally
* one-way: AP's option is the single source of truth, so FOSSE does not own
* a parallel option. Same degradation posture as the Object_Type block.
*/
add_action(
'init',
static function () {
if ( ! class_exists( \Automattic\Fosse\Post_Types::class ) ) {
return;
}
\Automattic\Fosse\Post_Types::register();
}
);
/*
* One-time migration of FOSSE-side projector options to canonical
* upstream options (`fosse_object_type` → `activitypub_object_type`,
* `fosse_long_form_strategy` → `atmosphere_long_form_composition`).
*
* Replaces the long-form `fosse_long_form_strategy` projector entirely
* and the AP-side half of the object-type projector. Runs at most once
* per site, gated on a flag option, on `init` priority 5 so the
* migration completes before the projector callbacks (priority 10) and
* before any post publish path queries the canonical option. Also
* seeds Atmosphere's long-form composition with FOSSE's preferred
* default (`'teaser-thread'`) for fresh installs that have neither
* option set, preserving today's behavior for new sites.
*
* Registration is deferred to `plugins_loaded` (not the surrounding
* `init` callback) so the migrator's own `add_action('init', ..., 5)`
* lands on the priority-5 slot of the same `init` cycle. Registering
* from inside an `init`-default-priority callback would miss the
* priority-5 slot in the active iteration and the migration would
* never run on first activation. See `sdd/canonical-upstream-options/`.
*/
add_action(
'plugins_loaded',
static function () {
if ( ! class_exists( \Automattic\Fosse\Canonical_Options_Migrator::class ) ) {
return;
}
\Automattic\Fosse\Canonical_Options_Migrator::register();
}
);
/*
* Reactions block relabel.
*
* Overlays a FOSSE-flavored title and description onto the bundled
* activitypub/reactions block via register_block_type_args. The
* block's server-side render is already protocol-agnostic and
* aggregates ActivityPub plus Bluesky reactions; the relabel makes
* the inserter UI wording match what the block actually shows. The
* register() method itself guards on the AP class_exists check so
* the filter is never registered on hosts without ActivityPub.
*/
add_action(
'init',
static function () {
if ( ! class_exists( \Automattic\Fosse\Reactions_Label::class ) ) {
return;
}
\Automattic\Fosse\Reactions_Label::register();
}
);
/*
* Metrics: search-indexing watcher.
*
* Emits `fosse_search_indexing_disabled_post_active` when a site flips
* the federation gate (`blog_public`) off while FOSSE is active. Each
* host wires the active-determination via the
* `fosse_metrics_is_active_for_site` filter; the default is `false` so
* pure-self-host checkouts emit nothing.
*/
add_action(
'init',
static function () {
if ( ! class_exists( \Automattic\Fosse\Metrics\Search_Indexing_Watcher::class ) ) {
return;
}
\Automattic\Fosse\Metrics\Search_Indexing_Watcher::register();
}
);
/*
* Provider bootstrap.
*
* Providers self-register on the 'fosse_register_providers' action fired
* by Provider_Loader::boot(). This runs unconditionally so provider hooks
* (option-projection filters, etc.) are active on every request — admin,
* REST, WebFinger, cron.
*/
if ( class_exists( \Automattic\Fosse\Provider_Loader::class ) ) {
\Automattic\Fosse\Admin\AP_Provider::init();
\Automattic\Fosse\Admin\Bluesky_Provider::init();
\Automattic\Fosse\Provider_Loader::boot();
}
/*
* Activation redirect.
*
* Persists a one-shot signal in the options table on first activation
* so the admin-init handler in Menu can redirect to the onboarding
* wizard. Stored with autoload `false` and consumed on the first
* qualifying admin request. Survives indefinitely if no admin request
* ever runs (transients TTLed out and could leave the wizard never
* reached on slow-to-visit installs).
*/
register_activation_hook(
__FILE__,
static function () {
if ( ! class_exists( \Automattic\Fosse\Admin\Onboarding_Wizard::class ) ) {
error_log( 'FOSSE: Onboarding_Wizard class unavailable on activation; skipping redirect signal.' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- intentional plugin diagnostics; only fires when autoload is broken.
return;
}
$option = \Automattic\Fosse\Admin\Onboarding_Wizard::REDIRECT_OPTION;
if ( ! update_option( $option, 1, false ) && ! get_option( $option ) ) {
error_log( 'FOSSE: Failed to persist activation redirect signal (' . $option . ').' ); // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log -- intentional plugin diagnostics; only fires when the option write actually failed.
}
}
);
/*
* Admin UI: FOSSE setup and status pages.
*
* Menu registration, bundled-menu suppression, and CSS enqueue.
* Provider hooks are already registered above.
*/
if ( is_admin() && class_exists( \Automattic\Fosse\Admin\Menu::class ) ) {
\Automattic\Fosse\Admin\Menu::register();
}
/*
* Per-user settings-notice plumbing.
*
* Replaces WP core's site-global `settings_errors` transient with a
* per-user one so admin notices ("Your Bluesky handle is now …",
* connect/disconnect feedback, settings-saved banners) don't leak
* across users on multi-admin installs. Hooks `consume()` on
* `admin_init` priority 1 so the merge into `$wp_settings_errors`
* runs before any page calls `settings_errors()` to render.
*/
if ( is_admin() && class_exists( \Automattic\Fosse\Admin\User_Notices::class ) ) {
\Automattic\Fosse\Admin\User_Notices::register();
}