|
80 | 80 |
|
81 | 81 | case 'spam': |
82 | 82 | $user = get_userdata( $user_id ); |
| 83 | + if ( ! $user ) { |
| 84 | + continue; |
| 85 | + } |
83 | 86 | if ( is_super_admin( $user->ID ) ) { |
84 | 87 | wp_die( |
85 | 88 | sprintf( |
86 | 89 | /* translators: %s: User login. */ |
87 | 90 | __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), |
88 | 91 | esc_html( $user->user_login ) |
89 | | - ) |
| 92 | + ), |
| 93 | + 403 |
90 | 94 | ); |
91 | 95 | } |
92 | 96 |
|
93 | 97 | $userfunction = 'all_spam'; |
94 | | - $blogs = get_blogs_of_user( $user_id, true ); |
95 | 98 |
|
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 | + } |
99 | 112 | } |
100 | 113 | } |
101 | 114 |
|
|
107 | 120 |
|
108 | 121 | case 'notspam': |
109 | 122 | $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 | + } |
110 | 136 |
|
111 | 137 | $userfunction = 'all_notspam'; |
112 | | - $blogs = get_blogs_of_user( $user_id, true ); |
113 | 138 |
|
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 | + } |
116 | 146 | } |
117 | 147 |
|
118 | 148 | $user_data = $user->to_array(); |
|
0 commit comments