Skip to content

Commit 2bcd212

Browse files
author
Pratik Nawkar
committed
Multisite: Do not propagate user spam to sites by default. Adds propagate_network_user_spam_to_blogs filter and unit tests. Fixes #61146.
1 parent 785e61f commit 2bcd212

File tree

2 files changed

+427
-8
lines changed

2 files changed

+427
-8
lines changed

src/wp-admin/network/users.php

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,22 +80,35 @@
8080

8181
case 'spam':
8282
$user = get_userdata( $user_id );
83+
if ( ! $user ) {
84+
continue;
85+
}
8386
if ( is_super_admin( $user->ID ) ) {
8487
wp_die(
8588
sprintf(
8689
/* translators: %s: User login. */
8790
__( 'Warning! User cannot be modified. The user %s is a network administrator.' ),
8891
esc_html( $user->user_login )
89-
)
92+
),
93+
403
9094
);
9195
}
9296

9397
$userfunction = 'all_spam';
94-
$blogs = get_blogs_of_user( $user_id, true );
9598

96-
foreach ( (array) $blogs as $details ) {
97-
if ( ! is_main_site( $details->userblog_id ) ) { // Main site is not a spam!
98-
update_blog_status( $details->userblog_id, 'spam', '1' );
99+
/**
100+
* Filters whether to propagate the blog status when a user is marked as spam.
101+
*
102+
* @since 7.0.0
103+
*
104+
* @param bool $propagate Whether to propagate the blog status. Default false.
105+
* @param int $user_id User ID.
106+
*/
107+
if ( apply_filters( 'propagate_network_user_spam_to_blogs', false, $user_id ) ) {
108+
foreach ( get_blogs_of_user( $user_id, true ) as $details ) {
109+
if ( ! is_main_site( $details->userblog_id ) ) { // Main site is not a spam!
110+
update_blog_status( $details->userblog_id, 'spam', '1' );
111+
}
99112
}
100113
}
101114

@@ -107,12 +120,29 @@
107120

108121
case 'notspam':
109122
$user = get_userdata( $user_id );
123+
if ( ! $user ) {
124+
continue;
125+
}
126+
if ( is_super_admin( $user->ID ) ) {
127+
wp_die(
128+
sprintf(
129+
/* translators: %s: User login. */
130+
__( 'Warning! User cannot be modified. The user %s is a network administrator.' ),
131+
esc_html( $user->user_login )
132+
),
133+
403
134+
);
135+
}
110136

111137
$userfunction = 'all_notspam';
112-
$blogs = get_blogs_of_user( $user_id, true );
113138

114-
foreach ( (array) $blogs as $details ) {
115-
update_blog_status( $details->userblog_id, 'spam', '0' );
139+
/** This filter is documented in wp-admin/network/users.php */
140+
if ( apply_filters( 'propagate_network_user_spam_to_blogs', false, $user_id ) ) {
141+
foreach ( get_blogs_of_user( $user_id, true ) as $details ) {
142+
if ( ! is_main_site( $details->userblog_id ) && get_current_network_id() === $details->site_id ) { // Main site is never a spam and part of the current network.
143+
update_blog_status( $details->userblog_id, 'spam', '0' );
144+
}
145+
}
116146
}
117147

118148
$user_data = $user->to_array();

0 commit comments

Comments
 (0)