]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/network/users.php
WordPress 4.3.1-scripts
[autoinstalls/wordpress.git] / wp-admin / network / users.php
1 <?php
2 /**
3  * Multisite users administration panel.
4  *
5  * @package WordPress
6  * @subpackage Multisite
7  * @since 3.0.0
8  */
9
10 /** Load WordPress Administration Bootstrap */
11 require_once( dirname( __FILE__ ) . '/admin.php' );
12
13 if ( ! is_multisite() )
14         wp_die( __( 'Multisite support is not enabled.' ) );
15
16 if ( ! current_user_can( 'manage_network_users' ) )
17         wp_die( __( 'You do not have permission to access this page.' ), 403 );
18
19 /**
20  *
21  * @param array $users
22  */
23 function confirm_delete_users( $users ) {
24         $current_user = wp_get_current_user();
25         if ( ! is_array( $users ) || empty( $users ) ) {
26                 return false;
27         }
28         ?>
29         <h1><?php esc_html_e( 'Users' ); ?></h1>
30
31         <?php if ( 1 == count( $users ) ) : ?>
32                 <p><?php _e( 'You have chosen to delete the user from all networks and sites.' ); ?></p>
33         <?php else : ?>
34                 <p><?php _e( 'You have chosen to delete the following users from all networks and sites.' ); ?></p>
35         <?php endif; ?>
36
37         <form action="users.php?action=dodelete" method="post">
38         <input type="hidden" name="dodelete" />
39         <?php
40         wp_nonce_field( 'ms-users-delete' );
41         $site_admins = get_super_admins();
42         $admin_out = '<option value="' . esc_attr( $current_user->ID ) . '">' . $current_user->user_login . '</option>'; ?>
43         <table class="form-table">
44         <?php foreach ( ( $allusers = (array) $_POST['allusers'] ) as $user_id ) {
45                 if ( $user_id != '' && $user_id != '0' ) {
46                         $delete_user = get_userdata( $user_id );
47
48                         if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) {
49                                 wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
50                         }
51
52                         if ( in_array( $delete_user->user_login, $site_admins ) ) {
53                                 wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network administrator.' ), '<em>' . $delete_user->user_login . '</em>' ) );
54                         }
55                         ?>
56                         <tr>
57                                 <th scope="row"><?php echo $delete_user->user_login; ?>
58                                         <?php echo '<input type="hidden" name="user[]" value="' . esc_attr( $user_id ) . '" />' . "\n"; ?>
59                                 </th>
60                         <?php $blogs = get_blogs_of_user( $user_id, true );
61
62                         if ( ! empty( $blogs ) ) {
63                                 ?>
64                                 <td><fieldset><p><legend><?php printf(
65                                         /* translators: user login */
66                                         __( 'What should be done with content owned by %s?' ),
67                                         '<em>' . $delete_user->user_login . '</em>'
68                                 ); ?></legend></p>
69                                 <?php
70                                 foreach ( (array) $blogs as $key => $details ) {
71                                         $blog_users = get_users( array( 'blog_id' => $details->userblog_id, 'fields' => array( 'ID', 'user_login' ) ) );
72                                         if ( is_array( $blog_users ) && !empty( $blog_users ) ) {
73                                                 $user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
74                                                 $user_dropdown = '<label for="reassign_user" class="screen-reader-text">' . __( 'Select a user' ) . '</label>';
75                                                 $user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>";
76                                                 $user_list = '';
77                                                 foreach ( $blog_users as $user ) {
78                                                         if ( ! in_array( $user->ID, $allusers ) ) {
79                                                                 $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
80                                                         }
81                                                 }
82                                                 if ( '' == $user_list ) {
83                                                         $user_list = $admin_out;
84                                                 }
85                                                 $user_dropdown .= $user_list;
86                                                 $user_dropdown .= "</select>\n";
87                                                 ?>
88                                                 <ul style="list-style:none;">
89                                                         <li><?php printf( __( 'Site: %s' ), $user_site ); ?></li>
90                                                         <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="delete" checked="checked" />
91                                                         <?php _e( 'Delete all content.' ); ?></label></li>
92                                                         <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="reassign" />
93                                                         <?php _e( 'Attribute all content to:' ); ?></label>
94                                                         <?php echo $user_dropdown; ?></li>
95                                                 </ul>
96                                                 <?php
97                                         }
98                                 }
99                                 echo "</fieldset></td></tr>";
100                         } else {
101                                 ?>
102                                 <td><fieldset><p><legend><?php _e( 'User has no sites or content and will be deleted.' ); ?></legend></p>
103                         <?php } ?>
104                         </tr>
105                 <?php
106                 }
107         }
108
109         ?>
110         </table>
111         <?php
112         /** This action is documented in wp-admin/users.php */
113         do_action( 'delete_user_form', $current_user );
114
115         if ( 1 == count( $users ) ) : ?>
116                 <p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, the user will be permanently removed.' ); ?></p>
117         <?php else : ?>
118                 <p><?php _e( 'Once you hit &#8220;Confirm Deletion&#8221;, these users will be permanently removed.' ); ?></p>
119         <?php endif;
120
121         submit_button( __('Confirm Deletion'), 'delete' );
122         ?>
123         </form>
124         <?php
125         return true;
126 }
127
128 if ( isset( $_GET['action'] ) ) {
129         /** This action is documented in wp-admin/network/edit.php */
130         do_action( 'wpmuadminedit' );
131
132         switch ( $_GET['action'] ) {
133                 case 'deleteuser':
134                         if ( ! current_user_can( 'manage_network_users' ) )
135                                 wp_die( __( 'You do not have permission to access this page.' ), 403 );
136
137                         check_admin_referer( 'deleteuser' );
138
139                         $id = intval( $_GET['id'] );
140                         if ( $id != '0' && $id != '1' ) {
141                                 $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
142                                 $title = __( 'Users' );
143                                 $parent_file = 'users.php';
144                                 require_once( ABSPATH . 'wp-admin/admin-header.php' );
145                                 echo '<div class="wrap">';
146                                 confirm_delete_users( $_POST['allusers'] );
147                                 echo '</div>';
148                                 require_once( ABSPATH . 'wp-admin/admin-footer.php' );
149                         } else {
150                                 wp_redirect( network_admin_url( 'users.php' ) );
151                         }
152                         exit();
153
154                 case 'allusers':
155                         if ( !current_user_can( 'manage_network_users' ) )
156                                 wp_die( __( 'You do not have permission to access this page.' ), 403 );
157
158                         if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
159                                 check_admin_referer( 'bulk-users-network' );
160
161                                 $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
162                                 $userfunction = '';
163
164                                 foreach ( (array) $_POST['allusers'] as $user_id ) {
165                                         if ( !empty( $user_id ) ) {
166                                                 switch ( $doaction ) {
167                                                         case 'delete':
168                                                                 if ( ! current_user_can( 'delete_users' ) )
169                                                                         wp_die( __( 'You do not have permission to access this page.' ), 403 );
170                                                                 $title = __( 'Users' );
171                                                                 $parent_file = 'users.php';
172                                                                 require_once( ABSPATH . 'wp-admin/admin-header.php' );
173                                                                 echo '<div class="wrap">';
174                                                                 confirm_delete_users( $_POST['allusers'] );
175                                                                 echo '</div>';
176                                                                 require_once( ABSPATH . 'wp-admin/admin-footer.php' );
177                                                                 exit();
178
179                                                         case 'spam':
180                                                                 $user = get_userdata( $user_id );
181                                                                 if ( is_super_admin( $user->ID ) )
182                                                                         wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
183
184                                                                 $userfunction = 'all_spam';
185                                                                 $blogs = get_blogs_of_user( $user_id, true );
186                                                                 foreach ( (array) $blogs as $details ) {
187                                                                         if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
188                                                                                 update_blog_status( $details->userblog_id, 'spam', '1' );
189                                                                 }
190                                                                 update_user_status( $user_id, 'spam', '1' );
191                                                         break;
192
193                                                         case 'notspam':
194                                                                 $userfunction = 'all_notspam';
195                                                                 $blogs = get_blogs_of_user( $user_id, true );
196                                                                 foreach ( (array) $blogs as $details )
197                                                                         update_blog_status( $details->userblog_id, 'spam', '0' );
198
199                                                                 update_user_status( $user_id, 'spam', '0' );
200                                                         break;
201                                                 }
202                                         }
203                                 }
204
205                                 wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
206                         } else {
207                                 $location = network_admin_url( 'users.php' );
208
209                                 if ( ! empty( $_REQUEST['paged'] ) )
210                                         $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
211                                 wp_redirect( $location );
212                         }
213                         exit();
214
215                 case 'dodelete':
216                         check_admin_referer( 'ms-users-delete' );
217                         if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
218                                 wp_die( __( 'You do not have permission to access this page.' ), 403 );
219
220                         if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
221                                 foreach ( $_POST['blog'] as $id => $users ) {
222                                         foreach ( $users as $blogid => $user_id ) {
223                                                 if ( ! current_user_can( 'delete_user', $id ) )
224                                                         continue;
225
226                                                 if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
227                                                         remove_user_from_blog( $id, $blogid, $user_id );
228                                                 else
229                                                         remove_user_from_blog( $id, $blogid );
230                                         }
231                                 }
232                         }
233                         $i = 0;
234                         if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
235                                 foreach( $_POST['user'] as $id ) {
236                                         if ( ! current_user_can( 'delete_user', $id ) )
237                                                 continue;
238                                         wpmu_delete_user( $id );
239                                         $i++;
240                                 }
241
242                         if ( $i == 1 )
243                                 $deletefunction = 'delete';
244                         else
245                                 $deletefunction = 'all_delete';
246
247                         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
248                         exit();
249         }
250 }
251
252 $wp_list_table = _get_list_table('WP_MS_Users_List_Table');
253 $pagenum = $wp_list_table->get_pagenum();
254 $wp_list_table->prepare_items();
255 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
256
257 if ( $pagenum > $total_pages && $total_pages > 0 ) {
258         wp_redirect( add_query_arg( 'paged', $total_pages ) );
259         exit;
260 }
261 $title = __( 'Users' );
262 $parent_file = 'users.php';
263
264 add_screen_option( 'per_page' );
265
266 get_current_screen()->add_help_tab( array(
267         'id'      => 'overview',
268         'title'   => __('Overview'),
269         'content' =>
270                 '<p>' . __('This table shows all users across the network and the sites to which they are assigned.') . '</p>' .
271                 '<p>' . __('Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to their Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.') . '</p>' .
272                 '<p>' . __('You can also go to the user&#8217;s profile page by clicking on the individual username.') . '</p>' .
273                 '<p>' . __('You can sort the table by clicking on any of the bold headings and switch between list and excerpt views by using the icons in the upper right.') . '</p>' .
274                 '<p>' . __('The bulk action will permanently delete selected users, or mark/unmark those selected as spam. Spam users will have posts removed and will be unable to sign up again with the same email addresses.') . '</p>' .
275                 '<p>' . __('You can make an existing user an additional super admin by going to the Edit User profile page and checking the box to grant that privilege.') . '</p>'
276 ) );
277
278 get_current_screen()->set_help_sidebar(
279         '<p><strong>' . __('For more information:') . '</strong></p>' .
280         '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' .
281         '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
282 );
283
284 require_once( ABSPATH . 'wp-admin/admin-header.php' );
285
286 if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
287         ?>
288         <div id="message" class="updated notice is-dismissible"><p>
289                 <?php
290                 switch ( $_REQUEST['action'] ) {
291                         case 'delete':
292                                 _e( 'User deleted.' );
293                         break;
294                         case 'all_spam':
295                                 _e( 'Users marked as spam.' );
296                         break;
297                         case 'all_notspam':
298                                 _e( 'Users removed from spam.' );
299                         break;
300                         case 'all_delete':
301                                 _e( 'Users deleted.' );
302                         break;
303                         case 'add':
304                                 _e( 'User added.' );
305                         break;
306                 }
307                 ?>
308         </p></div>
309         <?php
310 }
311         ?>
312 <div class="wrap">
313         <h1><?php esc_html_e( 'Users' );
314         if ( current_user_can( 'create_users') ) : ?>
315                 <a href="<?php echo network_admin_url('user-new.php'); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a><?php
316         endif;
317
318         if ( !empty( $usersearch ) )
319         printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );
320         ?>
321         </h1>
322
323         <?php $wp_list_table->views(); ?>
324
325         <form method="get" class="search-form">
326                 <?php $wp_list_table->search_box( __( 'Search Users' ), 'all-user' ); ?>
327         </form>
328
329         <form id="form-user-list" action="users.php?action=allusers" method="post">
330                 <?php $wp_list_table->display(); ?>
331         </form>
332 </div>
333
334 <?php require_once( ABSPATH . 'wp-admin/admin-footer.php' ); ?>