@@ -70,156 +70,166 @@ public function bulk_fields_dropdown( $which ) {
7070 public function load_users () {
7171 add_action ( 'restrict_manage_users ' ,[ $ this , 'bulk_fields_dropdown ' ], 5 );
7272
73- if ( isset ( $ _GET ['update ' ] ) ) {
74-
75- $ action = sanitize_key ( $ _GET ['update ' ] );
76- $ role = sanitize_key ( $ _GET ['role ' ] );
77- $ count = intval ( $ _GET ['count ' ] );
78- if ( 'wpum-role-added ' === $ action ) {
79- WPUM ()->notices ->register_notice ( 'wpum_role_added ' , 'success ' , sprintf ( '<b>%s</b> role added to <b>%d</b> %s. ' , ucwords ( $ role ), $ count , $ count > 1 ? 'users ' : 'user ' ), 'wp-user-manager ' );
80- } elseif ( 'wpum-role-removed ' === $ action ) {
81- WPUM ()->notices ->register_notice ( 'wpum_role_removed ' , 'success ' , sprintf ( '<b>%s</b> role removed from <b>%d</b> %s. ' , ucwords ( $ role ), $ count , $ count > 1 ? 'users ' : 'user ' ), 'wp-user-manager ' );
82- } elseif ( 'wpum-error-remove-admin ' === $ action ) {
83- WPUM ()->notices ->register_notice ( 'wpum_admin_error ' , 'error ' , sprintf ( 'You cannot remove <b>%s</b> role from your account. ' , ucwords ( $ role ) ), 'wp-user-manager ' );
84- }
73+ if ( ! isset ( $ _GET ['update ' ] ) ) {
74+ return ;
75+ }
76+
77+ $ action = sanitize_key ( $ _GET ['update ' ] );
78+ $ role = sanitize_key ( $ _GET ['name ' ] );
79+ $ count = intval ( $ _GET ['count ' ] );
80+ if ( 'wpum-role-added ' === $ action ) {
81+ WPUM ()->notices ->register_notice ( 'wpum_role_added ' , 'success ' , sprintf ( '<b>%s</b> role added to <b>%d</b> %s. ' , ucwords ( $ role ), $ count , $ count > 1 ? 'users ' : 'user ' ), 'wp-user-manager ' );
82+ } elseif ( 'wpum-role-removed ' === $ action ) {
83+ WPUM ()->notices ->register_notice ( 'wpum_role_removed ' , 'success ' , sprintf ( '<b>%s</b> role removed from <b>%d</b> %s. ' , ucwords ( $ role ), $ count , $ count > 1 ? 'users ' : 'user ' ), 'wp-user-manager ' );
84+ } elseif ( 'wpum-error-remove-admin ' === $ action ) {
85+ WPUM ()->notices ->register_notice ( 'wpum_admin_error ' , 'error ' , sprintf ( 'You cannot remove the <b>%s</b> role from your account. ' , ucwords ( $ role ) ), 'wp-user-manager ' );
8586 }
8687 }
8788
8889 public function load_users_role_bulk_add () {
89- if ( ! empty ( $ _REQUEST ['users ' ] ) ) {
90+ if ( empty ( $ _REQUEST ['users ' ] ) ) {
91+ return ;
92+ }
9093
91- if ( ! empty ( $ _REQUEST ['wpum-add-role-top ' ] ) && ! empty ( $ _REQUEST ['wpum-add-role-submit-top ' ] ) ) {
92- $ role = sanitize_text_field ( $ _REQUEST ['wpum-add-role-top ' ] );
93- } else if ( ! empty ( $ _REQUEST ['wpum-add-role-bottom ' ] ) && ! empty ( $ _REQUEST ['wpum-add-role-submit-bottom ' ] ) ) {
94- $ role = sanitize_text_field ( $ _REQUEST ['wpum-add-role-bottom ' ] );
95- }
94+ check_admin_referer ( 'wpum-bulk-users ' , 'wpum-bulk-users-nonce ' );
9695
97- $ m_role = wpum_get_role ( $ role );
98- $ roles = array_column ( wpum_get_roles ( false , true ), 'value ' );
96+ if ( ! current_user_can ( 'promote_users ' ) ) {
97+ return ;
98+ }
9999
100- if ( empty ( $ role ) || ! in_array ( $ role , $ roles ) ) {
101- return ;
102- }
100+ if ( ! empty ( $ _REQUEST ['wpum-add-role-top ' ] ) && ! empty ( $ _REQUEST ['wpum-add-role-submit-top ' ] ) ) {
101+ $ role = sanitize_text_field ( $ _REQUEST ['wpum-add-role-top ' ] );
102+ } else if ( ! empty ( $ _REQUEST ['wpum-add-role-bottom ' ] ) && ! empty ( $ _REQUEST ['wpum-add-role-submit-bottom ' ] ) ) {
103+ $ role = sanitize_text_field ( $ _REQUEST ['wpum-add-role-bottom ' ] );
104+ }
103105
104- check_admin_referer ( 'wpum-bulk-users ' , 'wpum-bulk-users-nonce ' );
106+ $ m_role = wpum_get_role ( $ role );
107+ $ roles = array_column ( wpum_get_roles ( false , true ), 'value ' );
105108
106- if ( ! current_user_can ( ' promote_users ' ) ) {
107- return ;
108- }
109+ if ( empty ( $ role ) || ! in_array ( $ role , $ roles ) ) {
110+ return ;
111+ }
109112
110- $ count = 0 ;
113+ $ count = 0 ;
111114
112- foreach ( (array ) $ _REQUEST ['users ' ] as $ user_id ) {
115+ foreach ( (array ) $ _REQUEST ['users ' ] as $ user_id ) {
113116
114- $ user_id = absint ( $ user_id );
115- if ( is_multisite () && ! is_user_member_of_blog ( $ user_id ) ) {
117+ $ user_id = absint ( $ user_id );
118+ if ( is_multisite () && ! is_user_member_of_blog ( $ user_id ) ) {
116119
117- wp_die ( sprintf ( '<h1>%s</h1> <p>%s</p> ' , esc_html__ ( 'One of the selected users is not a member of this site. ' , 'wp-user-manager ' ) ), 403 );
118- }
120+ wp_die ( sprintf ( '<h1>%s</h1> <p>%s</p> ' , esc_html__ ( 'One of the selected users is not a member of this site. ' , 'wp-user-manager ' ) ), 403 );
121+ }
119122
120- if ( ! current_user_can ( 'promote_user ' , $ user_id ) ) {
121- continue ;
122- }
123+ if ( ! current_user_can ( 'promote_user ' , $ user_id ) ) {
124+ continue ;
125+ }
123126
124- $ user = new \WP_User ( $ user_id );
127+ $ user = new \WP_User ( $ user_id );
125128
126- if ( ! in_array ( $ role , $ user ->roles ) ) {
127- $ user ->add_role ( $ role );
128- $ count ++;
129- }
129+ if ( ! in_array ( $ role , $ user ->roles ) ) {
130+ $ user ->add_role ( $ role );
131+ $ count ++;
130132 }
131- wp_redirect ( add_query_arg ( [ 'update ' => 'wpum-role-added ' , 'role ' => $ m_role ->label , 'count ' => $ count ], 'users.php ' ) );
132- exit ;
133133 }
134+ wp_redirect ( add_query_arg ( [
135+ 'update ' => 'wpum-role-added ' ,
136+ 'name ' => $ m_role ->label ,
137+ 'count ' => $ count ,
138+ ], 'users.php ' ) );
139+
140+ exit ;
134141 }
135142
136143 public function load_users_role_bulk_remove () {
144+ if ( empty ( $ _REQUEST ['users ' ] ) ) {
145+ return ;
146+ }
137147
138- if ( ! empty ( $ _REQUEST ['users ' ] ) ) {
139-
140- if ( ! empty ( $ _REQUEST ['wpum-remove-role-top ' ] ) && ! empty ( $ _REQUEST ['wpum-remove-role-submit-top ' ] ) ) {
141- $ role = sanitize_text_field ( $ _REQUEST ['wpum-remove-role-top ' ] );
142- } elseif ( ! empty ( $ _REQUEST ['wpum-remove-role-bottom ' ] ) && ! empty ( $ _REQUEST ['wpum-remove-role-submit-bottom ' ] ) ) {
143- $ role = sanitize_text_field ( $ _REQUEST ['wpum-remove-role-bottom ' ] );
144- }
145-
148+ check_admin_referer ( 'wpum-bulk-users ' , 'wpum-bulk-users-nonce ' );
146149
147- $ roles = array_column ( wpum_get_roles (), 'value ' );
150+ if ( ! current_user_can ( 'promote_users ' ) ) {
151+ return ;
152+ }
148153
149- if ( empty ( $ role ) || ! in_array ( $ role , $ roles ) ) {
150- return ;
151- }
154+ if ( ! empty ( $ _REQUEST ['wpum-remove-role-top ' ] ) && ! empty ( $ _REQUEST ['wpum-remove-role-submit-top ' ] ) ) {
155+ $ role = sanitize_text_field ( $ _REQUEST ['wpum-remove-role-top ' ] );
156+ } elseif ( ! empty ( $ _REQUEST ['wpum-remove-role-bottom ' ] ) && ! empty ( $ _REQUEST ['wpum-remove-role-submit-bottom ' ] ) ) {
157+ $ role = sanitize_text_field ( $ _REQUEST ['wpum-remove-role-bottom ' ] );
158+ }
152159
153- check_admin_referer ( ' wpum-bulk-users ' , 'wpum-bulk-users-nonce ' );
160+ $ roles = array_column ( wpum_get_roles () , 'value ' );
154161
155- if ( ! current_user_can ( ' promote_users ' ) ) {
156- return ;
157- }
162+ if ( empty ( $ role ) || ! in_array ( $ role , $ roles ) ) {
163+ return ;
164+ }
158165
159- $ current_user = wp_get_current_user ();
160- $ m_role = wpum_get_role ( $ role );
161- $ update = 'wpum-role-removed ' ;
166+ $ current_user = wp_get_current_user ();
167+ $ m_role = wpum_get_role ( $ role );
168+ $ update = 'wpum-role-removed ' ;
162169
163- $ count = 0 ;
170+ $ count = 0 ;
164171
165- foreach ( (array ) $ _REQUEST ['users ' ] as $ user_id ) {
172+ foreach ( (array ) $ _REQUEST ['users ' ] as $ user_id ) {
166173
167- $ user_id = absint ( $ user_id );
174+ $ user_id = absint ( $ user_id );
168175
169- if ( is_multisite () && ! is_user_member_of_blog ( $ user_id ) ) {
176+ if ( is_multisite () && ! is_user_member_of_blog ( $ user_id ) ) {
170177
171- wp_die ( sprintf ( '<h1>%s</h1> <p>%s</p> ' , esc_html__ ( 'One of the selected users is not a member of this site. ' , 'wp-user-manager ' ) ), 403 );
172- }
178+ wp_die ( sprintf ( '<h1>%s</h1> <p>%s</p> ' , esc_html__ ( 'One of the selected users is not a member of this site. ' , 'wp-user-manager ' ) ), 403 );
179+ }
173180
174- if ( ! current_user_can ( 'promote_user ' , $ user_id ) ) {
175- continue ;
176- }
181+ if ( ! current_user_can ( 'promote_user ' , $ user_id ) ) {
182+ continue ;
183+ }
177184
178- $ is_current_user = $ user_id == $ current_user ->ID ;
179- $ role_can_promote = in_array ( 'promote_users ' , $ m_role ->granted_caps );
180- $ can_manage_network = is_multisite () && current_user_can ( 'manage_network_users ' );
185+ $ is_current_user = $ user_id == $ current_user ->ID ;
186+ $ role_can_promote = in_array ( 'promote_users ' , $ m_role ->granted_caps );
187+ $ can_manage_network = is_multisite () && current_user_can ( 'manage_network_users ' );
181188
182- if ( $ is_current_user && $ role_can_promote && ! $ can_manage_network ) {
183- $ can_remove = false ;
189+ if ( $ is_current_user && $ role_can_promote && ! $ can_manage_network ) {
190+ $ can_remove = false ;
184191
185- foreach ( $ current_user ->roles as $ _r ) {
192+ foreach ( $ current_user ->roles as $ _r ) {
186193
187- if ( $ role !== $ _r && in_array ( 'promote_users ' , wpum_get_role ( $ _r )->granted_caps ) ) {
194+ if ( $ role !== $ _r && in_array ( 'promote_users ' , wpum_get_role ( $ _r )->granted_caps ) ) {
188195
189- $ can_remove = true ;
190- break ;
191- }
196+ $ can_remove = true ;
197+ break ;
192198 }
199+ }
193200
194- if ( ! $ can_remove ) {
195- $ update = 'wpum-error-remove-admin ' ;
196- continue ;
197- }
201+ if ( ! $ can_remove ) {
202+ $ update = 'wpum-error-remove-admin ' ;
203+ continue ;
198204 }
205+ }
199206
200- $ user = new \WP_User ( $ user_id );
207+ $ user = new \WP_User ( $ user_id );
201208
202- if ( in_array ( $ role , $ user ->roles ) ) {
203- $ user ->remove_role ( $ role );
204- $ count ++;
205- }
209+ if ( in_array ( $ role , $ user ->roles ) ) {
210+ $ user ->remove_role ( $ role );
211+ $ count ++;
206212 }
207- wp_redirect ( add_query_arg ( [ 'update ' => $ update , 'role ' => $ m_role ->label , 'count ' => $ count ], 'users.php ' ) );
208- exit ;
209213 }
214+ wp_redirect ( add_query_arg ( [
215+ 'update ' => $ update ,
216+ 'name ' => $ m_role ->label ,
217+ 'count ' => $ count ,
218+ ], 'users.php ' ) );
219+
220+ exit ;
210221 }
211222
212223 /**
213224 * Add the user id column.
214225 *
215226 * @param array $columns
216- * @return void
227+ * @return array
217228 */
218229 public function add_user_id_column ( $ columns ) {
219-
220230 $ columns ['user_id ' ] = __ ( 'ID ' , 'wp-user-manager ' );
221- return $ columns ;
222231
232+ return $ columns ;
223233 }
224234
225235 /**
@@ -228,12 +238,13 @@ public function add_user_id_column( $columns ) {
228238 * @param string $value
229239 * @param string $column_name
230240 * @param int $user_id
231- * @return void
241+ * @return mixed
232242 */
233243 public function show_user_id ( $ value , $ column_name , $ user_id ) {
234244 if ( 'user_id ' == $ column_name ) {
235245 return $ user_id ;
236246 }
247+
237248 return $ value ;
238249 }
239250
0 commit comments