From 234cf69e38389066e1bed115ff7a465bb0307761 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Mon, 7 Apr 2025 12:10:50 +0200 Subject: [PATCH 1/6] Add: Shared Inbox setting --- includes/class-activitypub.php | 22 ++++++++++++++ includes/constants.php | 1 - includes/model/class-blog.php | 2 +- includes/model/class-user.php | 2 +- .../class-advanced-settings-fields.php | 29 +++++++++++++++++++ includes/wp-admin/class-health-check.php | 6 ++++ includes/wp-admin/class-settings.php | 10 +++++++ 7 files changed, 69 insertions(+), 3 deletions(-) diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index 936cd6ce4..9bf77e7ed 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -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' ) ); \add_action( 'init', array( self::class, 'register_user_meta' ), 11 ); @@ -100,6 +101,7 @@ public static function uninstall() { delete_option( 'activitypub_allow_replies' ); delete_option( 'activitypub_attribution_domains' ); delete_option( 'activitypub_authorized_fetch' ); + delete_option( 'activitypub_shared_inbox' ); delete_option( 'activitypub_application_user_private_key' ); delete_option( 'activitypub_application_user_public_key' ); delete_option( 'activitypub_blog_user_also_known_as' ); @@ -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. * diff --git a/includes/constants.php b/includes/constants.php index f1a9b22d5..6adfce393 100644 --- a/includes/constants.php +++ b/includes/constants.php @@ -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 ); diff --git a/includes/model/class-blog.php b/includes/model/class-blog.php index 17dbcbba3..23c95bcb9 100644 --- a/includes/model/class-blog.php +++ b/includes/model/class-blog.php @@ -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' ), ); diff --git a/includes/model/class-user.php b/includes/model/class-user.php index 29358d6a2..c12fccafc 100644 --- a/includes/model/class-user.php +++ b/includes/model/class-user.php @@ -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' ), ); diff --git a/includes/wp-admin/class-advanced-settings-fields.php b/includes/wp-admin/class-advanced-settings-fields.php index c984465c9..f3caf6301 100644 --- a/includes/wp-admin/class-advanced-settings-fields.php +++ b/includes/wp-admin/class-advanced-settings-fields.php @@ -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', 'activitypub' ) . ' ' . \__( '(beta)', 'activitypub' ), + array( self::class, 'render_shared_inbox_field' ), + 'activitypub_advanced_settings', + 'activitypub_advanced_settings', + array( 'label_for' => 'activitypub_shared_inbox' ) + ); + } } /** @@ -110,4 +121,22 @@ public static function render_authorized_fetch_field() {

+

+ +

+

+ +

+ 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'] ) ) { diff --git a/includes/wp-admin/class-settings.php b/includes/wp-admin/class-settings.php index ef4568f66..537a56c46 100644 --- a/includes/wp-admin/class-settings.php +++ b/includes/wp-admin/class-settings.php @@ -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' ), + 'default' => false, + ) + ); + \register_setting( 'activitypub', 'activitypub_relays', From 7737d31a8833f2e3411bf63f4d4c9decb20415c6 Mon Sep 17 00:00:00 2001 From: Automattic Bot Date: Mon, 7 Apr 2025 13:13:21 +0300 Subject: [PATCH 2/6] Add changelog --- .github/changelog/1553-from-description | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .github/changelog/1553-from-description diff --git a/.github/changelog/1553-from-description b/.github/changelog/1553-from-description new file mode 100644 index 000000000..4ff788f86 --- /dev/null +++ b/.github/changelog/1553-from-description @@ -0,0 +1,4 @@ +Significance: patch +Type: changed + +Add option to enable/disable the "shared inbox" to the "Advanced Settings". From 08f7d7db74b0f289cb21dc0f019589f0c86705c7 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Mon, 7 Apr 2025 18:04:43 +0200 Subject: [PATCH 3/6] fix order --- includes/class-activitypub.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index 9bf77e7ed..c623d0bd7 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -101,7 +101,6 @@ public static function uninstall() { delete_option( 'activitypub_allow_replies' ); delete_option( 'activitypub_attribution_domains' ); delete_option( 'activitypub_authorized_fetch' ); - delete_option( 'activitypub_shared_inbox' ); delete_option( 'activitypub_application_user_private_key' ); delete_option( 'activitypub_application_user_public_key' ); delete_option( 'activitypub_blog_user_also_known_as' ); @@ -123,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' ); From 04e7628bbaa5941643eb91d218e9f261774b7ad8 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Mon, 7 Apr 2025 18:05:57 +0200 Subject: [PATCH 4/6] more RTL friendly props @obenland --- includes/wp-admin/class-advanced-settings-fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wp-admin/class-advanced-settings-fields.php b/includes/wp-admin/class-advanced-settings-fields.php index f3caf6301..82ee0f8d8 100644 --- a/includes/wp-admin/class-advanced-settings-fields.php +++ b/includes/wp-admin/class-advanced-settings-fields.php @@ -53,7 +53,7 @@ public static function register_advanced_fields() { if ( ! defined( 'ACTIVITYPUB_SHARED_INBOX_FEATURE' ) ) { \add_settings_field( 'activitypub_shared_inbox', - \__( 'Shared Inbox', 'activitypub' ) . ' ' . \__( '(beta)', 'activitypub' ), + \__( 'Shared Inbox (beta)', 'activitypub' ), array( self::class, 'render_shared_inbox_field' ), 'activitypub_advanced_settings', 'activitypub_advanced_settings', From 8f0a6bb5adda0e5fd3a43265eb5a9f8e4d5e2aa3 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Mon, 7 Apr 2025 18:09:09 +0200 Subject: [PATCH 5/6] improve wording props @obenland --- includes/wp-admin/class-advanced-settings-fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wp-admin/class-advanced-settings-fields.php b/includes/wp-admin/class-advanced-settings-fields.php index 82ee0f8d8..9ebaa6b7b 100644 --- a/includes/wp-admin/class-advanced-settings-fields.php +++ b/includes/wp-admin/class-advanced-settings-fields.php @@ -135,7 +135,7 @@ public static function render_shared_inbox_field() {

- +

Date: Mon, 7 Apr 2025 18:09:46 +0200 Subject: [PATCH 6/6] improve wording --- includes/wp-admin/class-advanced-settings-fields.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wp-admin/class-advanced-settings-fields.php b/includes/wp-admin/class-advanced-settings-fields.php index 9ebaa6b7b..81c521822 100644 --- a/includes/wp-admin/class-advanced-settings-fields.php +++ b/includes/wp-admin/class-advanced-settings-fields.php @@ -131,7 +131,7 @@ public static function render_shared_inbox_field() {