Update and error messages for site-users. See #15558.
git-svn-id: http://svn.automattic.com/wordpress/trunk@16582 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
6e2eae9736
commit
cad42deee5
|
@ -51,26 +51,37 @@ if ( ! empty($wp_roles->use_db) ) {
|
||||||
|
|
||||||
$action = $wp_list_table->current_action();
|
$action = $wp_list_table->current_action();
|
||||||
|
|
||||||
|
if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] )
|
||||||
|
wp_redirect( wp_get_referer() );
|
||||||
|
|
||||||
if ( $action ) {
|
if ( $action ) {
|
||||||
switch_to_blog( $id );
|
switch_to_blog( $id );
|
||||||
|
|
||||||
switch ( $action ) {
|
switch ( $action ) {
|
||||||
case 'adduser':
|
case 'adduser':
|
||||||
if ( !empty( $_POST['newuser'] ) ) {
|
if ( !empty( $_POST['newuser'] ) ) {
|
||||||
$newuser = $_POST['newuser'];
|
$update = 'add';
|
||||||
|
$newuser = $_POST['newuser'];
|
||||||
$userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) );
|
$userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) );
|
||||||
if ( $userid ) {
|
if ( $userid ) {
|
||||||
$user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='{$blog_prefix}capabilities'" );
|
$user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='{$blog_prefix}capabilities'" );
|
||||||
if ( $user == false )
|
if ( $user == false )
|
||||||
add_user_to_blog( $id, $userid, $_POST['new_role'] );
|
add_user_to_blog( $id, $userid, $_POST['new_role'] );
|
||||||
|
else
|
||||||
|
$update = 'err_add_member';
|
||||||
|
} else {
|
||||||
|
$update = 'err_add_notfound';
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
$update = 'err_add_notfound';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'remove':
|
case 'remove':
|
||||||
if ( !current_user_can('remove_users') )
|
if ( !current_user_can('remove_users') )
|
||||||
die(__('You can’t remove users.'));
|
die(__('You can’t remove users.'));
|
||||||
|
|
||||||
|
$update = 'remove';
|
||||||
if ( isset( $_REQUEST['users'] ) ) {
|
if ( isset( $_REQUEST['users'] ) ) {
|
||||||
$userids = $_REQUEST['users'];
|
$userids = $_REQUEST['users'];
|
||||||
|
|
||||||
|
@ -78,8 +89,10 @@ if ( $action ) {
|
||||||
$user_id = (int) $user_id;
|
$user_id = (int) $user_id;
|
||||||
remove_user_from_blog( $user_id, $id );
|
remove_user_from_blog( $user_id, $id );
|
||||||
}
|
}
|
||||||
} else {
|
} elseif ( isset( $_GET['user'] ) ) {
|
||||||
remove_user_from_blog( $_GET['user'] );
|
remove_user_from_blog( $_GET['user'] );
|
||||||
|
} else {
|
||||||
|
$update = 'err_remove';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -88,23 +101,27 @@ if ( $action ) {
|
||||||
if ( empty( $editable_roles[$_REQUEST['new_role']] ) )
|
if ( empty( $editable_roles[$_REQUEST['new_role']] ) )
|
||||||
wp_die(__('You can’t give users that role.'));
|
wp_die(__('You can’t give users that role.'));
|
||||||
|
|
||||||
$userids = $_REQUEST['users'];
|
if ( isset( $_REQUEST['users'] ) ) {
|
||||||
$update = 'promote';
|
$userids = $_REQUEST['users'];
|
||||||
foreach ( $userids as $user_id ) {
|
$update = 'promote';
|
||||||
$user_id = (int) $user_id;
|
foreach ( $userids as $user_id ) {
|
||||||
|
$user_id = (int) $user_id;
|
||||||
|
|
||||||
// If the user doesn't already belong to the blog, bail.
|
// If the user doesn't already belong to the blog, bail.
|
||||||
if ( !is_user_member_of_blog( $user_id ) )
|
if ( !is_user_member_of_blog( $user_id ) )
|
||||||
wp_die(__('Cheatin’ uh?'));
|
wp_die(__('Cheatin’ uh?'));
|
||||||
|
|
||||||
$user = new WP_User( $user_id );
|
$user = new WP_User( $user_id );
|
||||||
$user->set_role( $_REQUEST['new_role'] );
|
$user->set_role( $_REQUEST['new_role'] );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$update = 'err_promote';
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
restore_current_blog();
|
restore_current_blog();
|
||||||
wp_redirect( wp_get_referer() ); // @todo add_query_arg for update message
|
wp_redirect( add_query_arg( 'update', $update, wp_get_referer() ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
add_screen_option( 'per_page', array( 'label' => _x( 'Users', 'users per page (screen options)' ) ) );
|
add_screen_option( 'per_page', array( 'label' => _x( 'Users', 'users per page (screen options)' ) ) );
|
||||||
|
@ -113,9 +130,7 @@ $title = sprintf( __('Edit Site: %s'), get_blogaddress_by_id($id));
|
||||||
$parent_file = 'sites.php';
|
$parent_file = 'sites.php';
|
||||||
$submenu_file = 'sites.php';
|
$submenu_file = 'sites.php';
|
||||||
|
|
||||||
require('../admin-header.php');
|
require('../admin-header.php'); ?>
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
<?php screen_icon('ms-admin'); ?>
|
<?php screen_icon('ms-admin'); ?>
|
||||||
|
@ -129,7 +144,34 @@ foreach ( $tabs as $tab_id => $tab ) {
|
||||||
echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
|
echo '<a href="' . $tab['url'] . '?id=' . $id .'" class="nav-tab' . $class . '">' . esc_html( $tab['label'] ) . '</a>';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
</h3>
|
</h3><?php
|
||||||
|
|
||||||
|
if ( isset($_GET['update']) ) :
|
||||||
|
switch($_GET['update']) {
|
||||||
|
case 'add':
|
||||||
|
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':
|
||||||
|
echo '<div id="message" class="updated fade"><p>' . __( 'User removed from this site.' ) . '</p></div>';
|
||||||
|
break;
|
||||||
|
case 'err_remove':
|
||||||
|
echo '<div id="message" class="error"><p>' . __( 'Select a user to remove.' ) . '</p></div>';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
endif; ?>
|
||||||
|
|
||||||
<form class="search-form" action="" method="get">
|
<form class="search-form" action="" method="get">
|
||||||
<p class="search-box">
|
<p class="search-box">
|
||||||
<label class="screen-reader-text" for="user-search-input"><?php _e( 'Search Users' ); ?>:</label>
|
<label class="screen-reader-text" for="user-search-input"><?php _e( 'Search Users' ); ?>:</label>
|
||||||
|
|
Loading…
Reference in New Issue