Skip to content

Commit c30a60c

Browse files
committed
Networks and Sites: prevent a PHP error in wp-admin/network/site-users.php.
This change brings the multisite specific `promote` user action up-to-speed with the single-site one, by adding: * capability checks where appropriate * a `none` check on `$role` to set it to an empty string It also updates the inline documentation of the single-site `promote` user action in `users.php`, to match the suggested additions to the multisite file. Props ignatiusjeroe, jeremyfelt, johnjamesjacoby, pratiklondhe, shanemuir, sudipatel007, techpartho. Fixes #61100. git-svn-id: https://develop.svn.wordpress.org/trunk@60976 602fd350-edb4-49c9-b593-d223f7449a82
1 parent d445d39 commit c30a60c

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/wp-admin/network/site-users.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,37 @@
139139

140140
case 'promote':
141141
check_admin_referer( 'bulk-users' );
142+
143+
if ( ! current_user_can( 'promote_users' ) ) {
144+
wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 );
145+
}
146+
142147
$editable_roles = get_editable_roles();
143148
$role = $_REQUEST['new_role'];
144149

150+
// Mock `none` as editable role.
151+
$editable_roles['none'] = array(
152+
'name' => __( '— No role for this site —' ),
153+
);
154+
145155
if ( empty( $editable_roles[ $role ] ) ) {
146156
wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
147157
}
148158

159+
if ( 'none' === $role ) {
160+
$role = '';
161+
}
162+
149163
if ( isset( $_REQUEST['users'] ) ) {
150164
$userids = $_REQUEST['users'];
151165
$update = 'promote';
152166
foreach ( $userids as $user_id ) {
153167
$user_id = (int) $user_id;
154168

169+
if ( ! current_user_can( 'promote_user', $user_id ) ) {
170+
wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 );
171+
}
172+
155173
// If the user doesn't already belong to the blog, bail.
156174
if ( ! is_user_member_of_blog( $user_id ) ) {
157175
wp_die(
@@ -162,6 +180,8 @@
162180
}
163181

164182
$user = get_userdata( $user_id );
183+
184+
// If $role is empty, none will be set.
165185
$user->set_role( $role );
166186
}
167187
} else {

src/wp-admin/users.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@
122122
$editable_roles = get_editable_roles();
123123
$role = $_REQUEST['new_role'];
124124

125-
// Mocking the `none` role so we are able to save it to the database
125+
// Mock `none` as editable role.
126126
$editable_roles['none'] = array(
127127
'name' => __( '— No role for this site —' ),
128128
);
@@ -162,6 +162,8 @@
162162
}
163163

164164
$user = get_userdata( $id );
165+
166+
// If $role is empty, none will be set.
165167
$user->set_role( $role );
166168
}
167169

0 commit comments

Comments
 (0)