3
* Edit Site Users Administration Screen
6
* @subpackage Multisite
10
/** Load WordPress Administration Bootstrap */
11
require_once( dirname( __FILE__ ) . '/admin.php' );
13
if ( ! is_multisite() )
14
wp_die( __( 'Multisite support is not enabled.' ) );
16
if ( ! current_user_can('manage_sites') )
17
wp_die(__('You do not have sufficient permissions to edit this site.'));
19
$wp_list_table = _get_list_table('WP_Users_List_Table');
20
$wp_list_table->prepare_items();
22
get_current_screen()->add_help_tab( array(
24
'title' => __('Overview'),
26
'<p>' . __('The menu is for editing information specific to individual sites, particularly if the admin area of a site is unavailable.') . '</p>' .
27
'<p>' . __('<strong>Info</strong> - The domain and path are rarely edited as this can cause the site to not work properly. The Registered date and Last Updated date are displayed. Network admins can mark a site as archived, spam, deleted and mature, to remove from public listings or disable.') . '</p>' .
28
'<p>' . __('<strong>Users</strong> - This displays the users associated with this site. You can also change their role, reset their password, or remove them from the site. Removing the user from the site does not remove the user from the network.') . '</p>' .
29
'<p>' . sprintf( __('<strong>Themes</strong> - This area shows themes that are not already enabled across the network. Enabling a theme in this menu makes it accessible to this site. It does not activate the theme, but allows it to show in the site’s Appearance menu. To enable a theme for the entire network, see the <a href="%s">Network Themes</a> screen.' ), network_admin_url( 'themes.php' ) ) . '</p>' .
30
'<p>' . __('<strong>Settings</strong> - This page shows a list of all settings associated with this site. Some are created by WordPress and others are created by plugins you activate. Note that some fields are grayed out and say Serialized Data. You cannot modify these values due to the way the setting is stored in the database.') . '</p>'
33
get_current_screen()->set_help_sidebar(
34
'<p><strong>' . __('For more information:') . '</strong></p>' .
35
'<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Sites_Screen" target="_blank">Documentation on Site Management</a>') . '</p>' .
36
'<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
39
$_SERVER['REQUEST_URI'] = remove_query_arg( 'update', $_SERVER['REQUEST_URI'] );
40
$referer = remove_query_arg( 'update', wp_get_referer() );
42
if ( ! empty( $_REQUEST['paged'] ) ) {
43
$referer = add_query_arg( 'paged', (int) $_REQUEST['paged'], $referer );
46
$id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
49
wp_die( __('Invalid site ID.') );
51
$details = get_blog_details( $id );
52
if ( ! can_edit_network( $details->site_id ) )
53
wp_die( __( 'You do not have permission to access this page.' ) );
55
$is_main_site = is_main_site( $id );
57
switch_to_blog( $id );
59
$action = $wp_list_table->current_action();
65
check_admin_referer( 'add-user', '_wpnonce_add-new-user' );
66
$user = $_POST['user'];
67
if ( ! is_array( $_POST['user'] ) || empty( $user['username'] ) || empty( $user['email'] ) ) {
70
$password = wp_generate_password( 12, false);
71
$user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
73
if ( false == $user_id ) {
74
$update = 'err_new_dup';
76
wp_new_user_notification( $user_id, $password );
77
add_user_to_blog( $id, $user_id, $_POST['new_role'] );
84
check_admin_referer( 'add-user', '_wpnonce_add-user' );
85
if ( !empty( $_POST['newuser'] ) ) {
87
$newuser = $_POST['newuser'];
88
$user = get_user_by( 'login', $newuser );
89
if ( $user && $user->exists() ) {
90
if ( ! is_user_member_of_blog( $user->ID, $id ) )
91
add_user_to_blog( $id, $user->ID, $_POST['new_role'] );
93
$update = 'err_add_member';
95
$update = 'err_add_notfound';
98
$update = 'err_add_notfound';
103
if ( ! current_user_can( 'remove_users' ) )
104
die(__('You can’t remove users.'));
105
check_admin_referer( 'bulk-users' );
108
if ( isset( $_REQUEST['users'] ) ) {
109
$userids = $_REQUEST['users'];
111
foreach ( $userids as $user_id ) {
112
$user_id = (int) $user_id;
113
remove_user_from_blog( $user_id, $id );
115
} elseif ( isset( $_GET['user'] ) ) {
116
remove_user_from_blog( $_GET['user'] );
118
$update = 'err_remove';
123
check_admin_referer( 'bulk-users' );
124
$editable_roles = get_editable_roles();
125
if ( empty( $editable_roles[$_REQUEST['new_role']] ) )
126
wp_die(__('You can’t give users that role.'));
128
if ( isset( $_REQUEST['users'] ) ) {
129
$userids = $_REQUEST['users'];
131
foreach ( $userids as $user_id ) {
132
$user_id = (int) $user_id;
134
// If the user doesn't already belong to the blog, bail.
135
if ( !is_user_member_of_blog( $user_id ) )
136
wp_die(__('Cheatin’ uh?'));
138
$user = get_userdata( $user_id );
139
$user->set_role( $_REQUEST['new_role'] );
142
$update = 'err_promote';
147
wp_safe_redirect( add_query_arg( 'update', $update, $referer ) );
151
restore_current_blog();
153
if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) {
154
wp_safe_redirect( $referer );
158
add_screen_option( 'per_page', array( 'label' => _x( 'Users', 'users per page (screen options)' ) ) );
160
$site_url_no_http = preg_replace( '#^http(s)?://#', '', get_blogaddress_by_id( $id ) );
161
$title_site_url_linked = sprintf( __('Edit Site: <a href="%1$s">%2$s</a>'), get_blogaddress_by_id( $id ), $site_url_no_http );
162
$title = sprintf( __('Edit Site: %s'), $site_url_no_http );
164
$parent_file = 'sites.php';
165
$submenu_file = 'sites.php';
168
* Filter whether to show the Add Existing User form on the Multisite Users screen.
172
* @param bool $bool Whether to show the Add Existing User form. Default true.
174
if ( ! wp_is_large_network( 'users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) )
175
wp_enqueue_script( 'user-suggest' );
177
require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
179
<script type="text/javascript">
181
var current_site_id = <?php echo $id; ?>;
187
<h2 id="edit-site"><?php echo $title_site_url_linked ?></h2>
188
<h3 class="nav-tab-wrapper">
191
'site-info' => array( 'label' => __( 'Info' ), 'url' => 'site-info.php' ),
192
'site-users' => array( 'label' => __( 'Users' ), 'url' => 'site-users.php' ),
193
'site-themes' => array( 'label' => __( 'Themes' ), 'url' => 'site-themes.php' ),
194
'site-settings' => array( 'label' => __( 'Settings' ), 'url' => 'site-settings.php' ),
196
foreach ( $tabs as $tab_id => $tab ) {
197
$class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
198
echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
203
if ( isset($_GET['update']) ) :
204
switch($_GET['update']) {
206
echo '<div id="message" class="updated"><p>' . __( 'User added.' ) . '</p></div>';
208
case 'err_add_member':
209
echo '<div id="message" class="error"><p>' . __( 'User is already a member of this site.' ) . '</p></div>';
211
case 'err_add_notfound':
212
echo '<div id="message" class="error"><p>' . __( 'Enter the username of an existing user.' ) . '</p></div>';
215
echo '<div id="message" class="updated"><p>' . __( 'Changed roles.' ) . '</p></div>';
218
echo '<div id="message" class="error"><p>' . __( 'Select a user to change role.' ) . '</p></div>';
221
echo '<div id="message" class="updated"><p>' . __( 'User removed from this site.' ) . '</p></div>';
224
echo '<div id="message" class="error"><p>' . __( 'Select a user to remove.' ) . '</p></div>';
227
echo '<div id="message" class="updated"><p>' . __( 'User created.' ) . '</p></div>';
230
echo '<div id="message" class="error"><p>' . __( 'Enter the username and email.' ) . '</p></div>';
233
echo '<div id="message" class="error"><p>' . __( 'Duplicated username or email address.' ) . '</p></div>';
238
<form class="search-form" action="" method="get">
239
<?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?>
240
<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
243
<?php $wp_list_table->views(); ?>
245
<form method="post" action="site-users.php?action=update-site">
246
<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
248
<?php $wp_list_table->display(); ?>
254
* Fires after the list table on the Users screen in the Multisite Network Admin.
258
do_action( 'network_site_users_after_list_table' );
260
/** This filter is documented in wp-admin/network/site-users.php */
261
if ( current_user_can( 'promote_users' ) && apply_filters( 'show_network_site_users_add_existing_form', true ) ) : ?>
262
<h3 id="add-existing-user"><?php _e( 'Add Existing User' ); ?></h3>
263
<form action="site-users.php?action=adduser" id="adduser" method="post">
264
<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
265
<table class="form-table">
267
<th scope="row"><?php _e( 'Username' ); ?></th>
268
<td><input type="text" class="regular-text wp-suggest-user" name="newuser" id="newuser" /></td>
271
<th scope="row"><?php _e( 'Role' ); ?></th>
272
<td><select name="new_role" id="new_role_0">
273
<?php wp_dropdown_roles( get_option( 'default_role' ) ); ?>
277
<?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ) ?>
278
<?php submit_button( __( 'Add User' ), 'primary', 'add-user', true, array( 'id' => 'submit-add-existing-user' ) ); ?>
284
* Filter whether to show the Add New User form on the Multisite Users screen.
288
* @param bool $bool Whether to show the Add New User form. Default true.
290
if ( current_user_can( 'create_users' ) && apply_filters( 'show_network_site_users_add_new_form', true ) ) : ?>
291
<h3 id="add-new-user"><?php _e( 'Add New User' ); ?></h3>
292
<form action="<?php echo network_admin_url('site-users.php?action=newuser'); ?>" id="newuser" method="post">
293
<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
294
<table class="form-table">
296
<th scope="row"><?php _e( 'Username' ) ?></th>
297
<td><input type="text" class="regular-text" name="user[username]" /></td>
300
<th scope="row"><?php _e( 'Email' ) ?></th>
301
<td><input type="text" class="regular-text" name="user[email]" /></td>
304
<th scope="row"><?php _e( 'Role' ); ?></th>
305
<td><select name="new_role" id="new_role_0">
306
<?php wp_dropdown_roles( get_option( 'default_role' ) ); ?>
309
<tr class="form-field">
310
<td colspan="2"><?php _e( 'Username and password will be mailed to the above email address.' ) ?></td>
313
<?php wp_nonce_field( 'add-user', '_wpnonce_add-new-user' ) ?>
314
<?php submit_button( __( 'Add New User' ), 'primary', 'add-user', true, array( 'id' => 'submit-add-user' ) ); ?>
319
require( ABSPATH . 'wp-admin/admin-footer.php' );