author | ymh <ymh.work@gmail.com> |
Mon, 14 Oct 2019 17:39:30 +0200 | |
changeset 7 | cf61fcea0001 |
parent 5 | 5e2f62d02dcd |
child 9 | 177826044cd9 |
permissions | -rw-r--r-- |
0 | 1 |
<?php |
2 |
/** |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
3 |
* User administration panel |
0 | 4 |
* |
5 |
* @package WordPress |
|
6 |
* @subpackage Administration |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
7 |
* @since 1.0.0 |
0 | 8 |
*/ |
9 |
||
10 |
/** WordPress Administration Bootstrap */ |
|
11 |
require_once( dirname( __FILE__ ) . '/admin.php' ); |
|
12 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
13 |
if ( ! current_user_can( 'list_users' ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
14 |
wp_die( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
15 |
'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
16 |
'<p>' . __( 'Sorry, you are not allowed to list users.' ) . '</p>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
17 |
403 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
18 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
19 |
} |
0 | 20 |
|
21 |
$wp_list_table = _get_list_table('WP_Users_List_Table'); |
|
22 |
$pagenum = $wp_list_table->get_pagenum(); |
|
23 |
$title = __('Users'); |
|
24 |
$parent_file = 'users.php'; |
|
25 |
||
5 | 26 |
add_screen_option( 'per_page' ); |
0 | 27 |
|
28 |
// contextual help - choose Help on the top right of admin panel to preview this. |
|
29 |
get_current_screen()->add_help_tab( array( |
|
30 |
'id' => 'overview', |
|
31 |
'title' => __('Overview'), |
|
32 |
'content' => '<p>' . __('This screen lists all the existing users for your site. Each user has one of five defined roles as set by the site admin: Site Administrator, Editor, Author, Contributor, or Subscriber. Users with roles other than Administrator will see fewer options in the dashboard navigation when they are logged in, based on their role.') . '</p>' . |
|
33 |
'<p>' . __('To add a new user for your site, click the Add New button at the top of the screen or Add New in the Users menu section.') . '</p>' |
|
34 |
) ) ; |
|
35 |
||
36 |
get_current_screen()->add_help_tab( array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
37 |
'id' => 'screen-content', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
38 |
'title' => __('Screen Content'), |
0 | 39 |
'content' => '<p>' . __('You can customize the display of this screen in a number of ways:') . '</p>' . |
40 |
'<ul>' . |
|
41 |
'<li>' . __('You can hide/display columns based on your needs and decide how many users to list per screen using the Screen Options tab.') . '</li>' . |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
42 |
'<li>' . __( 'You can filter the list of users by User Role using the text links above the users list to show All, Administrator, Editor, Author, Contributor, or Subscriber. The default view is to show all users. Unused User Roles are not listed.' ) . '</li>' . |
0 | 43 |
'<li>' . __('You can view all posts made by a user by clicking on the number under the Posts column.') . '</li>' . |
44 |
'</ul>' |
|
45 |
) ); |
|
46 |
||
47 |
$help = '<p>' . __('Hovering over a row in the users list will display action links that allow you to manage users. You can perform the following actions:') . '</p>' . |
|
48 |
'<ul>' . |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
49 |
'<li>' . __('<strong>Edit</strong> takes you to the editable profile screen for that user. You can also reach that screen by clicking on the username.') . '</li>'; |
0 | 50 |
|
51 |
if ( is_multisite() ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
52 |
$help .= '<li>' . __( '<strong>Remove</strong> allows you to remove a user from your site. It does not delete their content. You can also remove multiple users at once by using Bulk Actions.' ) . '</li>'; |
0 | 53 |
else |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
54 |
$help .= '<li>' . __( '<strong>Delete</strong> brings you to the Delete Users screen for confirmation, where you can permanently remove a user from your site and delete their content. You can also delete multiple users at once by using Bulk Actions.' ) . '</li>'; |
0 | 55 |
|
56 |
$help .= '</ul>'; |
|
57 |
||
58 |
get_current_screen()->add_help_tab( array( |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
59 |
'id' => 'action-links', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
60 |
'title' => __('Available Actions'), |
0 | 61 |
'content' => $help, |
62 |
) ); |
|
63 |
unset( $help ); |
|
64 |
||
65 |
get_current_screen()->set_help_sidebar( |
|
66 |
'<p><strong>' . __('For more information:') . '</strong></p>' . |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
67 |
'<p>' . __('<a href="https://codex.wordpress.org/Users_Screen">Documentation on Managing Users</a>') . '</p>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
68 |
'<p>' . __('<a href="https://codex.wordpress.org/Roles_and_Capabilities">Descriptions of Roles and Capabilities</a>') . '</p>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
69 |
'<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>' |
0 | 70 |
); |
71 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
72 |
get_current_screen()->set_screen_reader_content( array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
73 |
'heading_views' => __( 'Filter users list' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
74 |
'heading_pagination' => __( 'Users list navigation' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
75 |
'heading_list' => __( 'Users list' ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
76 |
) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
77 |
|
0 | 78 |
if ( empty($_REQUEST) ) { |
79 |
$referer = '<input type="hidden" name="wp_http_referer" value="'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />'; |
|
80 |
} elseif ( isset($_REQUEST['wp_http_referer']) ) { |
|
81 |
$redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), wp_unslash( $_REQUEST['wp_http_referer'] ) ); |
|
82 |
$referer = '<input type="hidden" name="wp_http_referer" value="' . esc_attr($redirect) . '" />'; |
|
83 |
} else { |
|
84 |
$redirect = 'users.php'; |
|
85 |
$referer = ''; |
|
86 |
} |
|
87 |
||
88 |
$update = ''; |
|
89 |
||
90 |
switch ( $wp_list_table->current_action() ) { |
|
91 |
||
92 |
/* Bulk Dropdown menu Role changes */ |
|
93 |
case 'promote': |
|
94 |
check_admin_referer('bulk-users'); |
|
95 |
||
96 |
if ( ! current_user_can( 'promote_users' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
97 |
wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 ); |
0 | 98 |
|
99 |
if ( empty($_REQUEST['users']) ) { |
|
100 |
wp_redirect($redirect); |
|
101 |
exit(); |
|
102 |
} |
|
103 |
||
104 |
$editable_roles = get_editable_roles(); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
105 |
$role = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
106 |
if ( ! empty( $_REQUEST['new_role2'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
107 |
$role = $_REQUEST['new_role2']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
108 |
} elseif ( ! empty( $_REQUEST['new_role'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
109 |
$role = $_REQUEST['new_role']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
110 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
111 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
112 |
if ( ! $role || empty( $editable_roles[ $role ] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
113 |
wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
114 |
} |
0 | 115 |
|
116 |
$userids = $_REQUEST['users']; |
|
117 |
$update = 'promote'; |
|
118 |
foreach ( $userids as $id ) { |
|
119 |
$id = (int) $id; |
|
120 |
||
121 |
if ( ! current_user_can('promote_user', $id) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
122 |
wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 ); |
0 | 123 |
// The new role of the current user must also have the promote_users cap or be a multisite super admin |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
124 |
if ( $id == $current_user->ID && ! $wp_roles->role_objects[ $role ]->has_cap('promote_users') |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
125 |
&& ! ( is_multisite() && current_user_can( 'manage_network_users' ) ) ) { |
0 | 126 |
$update = 'err_admin_role'; |
127 |
continue; |
|
128 |
} |
|
129 |
||
130 |
// If the user doesn't already belong to the blog, bail. |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
131 |
if ( is_multisite() && !is_user_member_of_blog( $id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
132 |
wp_die( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
133 |
'<h1>' . __( 'Something went wrong.' ) . '</h1>' . |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
134 |
'<p>' . __( 'One of the selected users is not a member of this site.' ) . '</p>', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
135 |
403 |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
136 |
); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
137 |
} |
0 | 138 |
|
139 |
$user = get_userdata( $id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
140 |
$user->set_role( $role ); |
0 | 141 |
} |
142 |
||
143 |
wp_redirect(add_query_arg('update', $update, $redirect)); |
|
144 |
exit(); |
|
145 |
||
146 |
case 'dodelete': |
|
147 |
if ( is_multisite() ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
148 |
wp_die( __('User deletion is not allowed from this screen.'), 400 ); |
0 | 149 |
|
150 |
check_admin_referer('delete-users'); |
|
151 |
||
152 |
if ( empty($_REQUEST['users']) ) { |
|
153 |
wp_redirect($redirect); |
|
154 |
exit(); |
|
155 |
} |
|
156 |
||
157 |
$userids = array_map( 'intval', (array) $_REQUEST['users'] ); |
|
158 |
||
159 |
if ( empty( $_REQUEST['delete_option'] ) ) { |
|
160 |
$url = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $userids ) . '&error=true' ); |
|
161 |
$url = str_replace( '&', '&', wp_nonce_url( $url, 'bulk-users' ) ); |
|
162 |
wp_redirect( $url ); |
|
163 |
exit; |
|
164 |
} |
|
165 |
||
166 |
if ( ! current_user_can( 'delete_users' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
167 |
wp_die( __( 'Sorry, you are not allowed to delete users.' ), 403 ); |
0 | 168 |
|
169 |
$update = 'del'; |
|
170 |
$delete_count = 0; |
|
171 |
||
172 |
foreach ( $userids as $id ) { |
|
173 |
if ( ! current_user_can( 'delete_user', $id ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
174 |
wp_die( __( 'Sorry, you are not allowed to delete that user.' ), 403 ); |
0 | 175 |
|
176 |
if ( $id == $current_user->ID ) { |
|
177 |
$update = 'err_admin_del'; |
|
178 |
continue; |
|
179 |
} |
|
180 |
switch ( $_REQUEST['delete_option'] ) { |
|
181 |
case 'delete': |
|
182 |
wp_delete_user( $id ); |
|
183 |
break; |
|
184 |
case 'reassign': |
|
185 |
wp_delete_user( $id, $_REQUEST['reassign_user'] ); |
|
186 |
break; |
|
187 |
} |
|
188 |
++$delete_count; |
|
189 |
} |
|
190 |
||
191 |
$redirect = add_query_arg( array('delete_count' => $delete_count, 'update' => $update), $redirect); |
|
192 |
wp_redirect($redirect); |
|
193 |
exit(); |
|
194 |
||
195 |
case 'delete': |
|
196 |
if ( is_multisite() ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
197 |
wp_die( __('User deletion is not allowed from this screen.'), 400 ); |
0 | 198 |
|
199 |
check_admin_referer('bulk-users'); |
|
200 |
||
201 |
if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) { |
|
202 |
wp_redirect($redirect); |
|
203 |
exit(); |
|
204 |
} |
|
205 |
||
206 |
if ( ! current_user_can( 'delete_users' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
207 |
$errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to delete users.' ) ); |
0 | 208 |
|
209 |
if ( empty($_REQUEST['users']) ) |
|
210 |
$userids = array( intval( $_REQUEST['user'] ) ); |
|
211 |
else |
|
212 |
$userids = array_map( 'intval', (array) $_REQUEST['users'] ); |
|
213 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
214 |
$users_have_content = false; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
215 |
if ( $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE post_author IN( " . implode( ',', $userids ) . " ) LIMIT 1" ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
216 |
$users_have_content = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
217 |
} elseif ( $wpdb->get_var( "SELECT link_id FROM {$wpdb->links} WHERE link_owner IN( " . implode( ',', $userids ) . " ) LIMIT 1" ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
218 |
$users_have_content = true; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
219 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
220 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
221 |
if ( $users_have_content ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
222 |
add_action( 'admin_head', 'delete_users_add_js' ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
223 |
} |
0 | 224 |
|
225 |
include( ABSPATH . 'wp-admin/admin-header.php' ); |
|
226 |
?> |
|
5 | 227 |
<form method="post" name="updateusers" id="updateusers"> |
0 | 228 |
<?php wp_nonce_field('delete-users') ?> |
229 |
<?php echo $referer; ?> |
|
230 |
||
231 |
<div class="wrap"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
232 |
<h1><?php _e( 'Delete Users' ); ?></h1> |
0 | 233 |
<?php if ( isset( $_REQUEST['error'] ) ) : ?> |
5 | 234 |
<div class="error"> |
235 |
<p><strong><?php _e( 'ERROR:' ); ?></strong> <?php _e( 'Please select an option.' ); ?></p> |
|
236 |
</div> |
|
0 | 237 |
<?php endif; ?> |
5 | 238 |
|
239 |
<?php if ( 1 == count( $userids ) ) : ?> |
|
240 |
<p><?php _e( 'You have specified this user for deletion:' ); ?></p> |
|
241 |
<?php else : ?> |
|
242 |
<p><?php _e( 'You have specified these users for deletion:' ); ?></p> |
|
243 |
<?php endif; ?> |
|
244 |
||
0 | 245 |
<ul> |
246 |
<?php |
|
247 |
$go_delete = 0; |
|
248 |
foreach ( $userids as $id ) { |
|
249 |
$user = get_userdata( $id ); |
|
250 |
if ( $id == $current_user->ID ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
251 |
/* translators: 1: user id, 2: user login */ |
0 | 252 |
echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n"; |
253 |
} else { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
254 |
/* translators: 1: user id, 2: user login */ |
0 | 255 |
echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n"; |
256 |
$go_delete++; |
|
257 |
} |
|
258 |
} |
|
259 |
?> |
|
260 |
</ul> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
261 |
<?php if ( $go_delete ) : |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
262 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
263 |
if ( ! $users_have_content ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
264 |
<input type="hidden" name="delete_option" value="delete" /> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
265 |
<?php else: ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
266 |
<?php if ( 1 == $go_delete ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
267 |
<fieldset><p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
268 |
<?php else : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
269 |
<fieldset><p><legend><?php _e( 'What should be done with content owned by these users?' ); ?></legend></p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
270 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
271 |
<ul style="list-style:none;"> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
272 |
<li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" /> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
273 |
<?php _e('Delete all content.'); ?></label></li> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
274 |
<li><input type="radio" id="delete_option1" name="delete_option" value="reassign" /> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
275 |
<?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> '; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
276 |
wp_dropdown_users( array( |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
277 |
'name' => 'reassign_user', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
278 |
'exclude' => array_diff( $userids, array( $current_user->ID ) ), |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
279 |
'show' => 'display_name_with_login', |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
280 |
) ); ?></li> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
281 |
</ul></fieldset> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
282 |
<?php endif; |
5 | 283 |
/** |
284 |
* Fires at the end of the delete users form prior to the confirm button. |
|
285 |
* |
|
286 |
* @since 4.0.0 |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
287 |
* @since 4.5.0 The `$userids` parameter was added. |
5 | 288 |
* |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
289 |
* @param WP_User $current_user WP_User object for the current user. |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
290 |
* @param array $userids Array of IDs for users being deleted. |
5 | 291 |
*/ |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
292 |
do_action( 'delete_user_form', $current_user, $userids ); |
5 | 293 |
?> |
0 | 294 |
<input type="hidden" name="action" value="dodelete" /> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
295 |
<?php submit_button( __('Confirm Deletion'), 'primary' ); ?> |
0 | 296 |
<?php else : ?> |
297 |
<p><?php _e('There are no valid users selected for deletion.'); ?></p> |
|
298 |
<?php endif; ?> |
|
299 |
</div> |
|
300 |
</form> |
|
301 |
<?php |
|
302 |
||
303 |
break; |
|
304 |
||
305 |
case 'doremove': |
|
306 |
check_admin_referer('remove-users'); |
|
307 |
||
308 |
if ( ! is_multisite() ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
309 |
wp_die( __( 'You can’t remove users.' ), 400 ); |
0 | 310 |
|
311 |
if ( empty($_REQUEST['users']) ) { |
|
312 |
wp_redirect($redirect); |
|
313 |
exit; |
|
314 |
} |
|
315 |
||
316 |
if ( ! current_user_can( 'remove_users' ) ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
317 |
wp_die( __( 'Sorry, you are not allowed to remove users.' ), 403 ); |
0 | 318 |
|
319 |
$userids = $_REQUEST['users']; |
|
320 |
||
321 |
$update = 'remove'; |
|
322 |
foreach ( $userids as $id ) { |
|
323 |
$id = (int) $id; |
|
324 |
if ( !current_user_can('remove_user', $id) ) { |
|
325 |
$update = 'err_admin_remove'; |
|
326 |
continue; |
|
327 |
} |
|
328 |
remove_user_from_blog($id, $blog_id); |
|
329 |
} |
|
330 |
||
331 |
$redirect = add_query_arg( array('update' => $update), $redirect); |
|
332 |
wp_redirect($redirect); |
|
333 |
exit; |
|
334 |
||
335 |
case 'remove': |
|
336 |
||
337 |
check_admin_referer('bulk-users'); |
|
338 |
||
339 |
if ( ! is_multisite() ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
340 |
wp_die( __( 'You can’t remove users.' ), 400 ); |
0 | 341 |
|
342 |
if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) { |
|
343 |
wp_redirect($redirect); |
|
344 |
exit(); |
|
345 |
} |
|
346 |
||
347 |
if ( !current_user_can('remove_users') ) |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
348 |
$error = new WP_Error('edit_users', __('Sorry, you are not allowed to remove users.')); |
0 | 349 |
|
350 |
if ( empty($_REQUEST['users']) ) |
|
351 |
$userids = array(intval($_REQUEST['user'])); |
|
352 |
else |
|
353 |
$userids = $_REQUEST['users']; |
|
354 |
||
355 |
include( ABSPATH . 'wp-admin/admin-header.php' ); |
|
356 |
?> |
|
5 | 357 |
<form method="post" name="updateusers" id="updateusers"> |
0 | 358 |
<?php wp_nonce_field('remove-users') ?> |
359 |
<?php echo $referer; ?> |
|
360 |
||
361 |
<div class="wrap"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
362 |
<h1><?php _e( 'Remove Users from Site' ); ?></h1> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
363 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
364 |
<?php if ( 1 == count( $userids ) ) : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
365 |
<p><?php _e( 'You have specified this user for removal:' ); ?></p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
366 |
<?php else : ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
367 |
<p><?php _e( 'You have specified these users for removal:' ); ?></p> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
368 |
<?php endif; ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
369 |
|
0 | 370 |
<ul> |
371 |
<?php |
|
372 |
$go_remove = false; |
|
373 |
foreach ( $userids as $id ) { |
|
374 |
$id = (int) $id; |
|
375 |
$user = get_userdata( $id ); |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
376 |
if ( ! current_user_can( 'remove_user', $id ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
377 |
/* translators: 1: user id, 2: user login */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
378 |
echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>Sorry, you are not allowed to remove this user.</strong>'), $id, $user->user_login) . "</li>\n"; |
0 | 379 |
} else { |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
380 |
/* translators: 1: user id, 2: user login */ |
0 | 381 |
echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n"; |
382 |
$go_remove = true; |
|
383 |
} |
|
384 |
} |
|
385 |
?> |
|
5 | 386 |
</ul> |
0 | 387 |
<?php if ( $go_remove ) : ?> |
388 |
<input type="hidden" name="action" value="doremove" /> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
389 |
<?php submit_button( __('Confirm Removal'), 'primary' ); ?> |
0 | 390 |
<?php else : ?> |
391 |
<p><?php _e('There are no valid users selected for removal.'); ?></p> |
|
392 |
<?php endif; ?> |
|
393 |
</div> |
|
394 |
</form> |
|
395 |
<?php |
|
396 |
||
397 |
break; |
|
398 |
||
399 |
default: |
|
400 |
||
401 |
if ( !empty($_GET['_wp_http_referer']) ) { |
|
402 |
wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce'), wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); |
|
403 |
exit; |
|
404 |
} |
|
405 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
406 |
if ( $wp_list_table->current_action() && ! empty( $_REQUEST['users'] ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
407 |
$userids = $_REQUEST['users']; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
408 |
$sendback = wp_get_referer(); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
409 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
410 |
/** This action is documented in wp-admin/edit-comments.php */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
411 |
$sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $wp_list_table->current_action(), $userids ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
412 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
413 |
wp_safe_redirect( $sendback ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
414 |
exit; |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
415 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
416 |
|
0 | 417 |
$wp_list_table->prepare_items(); |
418 |
$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' ); |
|
419 |
if ( $pagenum > $total_pages && $total_pages > 0 ) { |
|
420 |
wp_redirect( add_query_arg( 'paged', $total_pages ) ); |
|
421 |
exit; |
|
422 |
} |
|
423 |
||
424 |
include( ABSPATH . 'wp-admin/admin-header.php' ); |
|
425 |
||
426 |
$messages = array(); |
|
427 |
if ( isset($_GET['update']) ) : |
|
428 |
switch($_GET['update']) { |
|
429 |
case 'del': |
|
430 |
case 'del_many': |
|
431 |
$delete_count = isset($_GET['delete_count']) ? (int) $_GET['delete_count'] : 0; |
|
5 | 432 |
if ( 1 == $delete_count ) { |
433 |
$message = __( 'User deleted.' ); |
|
434 |
} else { |
|
435 |
$message = _n( '%s user deleted.', '%s users deleted.', $delete_count ); |
|
436 |
} |
|
437 |
$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $delete_count ) ) . '</p></div>'; |
|
0 | 438 |
break; |
439 |
case 'add': |
|
440 |
if ( isset( $_GET['id'] ) && ( $user_id = $_GET['id'] ) && current_user_can( 'edit_user', $user_id ) ) { |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
441 |
/* translators: %s: edit page url */ |
5 | 442 |
$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( __( 'New user created. <a href="%s">Edit user</a>' ), |
0 | 443 |
esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), |
444 |
self_admin_url( 'user-edit.php?user_id=' . $user_id ) ) ) ) . '</p></div>'; |
|
445 |
} else { |
|
5 | 446 |
$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'New user created.' ) . '</p></div>'; |
0 | 447 |
} |
448 |
break; |
|
449 |
case 'promote': |
|
5 | 450 |
$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __('Changed roles.') . '</p></div>'; |
0 | 451 |
break; |
452 |
case 'err_admin_role': |
|
5 | 453 |
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __('The current user’s role must have user editing capabilities.') . '</p></div>'; |
454 |
$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __('Other user roles have been changed.') . '</p></div>'; |
|
0 | 455 |
break; |
456 |
case 'err_admin_del': |
|
5 | 457 |
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __('You can’t delete the current user.') . '</p></div>'; |
458 |
$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __('Other users have been deleted.') . '</p></div>'; |
|
0 | 459 |
break; |
460 |
case 'remove': |
|
5 | 461 |
$messages[] = '<div id="message" class="updated notice is-dismissible fade"><p>' . __('User removed from this site.') . '</p></div>'; |
0 | 462 |
break; |
463 |
case 'err_admin_remove': |
|
5 | 464 |
$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __("You can't remove the current user.") . '</p></div>'; |
465 |
$messages[] = '<div id="message" class="updated notice is-dismissible fade"><p>' . __('Other users have been removed.') . '</p></div>'; |
|
0 | 466 |
break; |
467 |
} |
|
468 |
endif; ?> |
|
469 |
||
470 |
<?php if ( isset($errors) && is_wp_error( $errors ) ) : ?> |
|
471 |
<div class="error"> |
|
472 |
<ul> |
|
473 |
<?php |
|
474 |
foreach ( $errors->get_error_messages() as $err ) |
|
475 |
echo "<li>$err</li>\n"; |
|
476 |
?> |
|
477 |
</ul> |
|
478 |
</div> |
|
479 |
<?php endif; |
|
480 |
||
481 |
if ( ! empty($messages) ) { |
|
482 |
foreach ( $messages as $msg ) |
|
483 |
echo $msg; |
|
484 |
} ?> |
|
485 |
||
486 |
<div class="wrap"> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
487 |
<h1 class="wp-heading-inline"><?php |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
488 |
echo esc_html( $title ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
489 |
?></h1> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
490 |
|
0 | 491 |
<?php |
492 |
if ( current_user_can( 'create_users' ) ) { ?> |
|
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
493 |
<a href="<?php echo admin_url( 'user-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a> |
0 | 494 |
<?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?> |
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
495 |
<a href="<?php echo admin_url( 'user-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a> |
0 | 496 |
<?php } |
497 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
498 |
if ( strlen( $usersearch ) ) { |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
499 |
/* translators: %s: search keywords */ |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
500 |
printf( '<span class="subtitle">' . __( 'Search results for “%s”' ) . '</span>', esc_html( $usersearch ) ); |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
501 |
} |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
502 |
?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
503 |
|
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
504 |
<hr class="wp-header-end"> |
0 | 505 |
|
506 |
<?php $wp_list_table->views(); ?> |
|
507 |
||
5 | 508 |
<form method="get"> |
0 | 509 |
|
510 |
<?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?> |
|
511 |
||
7
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
512 |
<?php if ( ! empty( $_REQUEST['role'] ) ) { ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
513 |
<input type="hidden" name="role" value="<?php echo esc_attr( $_REQUEST['role'] ); ?>" /> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
514 |
<?php } ?> |
cf61fcea0001
resynchronize code repo with production
ymh <ymh.work@gmail.com>
parents:
5
diff
changeset
|
515 |
|
0 | 516 |
<?php $wp_list_table->display(); ?> |
517 |
</form> |
|
518 |
||
519 |
<br class="clear" /> |
|
520 |
</div> |
|
521 |
<?php |
|
522 |
break; |
|
523 |
||
524 |
} // end of the $doaction switch |
|
525 |
||
526 |
include( ABSPATH . 'wp-admin/admin-footer.php' ); |