Skip to content

Commit b704d95

Browse files
authored
Add: Shared Inbox setting (#1553)
1 parent e7bb8fd commit b704d95

File tree

8 files changed

+73
-3
lines changed

8 files changed

+73
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: patch
2+
Type: changed
3+
4+
Add option to enable/disable the "shared inbox" to the "Advanced Settings".

includes/class-activitypub.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static function init() {
5151
\add_action( 'added_post_meta', array( self::class, 'updated_postmeta' ), 10, 4 );
5252
\add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_option_activitypub_actor_mode' ) );
5353
\add_filter( 'pre_option_activitypub_authorized_fetch', array( self::class, 'pre_option_activitypub_authorized_fetch' ) );
54+
\add_filter( 'pre_option_activitypub_shared_inbox', array( self::class, 'pre_option_activitypub_shared_inbox' ) );
5455

5556
\add_action( 'init', array( self::class, 'register_user_meta' ), 11 );
5657

@@ -121,6 +122,7 @@ public static function uninstall() {
121122
delete_option( 'activitypub_migration_lock' );
122123
delete_option( 'activitypub_object_type' );
123124
delete_option( 'activitypub_outbox_purge_days' );
125+
delete_option( 'activitypub_shared_inbox' );
124126
delete_option( 'activitypub_support_post_types' );
125127
delete_option( 'activitypub_use_hashtags' );
126128
delete_option( 'activitypub_use_opengraph' );
@@ -436,6 +438,26 @@ public static function pre_option_activitypub_authorized_fetch( $pre ) {
436438
return '0';
437439
}
438440

441+
/**
442+
* Pre-get option filter for the Shared Inbox.
443+
*
444+
* @param string $pre The pre-get option value.
445+
*
446+
* @return string If the constant is defined, return the value, otherwise return the pre-get option value.
447+
*/
448+
public static function pre_option_activitypub_shared_inbox( $pre ) {
449+
if ( ! \defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) ) {
450+
return $pre;
451+
}
452+
453+
if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
454+
return '1';
455+
}
456+
457+
return '0';
458+
}
459+
460+
439461
/**
440462
* Store permalink in meta, to send delete Activity.
441463
*

includes/constants.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
\defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false );
2020
\defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS', false );
2121
\defined( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS', false );
22-
\defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) || \define( 'ACTIVITYPUB_SHARED_INBOX_FEATURE', false );
2322
\defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) || \define( 'ACTIVITYPUB_SEND_VARY_HEADER', false );
2423
\defined( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE' ) || \define( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE', 'wordpress-post-format' );
2524
\defined( 'ACTIVITYPUB_OUTBOX_PROCESSING_BATCH_SIZE' ) || \define( 'ACTIVITYPUB_OUTBOX_PROCESSING_BATCH_SIZE', 100 );

includes/model/class-blog.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ public function get_following() {
419419
public function get_endpoints() {
420420
$endpoints = null;
421421

422-
if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
422+
if ( \get_option( 'activitypub_shared_inbox' ) ) {
423423
$endpoints = array(
424424
'sharedInbox' => get_rest_url_by_path( 'inbox' ),
425425
);

includes/model/class-user.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ public function get_featured() {
295295
public function get_endpoints() {
296296
$endpoints = null;
297297

298-
if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
298+
if ( \get_option( 'activitypub_shared_inbox' ) ) {
299299
$endpoints = array(
300300
'sharedInbox' => get_rest_url_by_path( 'inbox' ),
301301
);

includes/wp-admin/class-advanced-settings-fields.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ public static function register_advanced_fields() {
4949
array( 'label_for' => 'activitypub_authorized_fetch' )
5050
);
5151
}
52+
53+
if ( ! defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) ) {
54+
\add_settings_field(
55+
'activitypub_shared_inbox',
56+
\__( 'Shared Inbox (beta)', 'activitypub' ),
57+
array( self::class, 'render_shared_inbox_field' ),
58+
'activitypub_advanced_settings',
59+
'activitypub_advanced_settings',
60+
array( 'label_for' => 'activitypub_shared_inbox' )
61+
);
62+
}
5263
}
5364

5465
/**
@@ -110,4 +121,22 @@ public static function render_authorized_fetch_field() {
110121
</p>
111122
<?php
112123
}
124+
125+
/**
126+
* Render shared inbox field.
127+
*/
128+
public static function render_shared_inbox_field() {
129+
$value = \get_option( 'activitypub_shared_inbox', '0' );
130+
?>
131+
<p>
132+
<label>
133+
<input type="checkbox" id="activitypub_shared_inbox" name="activitypub_shared_inbox" value="1" <?php checked( '1', $value ); ?> />
134+
<?php \esc_html_e( 'Use a shared inbox for incoming messages.', 'activitypub' ); ?>
135+
</label>
136+
</p>
137+
<p class="description">
138+
<?php \esc_html_e( 'Allows your site to handle incoming ActivityPub messages more efficiently, especially helpful for busy or multi-user sites. This feature is still in beta and may encounter issues.', 'activitypub' ); ?>
139+
</p>
140+
<?php
141+
}
113142
}

includes/wp-admin/class-health-check.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,12 @@ public static function debug_information( $info ) {
326326
'private' => false,
327327
);
328328

329+
$info['activitypub']['fields']['shared_inbox'] = array(
330+
'label' => \__( 'Shared Inbox', 'activitypub' ),
331+
'value' => \esc_attr( (int) \get_option( 'activitypub_shared_inbox', '0' ) ),
332+
'private' => false,
333+
);
334+
329335
$consts = get_defined_constants( true );
330336

331337
if ( ! isset( $consts['user'] ) ) {

includes/wp-admin/class-settings.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,16 @@ public static function register_settings() {
187187
)
188188
);
189189

190+
\register_setting(
191+
'activitypub_advanced',
192+
'activitypub_shared_inbox',
193+
array(
194+
'type' => 'boolean',
195+
'description' => \__( 'Enable the shared inbox.', 'activitypub' ),
196+
'default' => false,
197+
)
198+
);
199+
190200
\register_setting(
191201
'activitypub',
192202
'activitypub_relays',

0 commit comments

Comments
 (0)