Skip to content

Commit d7ddd86

Browse files
committed
- update notification message
1 parent 246da30 commit d7ddd86

File tree

1 file changed

+86
-79
lines changed

1 file changed

+86
-79
lines changed

includes/wpum-admin/class-wpum-user-table.php

Lines changed: 86 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -71,135 +71,142 @@ public function load_users() {
7171
add_action( 'restrict_manage_users',[ $this, 'bulk_fields_dropdown' ], 5 );
7272

7373
if ( isset( $_GET['update'] ) ) {
74-
$action = sanitize_key( $_GET['update'] );
7574

75+
$action = sanitize_key( $_GET['update'] );
76+
$role = sanitize_key( $_GET['role'] );
77+
$count = intval( $_GET['count'] );
7678
if ( 'wpum-role-added' === $action ) {
77-
WPUM()->notices->register_notice( 'wpum_db_upgrade_completed', 'success', esc_html__( 'Role added to selected users.', 'wp-user-manager' ) );
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' );
7880
} elseif ( 'wpum-role-removed' === $action ) {
79-
WPUM()->notices->register_notice( 'wpum_db_upgrade_completed', 'success', esc_html__( 'Role removed from selected users.', 'wp-user-manager' ) );
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' );
8082
} elseif ( 'wpum-error-remove-admin' === $action ) {
81-
WPUM()->notices->register_notice( 'wpum_db_upgrade_completed', 'success', esc_html__( 'Role removed from other selected users.', 'wp-user-manager' ) );
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' );
8284
}
8385
}
8486
}
8587

8688
public function load_users_role_bulk_add() {
87-
if ( empty( $_REQUEST['users'] ) ) {
88-
return;
89-
}
89+
if ( ! empty( $_REQUEST['users'] ) ) {
9090

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-
}
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+
}
9696

97-
$roles = array_column( wpum_get_roles( false, true ), 'value' );
97+
$m_role = wpum_get_role( $role );
98+
$roles = array_column( wpum_get_roles( false, true ), 'value' );
9899

99-
if ( empty( $role ) || ! in_array( $role, $roles ) ) {
100-
return;
101-
}
100+
if ( empty( $role ) || ! in_array( $role, $roles ) ) {
101+
return;
102+
}
102103

103-
check_admin_referer( 'wpum-bulk-users', 'wpum-bulk-users-nonce' );
104+
check_admin_referer( 'wpum-bulk-users', 'wpum-bulk-users-nonce' );
104105

105-
if ( ! current_user_can( 'promote_users' ) ) {
106-
return;
107-
}
106+
if ( ! current_user_can( 'promote_users' ) ) {
107+
return;
108+
}
108109

109-
foreach ( (array) $_REQUEST['users'] as $user_id ) {
110+
$count = 0;
110111

111-
$user_id = absint( $user_id );
112-
if ( is_multisite() && ! is_user_member_of_blog( $user_id ) ) {
112+
foreach ( (array) $_REQUEST['users'] as $user_id ) {
113113

114-
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 );
115-
}
114+
$user_id = absint( $user_id );
115+
if ( is_multisite() && ! is_user_member_of_blog( $user_id ) ) {
116116

117-
if ( ! current_user_can( 'promote_user', $user_id ) ) {
118-
continue;
119-
}
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+
}
120119

121-
$user = new \WP_User( $user_id );
120+
if ( ! current_user_can( 'promote_user', $user_id ) ) {
121+
continue;
122+
}
123+
124+
$user = new \WP_User( $user_id );
122125

123-
if ( ! in_array( $role, $user->roles ) ) {
124-
$user->add_role( $role );
126+
if ( ! in_array( $role, $user->roles ) ) {
127+
$user->add_role( $role );
128+
$count++;
129+
}
125130
}
131+
wp_redirect( add_query_arg( [ 'update' => 'wpum-role-added', 'role' => $m_role->label, 'count' => $count ], 'users.php' ) );
132+
exit;
126133
}
127-
128-
wp_redirect( add_query_arg( 'update', 'wpum-role-added', 'users.php' ) );
129134
}
130135

131136
public function load_users_role_bulk_remove() {
132137

133-
if ( empty( $_REQUEST['users'] ) ) {
134-
return;
135-
}
138+
if ( ! empty( $_REQUEST['users'] ) ) {
136139

137-
if ( ! empty( $_REQUEST['wpum-remove-role-top'] ) && ! empty( $_REQUEST['wpum-remove-role-submit-top'] ) ) {
138-
$role = sanitize_text_field( $_REQUEST['wpum-remove-role-top'] );
139-
} elseif ( ! empty( $_REQUEST['wpum-remove-role-bottom'] ) && ! empty( $_REQUEST['wpum-remove-role-submit-bottom'] ) ) {
140-
$role = sanitize_text_field( $_REQUEST['wpum-remove-role-bottom'] );
141-
}
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+
}
142145

143146

144-
$roles = array_column( wpum_get_roles(), 'value' );
147+
$roles = array_column( wpum_get_roles(), 'value' );
145148

146-
if ( empty( $role ) || ! in_array( $role, $roles ) ) {
147-
return;
148-
}
149+
if ( empty( $role ) || ! in_array( $role, $roles ) ) {
150+
return;
151+
}
149152

150-
check_admin_referer( 'wpum-bulk-users', 'wpum-bulk-users-nonce' );
153+
check_admin_referer( 'wpum-bulk-users', 'wpum-bulk-users-nonce' );
151154

152-
if ( ! current_user_can( 'promote_users' ) ) {
153-
return;
154-
}
155+
if ( ! current_user_can( 'promote_users' ) ) {
156+
return;
157+
}
155158

156-
$current_user = wp_get_current_user();
157-
$m_role = wpum_get_role( $role );
158-
$update = 'wpum-role-removed';
159+
$current_user = wp_get_current_user();
160+
$m_role = wpum_get_role( $role );
161+
$update = 'wpum-role-removed';
159162

160-
foreach ( (array) $_REQUEST['users'] as $user_id ) {
163+
$count = 0;
161164

162-
$user_id = absint( $user_id );
165+
foreach ( (array) $_REQUEST['users'] as $user_id ) {
163166

164-
if ( is_multisite() && ! is_user_member_of_blog( $user_id ) ) {
167+
$user_id = absint( $user_id );
165168

166-
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 );
167-
}
169+
if ( is_multisite() && ! is_user_member_of_blog( $user_id ) ) {
168170

169-
if ( ! current_user_can( 'promote_user', $user_id ) ) {
170-
continue;
171-
}
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+
}
173+
174+
if ( ! current_user_can( 'promote_user', $user_id ) ) {
175+
continue;
176+
}
172177

173-
$is_current_user = $user_id == $current_user->ID;
174-
$role_can_promote = in_array( 'promote_users', $m_role->granted_caps );
175-
$can_manage_network = is_multisite() && current_user_can( 'manage_network_users' );
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' );
176181

177-
if ( $is_current_user && $role_can_promote && ! $can_manage_network ) {
178-
$can_remove = false;
182+
if ( $is_current_user && $role_can_promote && ! $can_manage_network ) {
183+
$can_remove = false;
179184

180-
foreach ( $current_user->roles as $_r ) {
185+
foreach ( $current_user->roles as $_r ) {
181186

182-
if ( $role !== $_r && in_array( 'promote_users', wpum_get_role( $_r )->granted_caps ) ) {
187+
if ( $role !== $_r && in_array( 'promote_users', wpum_get_role( $_r )->granted_caps ) ) {
183188

184-
$can_remove = true;
185-
break;
189+
$can_remove = true;
190+
break;
191+
}
186192
}
187-
}
188193

189-
if ( ! $can_remove ) {
190-
$update = 'wpum-error-remove-admin';
191-
continue;
194+
if ( ! $can_remove ) {
195+
$update = 'wpum-error-remove-admin';
196+
continue;
197+
}
192198
}
193-
}
194199

195-
$user = new \WP_User( $user_id );
200+
$user = new \WP_User( $user_id );
196201

197-
if ( in_array( $role, $user->roles ) ) {
198-
$user->remove_role( $role );
202+
if ( in_array( $role, $user->roles ) ) {
203+
$user->remove_role( $role );
204+
$count++;
205+
}
199206
}
207+
wp_redirect( add_query_arg( [ 'update' => $update, 'role' => $m_role->label, 'count' => $count ], 'users.php' ) );
208+
exit;
200209
}
201-
202-
wp_redirect( add_query_arg( 'update', $update, 'users.php' ) );
203210
}
204211

205212
/**

0 commit comments

Comments
 (0)