Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/changelog/1553-from-description
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

Add option to enable/disable the "shared inbox" to the "Advanced Settings".
22 changes: 22 additions & 0 deletions includes/class-activitypub.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static function init() {
\add_action( 'added_post_meta', array( self::class, 'updated_postmeta' ), 10, 4 );
\add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_option_activitypub_actor_mode' ) );
\add_filter( 'pre_option_activitypub_authorized_fetch', array( self::class, 'pre_option_activitypub_authorized_fetch' ) );
\add_filter( 'pre_option_activitypub_shared_inbox', array( self::class, 'pre_option_activitypub_shared_inbox' ) );
Copy link
Member

Choose a reason for hiding this comment

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

The "fourth" callback! :)
Should we create a separate class for these?


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

Expand Down Expand Up @@ -121,6 +122,7 @@ public static function uninstall() {
delete_option( 'activitypub_migration_lock' );
delete_option( 'activitypub_object_type' );
delete_option( 'activitypub_outbox_purge_days' );
delete_option( 'activitypub_shared_inbox' );
delete_option( 'activitypub_support_post_types' );
delete_option( 'activitypub_use_hashtags' );
delete_option( 'activitypub_use_opengraph' );
Expand Down Expand Up @@ -436,6 +438,26 @@ public static function pre_option_activitypub_authorized_fetch( $pre ) {
return '0';
}

/**
* Pre-get option filter for the Shared Inbox.
*
* @param string $pre The pre-get option value.
*
* @return string If the constant is defined, return the value, otherwise return the pre-get option value.
*/
public static function pre_option_activitypub_shared_inbox( $pre ) {
if ( ! \defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) ) {
return $pre;
}

if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
return '1';
}

return '0';
}


/**
* Store permalink in meta, to send delete Activity.
*
Expand Down
1 change: 0 additions & 1 deletion includes/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
\defined( 'ACTIVITYPUB_DISABLE_REWRITES' ) || \define( 'ACTIVITYPUB_DISABLE_REWRITES', false );
\defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS', false );
\defined( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS' ) || \define( 'ACTIVITYPUB_DISABLE_OUTGOING_INTERACTIONS', false );
\defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) || \define( 'ACTIVITYPUB_SHARED_INBOX_FEATURE', false );
\defined( 'ACTIVITYPUB_SEND_VARY_HEADER' ) || \define( 'ACTIVITYPUB_SEND_VARY_HEADER', false );
\defined( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE' ) || \define( 'ACTIVITYPUB_DEFAULT_OBJECT_TYPE', 'wordpress-post-format' );
\defined( 'ACTIVITYPUB_OUTBOX_PROCESSING_BATCH_SIZE' ) || \define( 'ACTIVITYPUB_OUTBOX_PROCESSING_BATCH_SIZE', 100 );
Expand Down
2 changes: 1 addition & 1 deletion includes/model/class-blog.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ public function get_following() {
public function get_endpoints() {
$endpoints = null;

if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
if ( \get_option( 'activitypub_shared_inbox' ) ) {
$endpoints = array(
'sharedInbox' => get_rest_url_by_path( 'inbox' ),
);
Expand Down
2 changes: 1 addition & 1 deletion includes/model/class-user.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public function get_featured() {
public function get_endpoints() {
$endpoints = null;

if ( ACTIVITYPUB_SHARED_INBOX_FEATURE ) {
if ( \get_option( 'activitypub_shared_inbox' ) ) {
$endpoints = array(
'sharedInbox' => get_rest_url_by_path( 'inbox' ),
);
Expand Down
29 changes: 29 additions & 0 deletions includes/wp-admin/class-advanced-settings-fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public static function register_advanced_fields() {
array( 'label_for' => 'activitypub_authorized_fetch' )
);
}

if ( ! defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) ) {
\add_settings_field(
'activitypub_shared_inbox',
\__( 'Shared Inbox (beta)', 'activitypub' ),
array( self::class, 'render_shared_inbox_field' ),
'activitypub_advanced_settings',
'activitypub_advanced_settings',
array( 'label_for' => 'activitypub_shared_inbox' )
);
}
}

/**
Expand Down Expand Up @@ -110,4 +121,22 @@ public static function render_authorized_fetch_field() {
</p>
<?php
}

/**
* Render shared inbox field.
*/
public static function render_shared_inbox_field() {
$value = \get_option( 'activitypub_shared_inbox', '0' );
?>
<p>
<label>
<input type="checkbox" id="activitypub_shared_inbox" name="activitypub_shared_inbox" value="1" <?php checked( '1', $value ); ?> />
<?php \esc_html_e( 'Use a shared inbox for incoming messages.', 'activitypub' ); ?>
</label>
</p>
<p class="description">
<?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' ); ?>
</p>
<?php
}
}
6 changes: 6 additions & 0 deletions includes/wp-admin/class-health-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ public static function debug_information( $info ) {
'private' => false,
);

$info['activitypub']['fields']['shared_inbox'] = array(
'label' => \__( 'Shared Inbox', 'activitypub' ),
'value' => \esc_attr( (int) \get_option( 'activitypub_shared_inbox', '0' ) ),
'private' => false,
);

$consts = get_defined_constants( true );

if ( ! isset( $consts['user'] ) ) {
Expand Down
10 changes: 10 additions & 0 deletions includes/wp-admin/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,16 @@ public static function register_settings() {
)
);

\register_setting(
'activitypub_advanced',
'activitypub_shared_inbox',
array(
'type' => 'boolean',
'description' => \__( 'Enable the shared inbox.', 'activitypub' ),
Copy link
Member

Choose a reason for hiding this comment

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

Do these need to be translated? Where are these stings visible?

Copy link
Member Author

Choose a reason for hiding this comment

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

all settings are translated, that's why AI wanted to keep consistency. I am fine with both, but we should change the rest too then.

'default' => false,
)
);

\register_setting(
'activitypub',
'activitypub_relays',
Expand Down
Loading