Skip to content

Commit e337521

Browse files
committed
Proposal to use a short circuit filter
1 parent 4356848 commit e337521

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

src/wp-admin/network/users.php

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,21 @@
9191
}
9292

9393
$userfunction = 'all_spam';
94-
$blogs = get_blogs_of_user( $user_id, true );
9594

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' );
95+
/**
96+
* Filters whether the blog status for all of a user's blogs should be updated.
97+
*
98+
* @since 6.7
99+
*
100+
* @param bool $update_blog_status Whether to update the blog status. Default true.
101+
*/
102+
if ( apply_filters( 'handle_allusers_update_blog_status', true ) ) {
103+
$blogs = get_blogs_of_user( $user_id, true );
104+
105+
foreach ( (array) $blogs as $details ) {
106+
if ( ! is_main_site( $details->userblog_id ) ) { // Main site is not a spam!
107+
update_blog_status( $details->userblog_id, 'spam', '1' );
108+
}
99109
}
100110
}
101111

@@ -107,12 +117,27 @@
107117

108118
case 'notspam':
109119
$user = get_userdata( $user_id );
120+
if ( is_super_admin( $user->ID ) ) {
121+
wp_die(
122+
sprintf(
123+
/* translators: %s: User login. */
124+
__( 'Warning! User cannot be modified. The user %s is a network administrator.' ),
125+
esc_html( $user->user_login )
126+
)
127+
);
128+
}
110129

111130
$userfunction = 'all_notspam';
112-
$blogs = get_blogs_of_user( $user_id, true );
113131

114-
foreach ( (array) $blogs as $details ) {
115-
update_blog_status( $details->userblog_id, 'spam', '0' );
132+
/** This filter is documented in wp-admin/network/users.php#L95 */
133+
if ( apply_filters( 'handle_allusers_blog_status', true ) ) {
134+
$blogs = get_blogs_of_user( $user_id, true );
135+
136+
foreach ( (array) $blogs as $details ) {
137+
if ( ! is_main_site( $details->userblog_id ) ) { // Main site is never a spam!
138+
update_blog_status( $details->userblog_id, 'spam', '0' );
139+
}
140+
}
116141
}
117142

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

0 commit comments

Comments
 (0)