25 } |
25 } |
26 |
26 |
27 check_admin_referer( 'deleteuser' ); |
27 check_admin_referer( 'deleteuser' ); |
28 |
28 |
29 $id = intval( $_GET['id'] ); |
29 $id = intval( $_GET['id'] ); |
30 if ( $id != '0' && $id != '1' ) { |
30 if ( $id > 1 ) { |
31 $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays |
31 $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle arrays. |
32 $title = __( 'Users' ); |
32 $title = __( 'Users' ); |
33 $parent_file = 'users.php'; |
33 $parent_file = 'users.php'; |
34 require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
34 require_once ABSPATH . 'wp-admin/admin-header.php'; |
35 echo '<div class="wrap">'; |
35 echo '<div class="wrap">'; |
36 confirm_delete_users( $_POST['allusers'] ); |
36 confirm_delete_users( $_POST['allusers'] ); |
37 echo '</div>'; |
37 echo '</div>'; |
38 require_once( ABSPATH . 'wp-admin/admin-footer.php' ); |
38 require_once ABSPATH . 'wp-admin/admin-footer.php'; |
39 } else { |
39 } else { |
40 wp_redirect( network_admin_url( 'users.php' ) ); |
40 wp_redirect( network_admin_url( 'users.php' ) ); |
41 } |
41 } |
42 exit(); |
42 exit; |
43 |
43 |
44 case 'allusers': |
44 case 'allusers': |
45 if ( ! current_user_can( 'manage_network_users' ) ) { |
45 if ( ! current_user_can( 'manage_network_users' ) ) { |
46 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
46 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
47 } |
47 } |
48 |
48 |
49 if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) { |
49 if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) { |
50 check_admin_referer( 'bulk-users-network' ); |
50 check_admin_referer( 'bulk-users-network' ); |
51 |
51 |
52 $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2']; |
52 $doaction = -1 != $_POST['action'] ? $_POST['action'] : $_POST['action2']; |
53 $userfunction = ''; |
53 $userfunction = ''; |
54 |
54 |
55 foreach ( (array) $_POST['allusers'] as $user_id ) { |
55 foreach ( (array) $_POST['allusers'] as $user_id ) { |
56 if ( ! empty( $user_id ) ) { |
56 if ( ! empty( $user_id ) ) { |
57 switch ( $doaction ) { |
57 switch ( $doaction ) { |
59 if ( ! current_user_can( 'delete_users' ) ) { |
59 if ( ! current_user_can( 'delete_users' ) ) { |
60 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
60 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
61 } |
61 } |
62 $title = __( 'Users' ); |
62 $title = __( 'Users' ); |
63 $parent_file = 'users.php'; |
63 $parent_file = 'users.php'; |
64 require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
64 require_once ABSPATH . 'wp-admin/admin-header.php'; |
65 echo '<div class="wrap">'; |
65 echo '<div class="wrap">'; |
66 confirm_delete_users( $_POST['allusers'] ); |
66 confirm_delete_users( $_POST['allusers'] ); |
67 echo '</div>'; |
67 echo '</div>'; |
68 require_once( ABSPATH . 'wp-admin/admin-footer.php' ); |
68 require_once ABSPATH . 'wp-admin/admin-footer.php'; |
69 exit(); |
69 exit; |
70 |
70 |
71 case 'spam': |
71 case 'spam': |
72 $user = get_userdata( $user_id ); |
72 $user = get_userdata( $user_id ); |
73 if ( is_super_admin( $user->ID ) ) { |
73 if ( is_super_admin( $user->ID ) ) { |
74 wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) ); |
74 wp_die( |
|
75 sprintf( |
|
76 /* translators: %s: User login. */ |
|
77 __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), |
|
78 esc_html( $user->user_login ) |
|
79 ) |
|
80 ); |
75 } |
81 } |
76 |
82 |
77 $userfunction = 'all_spam'; |
83 $userfunction = 'all_spam'; |
78 $blogs = get_blogs_of_user( $user_id, true ); |
84 $blogs = get_blogs_of_user( $user_id, true ); |
|
85 |
79 foreach ( (array) $blogs as $details ) { |
86 foreach ( (array) $blogs as $details ) { |
80 if ( $details->userblog_id != get_network()->site_id ) { // main blog not a spam ! |
87 if ( get_network()->site_id != $details->userblog_id ) { // Main blog is not a spam! |
81 update_blog_status( $details->userblog_id, 'spam', '1' ); |
88 update_blog_status( $details->userblog_id, 'spam', '1' ); |
82 } |
89 } |
83 } |
90 } |
84 update_user_status( $user_id, 'spam', '1' ); |
91 |
|
92 $user_data = $user->to_array(); |
|
93 $user_data['spam'] = '1'; |
|
94 |
|
95 wp_update_user( $user_data ); |
85 break; |
96 break; |
86 |
97 |
87 case 'notspam': |
98 case 'notspam': |
|
99 $user = get_userdata( $user_id ); |
|
100 |
88 $userfunction = 'all_notspam'; |
101 $userfunction = 'all_notspam'; |
89 $blogs = get_blogs_of_user( $user_id, true ); |
102 $blogs = get_blogs_of_user( $user_id, true ); |
|
103 |
90 foreach ( (array) $blogs as $details ) { |
104 foreach ( (array) $blogs as $details ) { |
91 update_blog_status( $details->userblog_id, 'spam', '0' ); |
105 update_blog_status( $details->userblog_id, 'spam', '0' ); |
92 } |
106 } |
93 |
107 |
94 update_user_status( $user_id, 'spam', '0' ); |
108 $user_data = $user->to_array(); |
|
109 $user_data['spam'] = '0'; |
|
110 |
|
111 wp_update_user( $user_data ); |
95 break; |
112 break; |
96 } |
113 } |
97 } |
114 } |
98 } |
115 } |
99 |
116 |
100 if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) { |
117 if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) { |
101 $sendback = wp_get_referer(); |
118 $sendback = wp_get_referer(); |
102 |
|
103 $user_ids = (array) $_POST['allusers']; |
119 $user_ids = (array) $_POST['allusers']; |
|
120 |
104 /** This action is documented in wp-admin/network/site-themes.php */ |
121 /** This action is documented in wp-admin/network/site-themes.php */ |
105 $sendback = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids ); |
122 $sendback = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
106 |
123 |
107 wp_safe_redirect( $sendback ); |
124 wp_safe_redirect( $sendback ); |
108 exit(); |
125 exit; |
109 } |
126 } |
110 |
127 |
111 wp_safe_redirect( |
128 wp_safe_redirect( |
112 add_query_arg( |
129 add_query_arg( |
113 array( |
130 array( |
123 if ( ! empty( $_REQUEST['paged'] ) ) { |
140 if ( ! empty( $_REQUEST['paged'] ) ) { |
124 $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location ); |
141 $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location ); |
125 } |
142 } |
126 wp_redirect( $location ); |
143 wp_redirect( $location ); |
127 } |
144 } |
128 exit(); |
145 exit; |
129 |
146 |
130 case 'dodelete': |
147 case 'dodelete': |
131 check_admin_referer( 'ms-users-delete' ); |
148 check_admin_referer( 'ms-users-delete' ); |
132 if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) ) { |
149 if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) ) { |
133 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
150 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
138 foreach ( $users as $blogid => $user_id ) { |
155 foreach ( $users as $blogid => $user_id ) { |
139 if ( ! current_user_can( 'delete_user', $id ) ) { |
156 if ( ! current_user_can( 'delete_user', $id ) ) { |
140 continue; |
157 continue; |
141 } |
158 } |
142 |
159 |
143 if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][ $blogid ][ $id ] ) { |
160 if ( ! empty( $_POST['delete'] ) && 'reassign' === $_POST['delete'][ $blogid ][ $id ] ) { |
144 remove_user_from_blog( $id, $blogid, $user_id ); |
161 remove_user_from_blog( $id, $blogid, (int) $user_id ); |
145 } else { |
162 } else { |
146 remove_user_from_blog( $id, $blogid ); |
163 remove_user_from_blog( $id, $blogid ); |
147 } |
164 } |
148 } |
165 } |
149 } |
166 } |
150 } |
167 } |
|
168 |
151 $i = 0; |
169 $i = 0; |
|
170 |
152 if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) { |
171 if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) { |
153 foreach ( $_POST['user'] as $id ) { |
172 foreach ( $_POST['user'] as $id ) { |
154 if ( ! current_user_can( 'delete_user', $id ) ) { |
173 if ( ! current_user_can( 'delete_user', $id ) ) { |
155 continue; |
174 continue; |
156 } |
175 } |
157 wpmu_delete_user( $id ); |
176 wpmu_delete_user( $id ); |
158 $i++; |
177 $i++; |
159 } |
178 } |
160 } |
179 } |
161 |
180 |
162 if ( $i == 1 ) { |
181 if ( 1 === $i ) { |
163 $deletefunction = 'delete'; |
182 $deletefunction = 'delete'; |
164 } else { |
183 } else { |
165 $deletefunction = 'all_delete'; |
184 $deletefunction = 'all_delete'; |
166 } |
185 } |
167 |
186 |