]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/network/users.php
Wordpress 3.3-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( './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.' ) );
18
19 function confirm_delete_users( $users ) {
20         $current_user = wp_get_current_user();
21         if ( !is_array( $users ) )
22                 return false;
23
24         screen_icon();
25         ?>
26         <h2><?php esc_html_e( 'Users' ); ?></h2>
27         <p><?php _e( 'Transfer or delete posts and links before deleting users.' ); ?></p>
28         <form action="users.php?action=dodelete" method="post">
29         <input type="hidden" name="dodelete" />
30         <?php
31         wp_nonce_field( 'ms-users-delete' );
32         $site_admins = get_super_admins();
33         $admin_out = "<option value='$current_user->ID'>$current_user->user_login</option>";
34
35         foreach ( ( $allusers = (array) $_POST['allusers'] ) as $key => $val ) {
36                 if ( $val != '' && $val != '0' ) {
37                         $delete_user = new WP_User( $val );
38
39                         if ( ! current_user_can( 'delete_user', $delete_user->ID ) )
40                                 wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) );
41
42                         if ( in_array( $delete_user->user_login, $site_admins ) )
43                                 wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network admnistrator.' ), $delete_user->user_login ) );
44
45                         echo "<input type='hidden' name='user[]' value='{$val}'/>\n";
46                         $blogs = get_blogs_of_user( $val, true );
47
48                         if ( !empty( $blogs ) ) {
49                                 ?>
50                                 <br /><fieldset><p><legend><?php printf( __( "What should be done with posts and links owned by <em>%s</em>?" ), $delete_user->user_login ); ?></legend></p>
51                                 <?php
52                                 foreach ( (array) $blogs as $key => $details ) {
53                                         $blog_users = get_users( array( 'blog_id' => $details->userblog_id ) );
54                                         if ( is_array( $blog_users ) && !empty( $blog_users ) ) {
55                                                 $user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>";
56                                                 $user_dropdown = "<select name='blog[$val][{$key}]'>";
57                                                 $user_list = '';
58                                                 foreach ( $blog_users as $user ) {
59                                                         if ( ! in_array( $user->ID, $allusers ) )
60                                                                 $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>";
61                                                 }
62                                                 if ( '' == $user_list )
63                                                         $user_list = $admin_out;
64                                                 $user_dropdown .= $user_list;
65                                                 $user_dropdown .= "</select>\n";
66                                                 ?>
67                                                 <ul style="list-style:none;">
68                                                         <li><?php printf( __( 'Site: %s' ), $user_site ); ?></li>
69                                                         <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="delete" checked="checked" />
70                                                         <?php _e( 'Delete all posts and links.' ); ?></label></li>
71                                                         <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="reassign" />
72                                                         <?php echo __( 'Attribute all posts and links to:' ) . '</label>' . $user_dropdown; ?></li>
73                                                 </ul>
74                                                 <?php
75                                         }
76                                 }
77                                 echo "</fieldset>";
78                         }
79                 }
80         }
81
82         submit_button( __('Confirm Deletion'), 'delete' );
83         ?>
84         </form>
85     <?php
86         return true;
87 }
88
89 if ( isset( $_GET['action'] ) ) {
90         do_action( 'wpmuadminedit' , '' );
91
92         switch ( $_GET['action'] ) {
93                 case 'deleteuser':
94                         if ( ! current_user_can( 'manage_network_users' ) )
95                                 wp_die( __( 'You do not have permission to access this page.' ) );
96
97                         check_admin_referer( 'deleteuser' );
98
99                         $id = intval( $_GET['id'] );
100                         if ( $id != '0' && $id != '1' ) {
101                                 $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
102                                 $title = __( 'Users' );
103                                 $parent_file = 'users.php';
104                                 require_once( '../admin-header.php' );
105                                 echo '<div class="wrap">';
106                                 confirm_delete_users( $_POST['allusers'] );
107                                 echo '</div>';
108                     require_once( '../admin-footer.php' );
109                         } else {
110                                 wp_redirect( network_admin_url( 'users.php' ) );
111                         }
112                         exit();
113                 break;
114
115                 case 'allusers':
116                         if ( !current_user_can( 'manage_network_users' ) )
117                                 wp_die( __( 'You do not have permission to access this page.' ) );
118
119                         if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
120                                 check_admin_referer( 'bulk-users-network' );
121
122                                 if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
123                                         $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
124
125                                 $userfunction = '';
126
127                                 foreach ( (array) $_POST['allusers'] as $key => $val ) {
128                                         if ( !empty( $val ) ) {
129                                                 switch ( $doaction ) {
130                                                         case 'delete':
131                                                                 if ( ! current_user_can( 'delete_users' ) )
132                                                                         wp_die( __( 'You do not have permission to access this page.' ) );
133                                                                 $title = __( 'Users' );
134                                                                 $parent_file = 'users.php';
135                                                                 require_once( '../admin-header.php' );
136                                                                 echo '<div class="wrap">';
137                                                                 confirm_delete_users( $_POST['allusers'] );
138                                                                 echo '</div>';
139                                                     require_once( '../admin-footer.php' );
140                                                     exit();
141                                                 break;
142
143                                                         case 'spam':
144                                                                 $user = new WP_User( $val );
145                                                                 if ( in_array( $user->user_login, get_super_admins() ) )
146                                                                         wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
147
148                                                                 $userfunction = 'all_spam';
149                                                                 $blogs = get_blogs_of_user( $val, true );
150                                                                 foreach ( (array) $blogs as $key => $details ) {
151                                                                         if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
152                                                                                 update_blog_status( $details->userblog_id, 'spam', '1' );
153                                                                 }
154                                                                 update_user_status( $val, 'spam', '1' );
155                                                         break;
156
157                                                         case 'notspam':
158                                                                 $userfunction = 'all_notspam';
159                                                                 $blogs = get_blogs_of_user( $val, true );
160                                                                 foreach ( (array) $blogs as $key => $details )
161                                                                         update_blog_status( $details->userblog_id, 'spam', '0' );
162
163                                                                 update_user_status( $val, 'spam', '0' );
164                                                         break;
165                                                 }
166                                         }
167                                 }
168
169                                 wp_safe_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
170                         } else {
171                                 $location = network_admin_url( 'users.php' );
172
173                                 if ( ! empty( $_REQUEST['paged'] ) )
174                                         $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
175                                 wp_redirect( $location );
176                         }
177                         exit();
178                 break;
179
180                 case 'dodelete':
181                         check_admin_referer( 'ms-users-delete' );
182                         if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
183                                 wp_die( __( 'You do not have permission to access this page.' ) );
184
185                         if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
186                                 foreach ( $_POST['blog'] as $id => $users ) {
187                                         foreach ( $users as $blogid => $user_id ) {
188                                                 if ( ! current_user_can( 'delete_user', $id ) )
189                                                         continue;
190
191                                                 if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
192                                                         remove_user_from_blog( $id, $blogid, $user_id );
193                                                 else
194                                                         remove_user_from_blog( $id, $blogid );
195                                         }
196                                 }
197                         }
198                         $i = 0;
199                         if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
200                                 foreach( $_POST['user'] as $id ) {
201                                         if ( ! current_user_can( 'delete_user', $id ) )
202                                                 continue;
203                                         wpmu_delete_user( $id );
204                                         $i++;
205                                 }
206
207                         if ( $i == 1 )
208                                 $deletefunction = 'delete';
209                         else
210                                 $deletefunction = 'all_delete';
211
212                         wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
213                         exit();
214                 break;
215         }
216 }
217
218 $wp_list_table = _get_list_table('WP_MS_Users_List_Table');
219 $pagenum = $wp_list_table->get_pagenum();
220 $wp_list_table->prepare_items();
221 $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
222
223 if ( $pagenum > $total_pages && $total_pages > 0 ) {
224         wp_redirect( add_query_arg( 'paged', $total_pages ) );
225         exit;
226 }
227 $title = __( 'Users' );
228 $parent_file = 'users.php';
229
230 add_screen_option( 'per_page', array('label' => _x( 'Users', 'users per page (screen options)' )) );
231
232 get_current_screen()->add_help_tab( array(
233         'id'      => 'overview',
234         'title'   => __('Overview'),
235         'content' =>
236                 '<p>' . __('This table shows all users across the network and the sites to which they are assigned.') . '</p>' .
237                 '<p>' . __('Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to his or her Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.') . '</p>' .
238                 '<p>' . __('You can also go to the user&#8217;s profile page by clicking on the individual username.') . '</p>' .
239                 '<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>' .
240                 '<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>' .
241                 '<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>'
242 ) );
243
244 get_current_screen()->set_help_sidebar(
245         '<p><strong>' . __('For more information:') . '</strong></p>' .
246         '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' .
247         '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
248 );
249
250 require_once( '../admin-header.php' );
251
252 if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
253         ?>
254         <div id="message" class="updated"><p>
255                 <?php
256                 switch ( $_REQUEST['action'] ) {
257                         case 'delete':
258                                 _e( 'User deleted.' );
259                         break;
260                         case 'all_spam':
261                                 _e( 'Users marked as spam.' );
262                         break;
263                         case 'all_notspam':
264                                 _e( 'Users removed from spam.' );
265                         break;
266                         case 'all_delete':
267                                 _e( 'Users deleted.' );
268                         break;
269                         case 'add':
270                                 _e( 'User added.' );
271                         break;
272                 }
273                 ?>
274         </p></div>
275         <?php
276 }
277         ?>
278 <div class="wrap">
279         <?php screen_icon(); ?>
280         <h2><?php esc_html_e( 'Users' );
281         if ( current_user_can( 'create_users') ) : ?>
282                 <a href="<?php echo network_admin_url('user-new.php'); ?>" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a><?php
283         endif;
284
285         if ( !empty( $usersearch ) )
286         printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );
287         ?>
288         </h2>
289
290         <?php $wp_list_table->views(); ?>
291
292         <form action="" method="get" class="search-form">
293                 <?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?>
294         </form>
295
296         <form id="form-user-list" action='users.php?action=allusers' method='post'>
297                 <?php $wp_list_table->display(); ?>
298         </form>
299 </div>
300
301 <?php require_once( '../admin-footer.php' ); ?>