diff --git a/CHANGELOG.md b/CHANGELOG.md index eeb8d877..290d5f2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Add a filter to allow modifying the ActivityPub preview template * `@mentions` in the JSON representation of the reply +* Add settings to enable/disable e-mail notifications for new followers and direct messages ### Improved diff --git a/includes/class-admin.php b/includes/class-admin.php index bda5b573..bd577fee 100644 --- a/includes/class-admin.php +++ b/includes/class-admin.php @@ -313,6 +313,25 @@ public static function register_settings() { ) ); + \register_setting( + 'activitypub', + 'activitypub_mailer_new_follower', + array( + 'type' => 'boolean', + 'description' => \__( 'Send notifications via e-mail when a new follower is added.', 'activitypub' ), + 'default' => '0', + ) + ); + \register_setting( + 'activitypub', + 'activitypub_mailer_new_dm', + array( + 'type' => 'boolean', + 'description' => \__( 'Send notifications via e-mail when a direct message is received.', 'activitypub' ), + 'default' => '0', + ) + ); + // Blog-User Settings. \register_setting( 'activitypub_blog', diff --git a/includes/class-mailer.php b/includes/class-mailer.php index 70acea9b..c9366216 100644 --- a/includes/class-mailer.php +++ b/includes/class-mailer.php @@ -22,10 +22,14 @@ public static function init() { \add_filter( 'comment_notification_text', array( self::class, 'comment_notification_text' ), 10, 2 ); // New follower notification. - \add_action( 'activitypub_notification_follow', array( self::class, 'new_follower' ) ); + if ( '1' === \get_option( 'activitypub_mailer_new_follower', '0' ) ) { + \add_action( 'activitypub_notification_follow', array( self::class, 'new_follower' ) ); + } // Direct message notification. - \add_action( 'activitypub_inbox_create', array( self::class, 'direct_message' ), 10, 2 ); + if ( '1' === \get_option( 'activitypub_mailer_new_dm', '0' ) ) { + \add_action( 'activitypub_inbox_create', array( self::class, 'direct_message' ), 10, 2 ); + } } /** diff --git a/includes/class-migration.php b/includes/class-migration.php index 5ebf26f0..fe352b47 100644 --- a/includes/class-migration.php +++ b/includes/class-migration.php @@ -452,6 +452,7 @@ public static function update_comment_counts( $batch_size = 100, $offset = 0 ) { */ public static function add_default_settings() { self::add_activitypub_capability(); + self::add_notification_defaults(); } /** @@ -471,6 +472,14 @@ private static function add_activitypub_capability() { } } + /** + * Add default notification settings. + */ + private static function add_notification_defaults() { + \add_option( 'activitypub_mailer_new_follower', '1' ); + \add_option( 'activitypub_mailer_new_dm', '1' ); + } + /** * Rename meta keys. * diff --git a/readme.txt b/readme.txt index 7c792598..646c7590 100644 --- a/readme.txt +++ b/readme.txt @@ -136,6 +136,7 @@ For reasons of data protection, it is not possible to see the followers of other * Added: A filter to allow modifying the ActivityPub preview template * Added: `@mentions` in the JSON representation of the reply +* Added: Settings to enable/disable e-mail notifications for new followers and direct messages * Improved: HTML to e-mail text conversion * Improved: Direct Messages: Test for the user being in the to field * Improved: Better support for FSE color schemes diff --git a/templates/settings.php b/templates/settings.php index 00bb02f5..3354d113 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -186,7 +186,43 @@ - +
+ + | ++ + | +
---|---|
+ + | ++ + | +
+ + | ++ + | +
- - | -
- - Disallowed Comment Keys" list.', 'activitypub' ), - \esc_url( \admin_url( 'options-discussion.php#disallowed_keys' ) ) - ), - 'default' - ); - ?> - - |
-
---|---|
+ + | +
+ + Disallowed Comment Keys" list.', 'activitypub' ), + \esc_url( \admin_url( 'options-discussion.php#disallowed_keys' ) ) + ), + 'default' + ); + ?> + + |
+