diff --git a/.github/changelog/add-reaction-email-setting b/.github/changelog/add-reaction-email-setting new file mode 100644 index 0000000000..fd44a91261 --- /dev/null +++ b/.github/changelog/add-reaction-email-setting @@ -0,0 +1,4 @@ +Significance: minor +Type: added + +Add a notification setting to turn off emails about likes, reposts, and quotes without silencing real comments and replies. diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index e73ebf5405..2252ee8cbc 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -295,6 +295,18 @@ public static function register_user_meta() { ); \add_filter( 'get_user_option_activitypub_mailer_new_mention', array( self::class, 'user_options_default' ) ); + \register_meta( + 'user', + $blog_prefix . 'activitypub_mailer_new_reaction', + array( + 'type' => 'integer', + 'description' => 'Send a notification when someone likes, reposts, or quotes this user\'s post.', + 'single' => true, + 'sanitize_callback' => 'absint', + ) + ); + \add_filter( 'get_user_option_activitypub_mailer_new_reaction', array( self::class, 'user_options_default' ) ); + \register_meta( 'user', $blog_prefix . 'activitypub_mailer_annual_report', diff --git a/includes/class-mailer.php b/includes/class-mailer.php index 46c0e49665..fb400f8235 100644 --- a/includes/class-mailer.php +++ b/includes/class-mailer.php @@ -8,6 +8,7 @@ namespace Activitypub; use Activitypub\Collection\Actors; +use Activitypub\Comment; /** * Mailer Class. @@ -26,6 +27,7 @@ public static function init() { \add_action( 'activitypub_inbox_create', array( self::class, 'mention' ), 20, 2 ); /** After @see \Activitypub\Handler\Create::handle_create() */ \add_filter( 'notify_post_author', array( self::class, 'maybe_prevent_comment_notification' ), 10, 2 ); + \add_filter( 'notify_post_author', array( self::class, 'maybe_prevent_reaction_notification' ), 10, 2 ); \add_filter( 'notify_moderator', array( self::class, 'maybe_prevent_comment_notification' ), 10, 2 ); } @@ -554,4 +556,38 @@ public static function maybe_prevent_comment_notification( $maybe_notify, $comme return $maybe_notify; } + + /** + * Let the post author mute email about reactions to their post. + * + * Likes, reposts, and quotes are stored as comments, so WordPress emails the post author about + * them like any other comment. This is hooked on `notify_post_author` only, so it never affects + * the moderator notification, and it targets the plugin's own reaction comment types so pingbacks, + * trackbacks, and plain replies keep notifying as usual. The preference defaults to on. + * + * @since unreleased + * + * @param bool $maybe_notify Whether to send the notification. + * @param int $comment_id The comment ID. + * + * @return bool Whether to send the notification. + */ + public static function maybe_prevent_reaction_notification( $maybe_notify, $comment_id ) { + // If already disabled, respect that. + if ( ! $maybe_notify ) { + return $maybe_notify; + } + + $comment = \get_comment( $comment_id ); + if ( ! $comment || ! \in_array( \get_comment_type( $comment ), Comment::get_comment_type_slugs(), true ) ) { + return $maybe_notify; + } + + $post = \get_post( $comment->comment_post_ID ); + if ( ! $post ) { + return $maybe_notify; + } + + return (bool) \get_user_option( 'activitypub_mailer_new_reaction', $post->post_author ); + } } diff --git a/includes/wp-admin/class-admin.php b/includes/wp-admin/class-admin.php index 0477eb06aa..dc518c9c63 100644 --- a/includes/wp-admin/class-admin.php +++ b/includes/wp-admin/class-admin.php @@ -260,6 +260,7 @@ public static function save_user_settings( $user_id ) { 'activitypub_mailer_new_dm', 'activitypub_mailer_new_follower', 'activitypub_mailer_new_mention', + 'activitypub_mailer_new_reaction', 'activitypub_mailer_annual_report', 'activitypub_mailer_monthly_report', ); diff --git a/includes/wp-admin/class-user-settings-fields.php b/includes/wp-admin/class-user-settings-fields.php index b9a3612e05..8ec417041f 100644 --- a/includes/wp-admin/class-user-settings-fields.php +++ b/includes/wp-admin/class-user-settings-fields.php @@ -253,6 +253,12 @@ public static function notifications_callback() {

+

+ +