2010-10-21 20:35:52 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Edit Site Users Administration Screen
|
|
|
|
*
|
|
|
|
* @package WordPress
|
2010-11-10 15:27:15 +01:00
|
|
|
* @subpackage Multisite
|
2010-10-21 20:35:52 +02:00
|
|
|
* @since 3.1.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** Load WordPress Administration Bootstrap */
|
2010-11-10 15:27:15 +01:00
|
|
|
require_once( './admin.php' );
|
2010-10-21 20:35:52 +02:00
|
|
|
|
|
|
|
if ( ! is_multisite() )
|
|
|
|
wp_die( __( 'Multisite support is not enabled.' ) );
|
|
|
|
|
|
|
|
if ( ! current_user_can('manage_sites') )
|
|
|
|
wp_die(__('You do not have sufficient permissions to edit this site.'));
|
|
|
|
|
2010-11-24 06:31:25 +01:00
|
|
|
$wp_list_table = get_list_table('WP_Users_List_Table');
|
|
|
|
$wp_list_table->check_permissions();
|
|
|
|
$wp_list_table->prepare_items();
|
|
|
|
|
|
|
|
$action = $wp_list_table->current_action();
|
|
|
|
|
2010-10-21 20:35:52 +02:00
|
|
|
$id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
|
|
|
|
|
|
|
|
if ( ! $id )
|
|
|
|
wp_die( __('Invalid site ID.') );
|
|
|
|
|
|
|
|
$details = get_blog_details( $id );
|
2010-12-09 13:36:39 +01:00
|
|
|
if ( !can_edit_network( $details->site_id ) )
|
2010-10-21 20:35:52 +02:00
|
|
|
wp_die( __( 'You do not have permission to access this page.' ) );
|
|
|
|
|
|
|
|
$is_main_site = is_main_site( $id );
|
|
|
|
|
2010-11-17 20:45:10 +01:00
|
|
|
// get blog prefix
|
|
|
|
$blog_prefix = $wpdb->get_blog_prefix( $id );
|
|
|
|
|
|
|
|
// @todo This is a hack. Eventually, add API to WP_Roles allowing retrieval of roles for a particular blog.
|
|
|
|
if ( ! empty($wp_roles->use_db) ) {
|
|
|
|
$editblog_roles = get_blog_option( $id, "{$blog_prefix}user_roles" );
|
|
|
|
} else {
|
|
|
|
// Roles are stored in memory, not the DB.
|
|
|
|
$editblog_roles = $wp_roles->roles;
|
|
|
|
}
|
|
|
|
|
2010-11-24 06:31:25 +01:00
|
|
|
$action = $wp_list_table->current_action();
|
2010-10-21 20:35:52 +02:00
|
|
|
|
2010-11-24 06:31:25 +01:00
|
|
|
if ( $action ) {
|
2010-10-21 20:35:52 +02:00
|
|
|
switch_to_blog( $id );
|
2010-11-24 06:31:25 +01:00
|
|
|
|
|
|
|
switch ( $action ) {
|
2010-11-25 12:12:33 +01:00
|
|
|
case 'newuser':
|
|
|
|
$user = $_POST['user'];
|
|
|
|
if ( !is_array( $_POST['user'] ) || empty( $user['username'] ) || empty( $user['email'] ) ) {
|
|
|
|
$update = 'err_new';
|
|
|
|
} else {
|
|
|
|
$password = wp_generate_password( 12, false);
|
|
|
|
$user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
|
|
|
|
|
|
|
|
if ( false == $user_id ) {
|
|
|
|
$update = 'err_new_dup';
|
|
|
|
} else {
|
|
|
|
wp_new_user_notification( $user_id, $password );
|
|
|
|
add_user_to_blog( $id, $user_id, $_POST['new_role'] );
|
|
|
|
$update = 'newuser';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-11-24 06:31:25 +01:00
|
|
|
case 'adduser':
|
|
|
|
if ( !empty( $_POST['newuser'] ) ) {
|
2010-11-25 12:12:33 +01:00
|
|
|
$update = 'adduser';
|
2010-11-25 10:13:38 +01:00
|
|
|
$newuser = $_POST['newuser'];
|
2010-11-24 06:31:25 +01:00
|
|
|
$userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) );
|
|
|
|
if ( $userid ) {
|
|
|
|
$user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='{$blog_prefix}capabilities'" );
|
|
|
|
if ( $user == false )
|
|
|
|
add_user_to_blog( $id, $userid, $_POST['new_role'] );
|
2010-11-25 10:13:38 +01:00
|
|
|
else
|
|
|
|
$update = 'err_add_member';
|
|
|
|
} else {
|
|
|
|
$update = 'err_add_notfound';
|
2010-11-24 06:31:25 +01:00
|
|
|
}
|
2010-11-25 10:13:38 +01:00
|
|
|
} else {
|
|
|
|
$update = 'err_add_notfound';
|
2010-11-24 06:31:25 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'remove':
|
|
|
|
if ( !current_user_can('remove_users') )
|
|
|
|
die(__('You can’t remove users.'));
|
2010-11-25 10:13:38 +01:00
|
|
|
|
|
|
|
$update = 'remove';
|
2010-11-24 06:31:25 +01:00
|
|
|
if ( isset( $_REQUEST['users'] ) ) {
|
|
|
|
$userids = $_REQUEST['users'];
|
|
|
|
|
|
|
|
foreach ( $userids as $user_id ) {
|
|
|
|
$user_id = (int) $user_id;
|
|
|
|
remove_user_from_blog( $user_id, $id );
|
|
|
|
}
|
2010-11-25 10:13:38 +01:00
|
|
|
} elseif ( isset( $_GET['user'] ) ) {
|
2010-11-24 06:31:25 +01:00
|
|
|
remove_user_from_blog( $_GET['user'] );
|
2010-11-25 10:13:38 +01:00
|
|
|
} else {
|
|
|
|
$update = 'err_remove';
|
2010-11-24 06:31:25 +01:00
|
|
|
}
|
|
|
|
break;
|
2010-10-21 20:35:52 +02:00
|
|
|
|
2010-11-24 06:31:25 +01:00
|
|
|
case 'promote':
|
|
|
|
$editable_roles = get_editable_roles();
|
|
|
|
if ( empty( $editable_roles[$_REQUEST['new_role']] ) )
|
|
|
|
wp_die(__('You can’t give users that role.'));
|
2010-10-21 20:35:52 +02:00
|
|
|
|
2010-11-25 10:13:38 +01:00
|
|
|
if ( isset( $_REQUEST['users'] ) ) {
|
|
|
|
$userids = $_REQUEST['users'];
|
|
|
|
$update = 'promote';
|
|
|
|
foreach ( $userids as $user_id ) {
|
|
|
|
$user_id = (int) $user_id;
|
2010-10-21 20:35:52 +02:00
|
|
|
|
2010-11-25 10:13:38 +01:00
|
|
|
// If the user doesn't already belong to the blog, bail.
|
|
|
|
if ( !is_user_member_of_blog( $user_id ) )
|
|
|
|
wp_die(__('Cheatin’ uh?'));
|
2010-10-21 20:35:52 +02:00
|
|
|
|
2010-11-25 10:13:38 +01:00
|
|
|
$user = new WP_User( $user_id );
|
|
|
|
$user->set_role( $_REQUEST['new_role'] );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$update = 'err_promote';
|
2010-11-24 06:31:25 +01:00
|
|
|
}
|
|
|
|
break;
|
2010-10-21 20:35:52 +02:00
|
|
|
}
|
2010-11-24 06:31:25 +01:00
|
|
|
|
2010-10-21 20:35:52 +02:00
|
|
|
restore_current_blog();
|
2010-11-25 10:13:38 +01:00
|
|
|
wp_redirect( add_query_arg( 'update', $update, wp_get_referer() ) );
|
2010-11-25 10:25:50 +01:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) {
|
|
|
|
wp_redirect( wp_get_referer() );
|
|
|
|
exit();
|
2010-10-21 20:35:52 +02:00
|
|
|
}
|
|
|
|
|
2010-11-24 06:31:25 +01:00
|
|
|
add_screen_option( 'per_page', array( 'label' => _x( 'Users', 'users per page (screen options)' ) ) );
|
2010-10-21 20:35:52 +02:00
|
|
|
|
|
|
|
$title = sprintf( __('Edit Site: %s'), get_blogaddress_by_id($id));
|
|
|
|
$parent_file = 'sites.php';
|
|
|
|
$submenu_file = 'sites.php';
|
|
|
|
|
2010-11-25 10:13:38 +01:00
|
|
|
require('../admin-header.php'); ?>
|
2010-10-21 20:35:52 +02:00
|
|
|
|
|
|
|
<div class="wrap">
|
2010-10-21 22:24:54 +02:00
|
|
|
<?php screen_icon('ms-admin'); ?>
|
2010-10-21 20:35:52 +02:00
|
|
|
<h2 id="edit-site"><?php echo $title ?></h2>
|
2010-10-25 22:45:58 +02:00
|
|
|
<h3 class="nav-tab-wrapper">
|
2010-10-21 20:35:52 +02:00
|
|
|
<?php
|
|
|
|
$tabs = array( 'site-info' => array( 'label' => __('Info'), 'url' => 'site-info.php'), 'site-options' => array( 'label' => __('Options'), 'url' => 'site-options.php'),
|
|
|
|
'site-users' => array( 'label' => __('Users'), 'url' => 'site-users.php'), 'site-themes' => array( 'label' => __('Themes'), 'url' => 'site-themes.php'));
|
|
|
|
foreach ( $tabs as $tab_id => $tab ) {
|
|
|
|
$class = ( $tab['url'] == $pagenow ) ? ' nav-tab-active' : '';
|
|
|
|
echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
|
|
|
|
}
|
|
|
|
?>
|
2010-11-25 10:13:38 +01:00
|
|
|
</h3><?php
|
|
|
|
|
|
|
|
if ( isset($_GET['update']) ) :
|
|
|
|
switch($_GET['update']) {
|
2010-11-25 12:12:33 +01:00
|
|
|
case 'adduser':
|
2010-11-25 10:13:38 +01:00
|
|
|
echo '<div id="message" class="updated"><p>' . __( 'User added.' ) . '</p></div>';
|
|
|
|
break;
|
|
|
|
case 'err_add_member':
|
|
|
|
echo '<div id="message" class="error"><p>' . __( 'User is already a member of this site.' ) . '</p></div>';
|
|
|
|
break;
|
|
|
|
case 'err_add_notfound':
|
|
|
|
echo '<div id="message" class="error"><p>' . __( 'Enter the username of an existing user.' ) . '</p></div>';
|
|
|
|
break;
|
|
|
|
case 'promote':
|
|
|
|
echo '<div id="message" class="updated"><p>' . __( 'Changed roles.' ) . '</p></div>';
|
|
|
|
break;
|
|
|
|
case 'err_promote':
|
|
|
|
echo '<div id="message" class="error"><p>' . __( 'Select a user to change role.' ) . '</p></div>';
|
|
|
|
break;
|
|
|
|
case 'remove':
|
2010-11-25 12:12:33 +01:00
|
|
|
echo '<div id="message" class="updated"><p>' . __( 'User removed from this site.' ) . '</p></div>';
|
2010-11-25 10:13:38 +01:00
|
|
|
break;
|
|
|
|
case 'err_remove':
|
|
|
|
echo '<div id="message" class="error"><p>' . __( 'Select a user to remove.' ) . '</p></div>';
|
|
|
|
break;
|
2010-11-25 12:12:33 +01:00
|
|
|
case 'newuser':
|
|
|
|
echo '<div id="message" class="updated"><p>' . __( 'User created.' ) . '</p></div>';
|
|
|
|
break;
|
|
|
|
case 'err_new':
|
|
|
|
echo '<div id="message" class="error"><p>' . __( 'Enter the username and email.' ) . '</p></div>';
|
|
|
|
break;
|
|
|
|
case 'err_new_dup':
|
|
|
|
echo '<div id="message" class="error"><p>' . __( 'Duplicated username or email address.' ) . '</p></div>';
|
|
|
|
break;
|
2010-11-25 10:13:38 +01:00
|
|
|
}
|
|
|
|
endif; ?>
|
|
|
|
|
2010-11-24 06:31:25 +01:00
|
|
|
<form class="search-form" action="" method="get">
|
|
|
|
<p class="search-box">
|
|
|
|
<label class="screen-reader-text" for="user-search-input"><?php _e( 'Search Users' ); ?>:</label>
|
|
|
|
<input type="text" id="user-search-input" name="s" value="<?php echo esc_attr($usersearch); ?>" />
|
|
|
|
<?php submit_button( __( 'Search Users' ), 'button', 'submit', false ); ?>
|
|
|
|
</p>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<?php $wp_list_table->views(); ?>
|
|
|
|
|
2010-10-21 20:35:52 +02:00
|
|
|
<form method="post" action="site-users.php?action=update-site">
|
|
|
|
<?php wp_nonce_field( 'edit-site' ); ?>
|
|
|
|
<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
|
|
|
|
|
2010-11-24 06:31:25 +01:00
|
|
|
<?php $wp_list_table->display(); ?>
|
2010-10-21 20:35:52 +02:00
|
|
|
|
|
|
|
</form>
|
|
|
|
|
2010-12-13 12:58:49 +01:00
|
|
|
do_action( 'network_site_users_after_list_table', '' );
|
|
|
|
|
|
|
|
<?php if ( apply_filters( 'show_network_site_users_add_existing_form', true ) ) : ?>
|
2010-11-25 12:12:33 +01:00
|
|
|
<h3 id="add-existing-user"><?php _e('Add Existing User') ?></h3>
|
|
|
|
<p><?php _e( 'Enter the username of an existing user on this network.' ) ?></p>
|
|
|
|
<form action="site-users.php?action=adduser" id="adduser" method="post">
|
2010-11-17 20:45:10 +01:00
|
|
|
<?php wp_nonce_field( 'edit-site' ); ?>
|
|
|
|
<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
|
|
|
|
<table class="form-table">
|
|
|
|
<tr>
|
|
|
|
<th scope="row"><?php _e( 'Username' ); ?></th>
|
2010-11-25 12:12:33 +01:00
|
|
|
<td><input type="text" class="regular-text" name="newuser" id="newuser" /></td>
|
2010-11-17 20:45:10 +01:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th scope="row"><?php _e( 'Role'); ?></th>
|
|
|
|
<td><select name="new_role" id="new_role_0">
|
|
|
|
<?php
|
|
|
|
$default_role = $wpdb->get_var( "SELECT `option_value` FROM {$blog_prefix}options WHERE option_name = 'default_role'" );
|
|
|
|
reset( $editblog_roles );
|
|
|
|
foreach ( $editblog_roles as $role => $role_assoc ){
|
|
|
|
$name = translate_user_role( $role_assoc['name'] );
|
|
|
|
$selected = ( $role == $default_role ) ? 'selected="selected"' : '';
|
|
|
|
echo '<option ' . $selected . ' value="' . esc_attr( $role ) . '">' . esc_html( $name ) . '</option>';
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</select></td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<?php submit_button( __('Add User'), 'primary', 'add-user' ); ?>
|
2010-11-25 12:12:33 +01:00
|
|
|
</form>
|
2010-12-13 12:58:49 +01:00
|
|
|
<?php endif; ?>
|
2010-11-25 12:12:33 +01:00
|
|
|
|
2010-12-13 12:58:49 +01:00
|
|
|
<?php if ( apply_filters( 'show_network_site_users_add_new_form', true ) ) : ?>
|
2010-11-25 12:12:33 +01:00
|
|
|
<h3 id="add-new-user"><?php _e('Create New User') ?></h3>
|
|
|
|
<p><?php _e( 'Create a brand new user and add it to this site.' ) ?></p>
|
|
|
|
<form action="<?php echo network_admin_url('site-users.php?action=newuser'); ?>" id="newuser" method="post">
|
|
|
|
<?php wp_nonce_field( 'edit-site' ); ?>
|
|
|
|
<input type="hidden" name="id" value="<?php echo esc_attr( $id ) ?>" />
|
|
|
|
<table class="form-table">
|
|
|
|
<tr>
|
|
|
|
<th scope="row"><?php _e( 'Username' ) ?></th>
|
|
|
|
<td><input type="text" class="regular-text" name="user[username]" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th scope="row"><?php _e( 'Email' ) ?></th>
|
|
|
|
<td><input type="text" class="regular-text" name="user[email]" /></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<th scope="row"><?php _e( 'Role'); ?></th>
|
|
|
|
<td><select name="new_role" id="new_role_0">
|
|
|
|
<?php
|
|
|
|
reset( $editblog_roles );
|
|
|
|
foreach ( $editblog_roles as $role => $role_assoc ){
|
|
|
|
$name = translate_user_role( $role_assoc['name'] );
|
|
|
|
$selected = ( $role == $default_role ) ? 'selected="selected"' : '';
|
|
|
|
echo '<option ' . $selected . ' value="' . esc_attr( $role ) . '">' . esc_html( $name ) . '</option>';
|
|
|
|
}
|
|
|
|
?>
|
|
|
|
</select></td>
|
|
|
|
</tr>
|
|
|
|
<tr class="form-field">
|
|
|
|
<td colspan="2"><?php _e( 'Username and password will be mailed to the above email address.' ) ?></td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ) ?>
|
|
|
|
<?php submit_button( __('Add User'), 'primary', 'add-user' ); ?>
|
|
|
|
</form>
|
2010-10-21 20:35:52 +02:00
|
|
|
</div>
|
2010-12-13 12:58:49 +01:00
|
|
|
<?php endif; ?>
|
2010-10-21 20:35:52 +02:00
|
|
|
<?php
|
2010-12-13 12:58:49 +01:00
|
|
|
require('../admin-footer.php');
|