Skip to content

Commit 9b7a5f9

Browse files
authored
Prevent comment email notifications for ap_post (#2667)
1 parent 113bdb4 commit 9b7a5f9

File tree

3 files changed

+5
-59
lines changed

3 files changed

+5
-59
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: fixed
3+
4+
Prevent comment email notifications for ap_post.

includes/class-mailer.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace Activitypub;
99

1010
use Activitypub\Collection\Actors;
11-
use Activitypub\Collection\Posts;
1211

1312
/**
1413
* Mailer Class.
@@ -463,11 +462,6 @@ public static function maybe_prevent_comment_notification( $maybe_notify, $comme
463462
return $maybe_notify;
464463
}
465464

466-
// Only prevent if the create_posts option is enabled.
467-
if ( '1' !== \get_option( 'activitypub_create_posts', false ) ) {
468-
return $maybe_notify;
469-
}
470-
471465
$comment = \get_comment( $comment_id );
472466
if ( ! $comment ) {
473467
return $maybe_notify;
@@ -479,7 +473,7 @@ public static function maybe_prevent_comment_notification( $maybe_notify, $comme
479473
}
480474

481475
// Prevent notifications for comments on ap_post.
482-
if ( Posts::POST_TYPE === $post->post_type ) {
476+
if ( is_ap_post( $post ) ) {
483477
return false;
484478
}
485479

tests/phpunit/tests/includes/class-test-mailer.php

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,6 @@ public function test_mention_filters_recipients() {
993993
* @covers ::maybe_prevent_comment_notification
994994
*/
995995
public function test_prevent_email_notifications_for_ap_post_comments() {
996-
// Enable the create_posts option.
997-
\update_option( 'activitypub_create_posts', '1' );
998-
999996
// Create an ap_post.
1000997
$ap_post_id = self::factory()->post->create(
1001998
array(
@@ -1019,9 +1016,6 @@ public function test_prevent_email_notifications_for_ap_post_comments() {
10191016
// Test notify_moderator filter.
10201017
$notify_moderator = \apply_filters( 'notify_moderator', true, $comment_id );
10211018
$this->assertFalse( $notify_moderator, 'Email notifications to moderator should be prevented for ap_post comments' );
1022-
1023-
// Clean up.
1024-
\delete_option( 'activitypub_create_posts' );
10251019
}
10261020

10271021
/**
@@ -1030,9 +1024,6 @@ public function test_prevent_email_notifications_for_ap_post_comments() {
10301024
* @covers ::maybe_prevent_comment_notification
10311025
*/
10321026
public function test_allow_email_notifications_for_regular_post_comments() {
1033-
// Enable the create_posts option.
1034-
\update_option( 'activitypub_create_posts', '1' );
1035-
10361027
// Create a regular post.
10371028
$post_id = self::factory()->post->create(
10381029
array(
@@ -1055,43 +1046,6 @@ public function test_allow_email_notifications_for_regular_post_comments() {
10551046
// Test notify_moderator filter.
10561047
$notify_moderator = \apply_filters( 'notify_moderator', true, $comment_id );
10571048
$this->assertTrue( $notify_moderator, 'Email notifications to moderator should be allowed for regular post comments' );
1058-
1059-
// Clean up.
1060-
\delete_option( 'activitypub_create_posts' );
1061-
}
1062-
1063-
/**
1064-
* Test that email notifications are allowed for ap_post when option is disabled.
1065-
*
1066-
* @covers ::maybe_prevent_comment_notification
1067-
*/
1068-
public function test_allow_email_notifications_when_option_disabled() {
1069-
// Ensure the create_posts option is disabled.
1070-
\delete_option( 'activitypub_create_posts' );
1071-
1072-
// Create an ap_post.
1073-
$ap_post_id = self::factory()->post->create(
1074-
array(
1075-
'post_type' => 'ap_post',
1076-
'post_status' => 'publish',
1077-
)
1078-
);
1079-
1080-
// Create a comment on the ap_post.
1081-
$comment_id = self::factory()->comment->create(
1082-
array(
1083-
'comment_post_ID' => $ap_post_id,
1084-
'comment_approved' => '1',
1085-
)
1086-
);
1087-
1088-
// Test notify_post_author filter.
1089-
$notify_author = \apply_filters( 'notify_post_author', true, $comment_id );
1090-
$this->assertTrue( $notify_author, 'Email notifications should be allowed when option is disabled' );
1091-
1092-
// Test notify_moderator filter.
1093-
$notify_moderator = \apply_filters( 'notify_moderator', true, $comment_id );
1094-
$this->assertTrue( $notify_moderator, 'Email notifications should be allowed when option is disabled' );
10951049
}
10961050

10971051
/**
@@ -1100,9 +1054,6 @@ public function test_allow_email_notifications_when_option_disabled() {
11001054
* @covers ::maybe_prevent_comment_notification
11011055
*/
11021056
public function test_respect_existing_notification_settings() {
1103-
// Enable the create_posts option.
1104-
\update_option( 'activitypub_create_posts', '1' );
1105-
11061057
// Create an ap_post.
11071058
$ap_post_id = self::factory()->post->create(
11081059
array(
@@ -1125,9 +1076,6 @@ public function test_respect_existing_notification_settings() {
11251076

11261077
$notify_moderator = \apply_filters( 'notify_moderator', false, $comment_id );
11271078
$this->assertFalse( $notify_moderator, 'Should respect already disabled notifications' );
1128-
1129-
// Clean up.
1130-
\delete_option( 'activitypub_create_posts' );
11311079
}
11321080

11331081
/**

0 commit comments

Comments
 (0)