wp/wp-admin/users.php
changeset 7 cf61fcea0001
parent 5 5e2f62d02dcd
child 9 177826044cd9
equal deleted inserted replaced
6:490d5cc509ed 7:cf61fcea0001
     1 <?php
     1 <?php
     2 /**
     2 /**
     3  * Users administration panel.
     3  * User administration panel
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  * @subpackage Administration
     6  * @subpackage Administration
       
     7  * @since 1.0.0
     7  */
     8  */
     8 
     9 
     9 /** WordPress Administration Bootstrap */
    10 /** WordPress Administration Bootstrap */
    10 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 require_once( dirname( __FILE__ ) . '/admin.php' );
    11 
    12 
    12 if ( ! current_user_can( 'list_users' ) )
    13 if ( ! current_user_can( 'list_users' ) ) {
    13 	wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
    14 	wp_die(
       
    15 		'<h1>' . __( 'You need a higher level of permission.' ) . '</h1>' .
       
    16 		'<p>' . __( 'Sorry, you are not allowed to list users.' ) . '</p>',
       
    17 		403
       
    18 	);
       
    19 }
    14 
    20 
    15 $wp_list_table = _get_list_table('WP_Users_List_Table');
    21 $wp_list_table = _get_list_table('WP_Users_List_Table');
    16 $pagenum = $wp_list_table->get_pagenum();
    22 $pagenum = $wp_list_table->get_pagenum();
    17 $title = __('Users');
    23 $title = __('Users');
    18 $parent_file = 'users.php';
    24 $parent_file = 'users.php';
    26 	'content' => '<p>' . __('This screen lists all the existing users for your site. Each user has one of five defined roles as set by the site admin: Site Administrator, Editor, Author, Contributor, or Subscriber. Users with roles other than Administrator will see fewer options in the dashboard navigation when they are logged in, based on their role.') . '</p>' .
    32 	'content' => '<p>' . __('This screen lists all the existing users for your site. Each user has one of five defined roles as set by the site admin: Site Administrator, Editor, Author, Contributor, or Subscriber. Users with roles other than Administrator will see fewer options in the dashboard navigation when they are logged in, based on their role.') . '</p>' .
    27 				 '<p>' . __('To add a new user for your site, click the Add New button at the top of the screen or Add New in the Users menu section.') . '</p>'
    33 				 '<p>' . __('To add a new user for your site, click the Add New button at the top of the screen or Add New in the Users menu section.') . '</p>'
    28 ) ) ;
    34 ) ) ;
    29 
    35 
    30 get_current_screen()->add_help_tab( array(
    36 get_current_screen()->add_help_tab( array(
    31 	'id'      => 'screen-display',
    37 	'id'      => 'screen-content',
    32 	'title'   => __('Screen Display'),
    38 	'title'   => __('Screen Content'),
    33 	'content' => '<p>' . __('You can customize the display of this screen in a number of ways:') . '</p>' .
    39 	'content' => '<p>' . __('You can customize the display of this screen in a number of ways:') . '</p>' .
    34 					'<ul>' .
    40 					'<ul>' .
    35 					'<li>' . __('You can hide/display columns based on your needs and decide how many users to list per screen using the Screen Options tab.') . '</li>' .
    41 					'<li>' . __('You can hide/display columns based on your needs and decide how many users to list per screen using the Screen Options tab.') . '</li>' .
    36 					'<li>' . __('You can filter the list of users by User Role using the text links in the upper left to show All, Administrator, Editor, Author, Contributor, or Subscriber. The default view is to show all users. Unused User Roles are not listed.') . '</li>' .
    42 					'<li>' . __( 'You can filter the list of users by User Role using the text links above the users list to show All, Administrator, Editor, Author, Contributor, or Subscriber. The default view is to show all users. Unused User Roles are not listed.' ) . '</li>' .
    37 					'<li>' . __('You can view all posts made by a user by clicking on the number under the Posts column.') . '</li>' .
    43 					'<li>' . __('You can view all posts made by a user by clicking on the number under the Posts column.') . '</li>' .
    38 					'</ul>'
    44 					'</ul>'
    39 ) );
    45 ) );
    40 
    46 
    41 $help = '<p>' . __('Hovering over a row in the users list will display action links that allow you to manage users. You can perform the following actions:') . '</p>' .
    47 $help = '<p>' . __('Hovering over a row in the users list will display action links that allow you to manage users. You can perform the following actions:') . '</p>' .
    42 	'<ul>' .
    48 	'<ul>' .
    43 	'<li>' . __('Edit takes you to the editable profile screen for that user. You can also reach that screen by clicking on the username.') . '</li>';
    49 	'<li>' . __('<strong>Edit</strong> takes you to the editable profile screen for that user. You can also reach that screen by clicking on the username.') . '</li>';
    44 
    50 
    45 if ( is_multisite() )
    51 if ( is_multisite() )
    46 	$help .= '<li>' . __( 'Remove allows you to remove a user from your site. It does not delete their content. You can also remove multiple users at once by using Bulk Actions.' ) . '</li>';
    52 	$help .= '<li>' . __( '<strong>Remove</strong> allows you to remove a user from your site. It does not delete their content. You can also remove multiple users at once by using Bulk Actions.' ) . '</li>';
    47 else
    53 else
    48 	$help .= '<li>' . __( 'Delete brings you to the Delete Users screen for confirmation, where you can permanently remove a user from your site and delete their content. You can also delete multiple users at once by using Bulk Actions.' ) . '</li>';
    54 	$help .= '<li>' . __( '<strong>Delete</strong> brings you to the Delete Users screen for confirmation, where you can permanently remove a user from your site and delete their content. You can also delete multiple users at once by using Bulk Actions.' ) . '</li>';
    49 
    55 
    50 $help .= '</ul>';
    56 $help .= '</ul>';
    51 
    57 
    52 get_current_screen()->add_help_tab( array(
    58 get_current_screen()->add_help_tab( array(
    53 	'id'      => 'actions',
    59 	'id'      => 'action-links',
    54 	'title'   => __('Actions'),
    60 	'title'   => __('Available Actions'),
    55 	'content' => $help,
    61 	'content' => $help,
    56 ) );
    62 ) );
    57 unset( $help );
    63 unset( $help );
    58 
    64 
    59 get_current_screen()->set_help_sidebar(
    65 get_current_screen()->set_help_sidebar(
    60     '<p><strong>' . __('For more information:') . '</strong></p>' .
    66     '<p><strong>' . __('For more information:') . '</strong></p>' .
    61     '<p>' . __('<a href="https://codex.wordpress.org/Users_Screen" target="_blank">Documentation on Managing Users</a>') . '</p>' .
    67     '<p>' . __('<a href="https://codex.wordpress.org/Users_Screen">Documentation on Managing Users</a>') . '</p>' .
    62     '<p>' . __('<a href="https://codex.wordpress.org/Roles_and_Capabilities" target="_blank">Descriptions of Roles and Capabilities</a>') . '</p>' .
    68     '<p>' . __('<a href="https://codex.wordpress.org/Roles_and_Capabilities">Descriptions of Roles and Capabilities</a>') . '</p>' .
    63     '<p>' . __('<a href="https://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
    69     '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>'
    64 );
    70 );
       
    71 
       
    72 get_current_screen()->set_screen_reader_content( array(
       
    73 	'heading_views'      => __( 'Filter users list' ),
       
    74 	'heading_pagination' => __( 'Users list navigation' ),
       
    75 	'heading_list'       => __( 'Users list' ),
       
    76 ) );
    65 
    77 
    66 if ( empty($_REQUEST) ) {
    78 if ( empty($_REQUEST) ) {
    67 	$referer = '<input type="hidden" name="wp_http_referer" value="'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
    79 	$referer = '<input type="hidden" name="wp_http_referer" value="'. esc_attr( wp_unslash( $_SERVER['REQUEST_URI'] ) ) . '" />';
    68 } elseif ( isset($_REQUEST['wp_http_referer']) ) {
    80 } elseif ( isset($_REQUEST['wp_http_referer']) ) {
    69 	$redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), wp_unslash( $_REQUEST['wp_http_referer'] ) );
    81 	$redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), wp_unslash( $_REQUEST['wp_http_referer'] ) );
    73 	$referer = '';
    85 	$referer = '';
    74 }
    86 }
    75 
    87 
    76 $update = '';
    88 $update = '';
    77 
    89 
    78 /**
       
    79  * @since 3.5.0
       
    80  * @access private
       
    81  */
       
    82 function delete_users_add_js() { ?>
       
    83 <script>
       
    84 jQuery(document).ready( function($) {
       
    85 	var submit = $('#submit').prop('disabled', true);
       
    86 	$('input[name=delete_option]').one('change', function() {
       
    87 		submit.prop('disabled', false);
       
    88 	});
       
    89 	$('#reassign_user').focus( function() {
       
    90 		$('#delete_option1').prop('checked', true).trigger('change');
       
    91 	});
       
    92 });
       
    93 </script>
       
    94 <?php
       
    95 }
       
    96 
       
    97 switch ( $wp_list_table->current_action() ) {
    90 switch ( $wp_list_table->current_action() ) {
    98 
    91 
    99 /* Bulk Dropdown menu Role changes */
    92 /* Bulk Dropdown menu Role changes */
   100 case 'promote':
    93 case 'promote':
   101 	check_admin_referer('bulk-users');
    94 	check_admin_referer('bulk-users');
   102 
    95 
   103 	if ( ! current_user_can( 'promote_users' ) )
    96 	if ( ! current_user_can( 'promote_users' ) )
   104 		wp_die( __( 'You can&#8217;t edit that user.' ) );
    97 		wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 );
   105 
    98 
   106 	if ( empty($_REQUEST['users']) ) {
    99 	if ( empty($_REQUEST['users']) ) {
   107 		wp_redirect($redirect);
   100 		wp_redirect($redirect);
   108 		exit();
   101 		exit();
   109 	}
   102 	}
   110 
   103 
   111 	$editable_roles = get_editable_roles();
   104 	$editable_roles = get_editable_roles();
   112 	if ( empty( $editable_roles[$_REQUEST['new_role']] ) )
   105 	$role = false;
   113 		wp_die(__('You can&#8217;t give users that role.'));
   106 	if ( ! empty( $_REQUEST['new_role2'] ) ) {
       
   107 		$role = $_REQUEST['new_role2'];
       
   108 	} elseif ( ! empty( $_REQUEST['new_role'] ) ) {
       
   109 		$role = $_REQUEST['new_role'];
       
   110 	}
       
   111 
       
   112 	if ( ! $role || empty( $editable_roles[ $role ] ) ) {
       
   113 		wp_die( __( 'Sorry, you are not allowed to give users that role.' ), 403 );
       
   114 	}
   114 
   115 
   115 	$userids = $_REQUEST['users'];
   116 	$userids = $_REQUEST['users'];
   116 	$update = 'promote';
   117 	$update = 'promote';
   117 	foreach ( $userids as $id ) {
   118 	foreach ( $userids as $id ) {
   118 		$id = (int) $id;
   119 		$id = (int) $id;
   119 
   120 
   120 		if ( ! current_user_can('promote_user', $id) )
   121 		if ( ! current_user_can('promote_user', $id) )
   121 			wp_die(__('You can&#8217;t edit that user.'));
   122 			wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 );
   122 		// The new role of the current user must also have the promote_users cap or be a multisite super admin
   123 		// The new role of the current user must also have the promote_users cap or be a multisite super admin
   123 		if ( $id == $current_user->ID && ! $wp_roles->role_objects[ $_REQUEST['new_role'] ]->has_cap('promote_users')
   124 		if ( $id == $current_user->ID && ! $wp_roles->role_objects[ $role ]->has_cap('promote_users')
   124 			&& ! ( is_multisite() && is_super_admin() ) ) {
   125 			&& ! ( is_multisite() && current_user_can( 'manage_network_users' ) ) ) {
   125 				$update = 'err_admin_role';
   126 				$update = 'err_admin_role';
   126 				continue;
   127 				continue;
   127 		}
   128 		}
   128 
   129 
   129 		// If the user doesn't already belong to the blog, bail.
   130 		// If the user doesn't already belong to the blog, bail.
   130 		if ( is_multisite() && !is_user_member_of_blog( $id ) )
   131 		if ( is_multisite() && !is_user_member_of_blog( $id ) ) {
   131 			wp_die( __( 'Cheatin&#8217; uh?' ), 403 );
   132 			wp_die(
       
   133 				'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
       
   134 				'<p>' . __( 'One of the selected users is not a member of this site.' ) . '</p>',
       
   135 				403
       
   136 			);
       
   137 		}
   132 
   138 
   133 		$user = get_userdata( $id );
   139 		$user = get_userdata( $id );
   134 		$user->set_role($_REQUEST['new_role']);
   140 		$user->set_role( $role );
   135 	}
   141 	}
   136 
   142 
   137 	wp_redirect(add_query_arg('update', $update, $redirect));
   143 	wp_redirect(add_query_arg('update', $update, $redirect));
   138 	exit();
   144 	exit();
   139 
   145 
   140 case 'dodelete':
   146 case 'dodelete':
   141 	if ( is_multisite() )
   147 	if ( is_multisite() )
   142 		wp_die( __('User deletion is not allowed from this screen.') );
   148 		wp_die( __('User deletion is not allowed from this screen.'), 400 );
   143 
   149 
   144 	check_admin_referer('delete-users');
   150 	check_admin_referer('delete-users');
   145 
   151 
   146 	if ( empty($_REQUEST['users']) ) {
   152 	if ( empty($_REQUEST['users']) ) {
   147 		wp_redirect($redirect);
   153 		wp_redirect($redirect);
   156 		wp_redirect( $url );
   162 		wp_redirect( $url );
   157 		exit;
   163 		exit;
   158 	}
   164 	}
   159 
   165 
   160 	if ( ! current_user_can( 'delete_users' ) )
   166 	if ( ! current_user_can( 'delete_users' ) )
   161 		wp_die(__('You can&#8217;t delete users.'));
   167 		wp_die( __( 'Sorry, you are not allowed to delete users.' ), 403 );
   162 
   168 
   163 	$update = 'del';
   169 	$update = 'del';
   164 	$delete_count = 0;
   170 	$delete_count = 0;
   165 
   171 
   166 	foreach ( $userids as $id ) {
   172 	foreach ( $userids as $id ) {
   167 		if ( ! current_user_can( 'delete_user', $id ) )
   173 		if ( ! current_user_can( 'delete_user', $id ) )
   168 			wp_die(__( 'You can&#8217;t delete that user.' ) );
   174 			wp_die( __( 'Sorry, you are not allowed to delete that user.' ), 403 );
   169 
   175 
   170 		if ( $id == $current_user->ID ) {
   176 		if ( $id == $current_user->ID ) {
   171 			$update = 'err_admin_del';
   177 			$update = 'err_admin_del';
   172 			continue;
   178 			continue;
   173 		}
   179 		}
   186 	wp_redirect($redirect);
   192 	wp_redirect($redirect);
   187 	exit();
   193 	exit();
   188 
   194 
   189 case 'delete':
   195 case 'delete':
   190 	if ( is_multisite() )
   196 	if ( is_multisite() )
   191 		wp_die( __('User deletion is not allowed from this screen.') );
   197 		wp_die( __('User deletion is not allowed from this screen.'), 400 );
   192 
   198 
   193 	check_admin_referer('bulk-users');
   199 	check_admin_referer('bulk-users');
   194 
   200 
   195 	if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) {
   201 	if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) {
   196 		wp_redirect($redirect);
   202 		wp_redirect($redirect);
   197 		exit();
   203 		exit();
   198 	}
   204 	}
   199 
   205 
   200 	if ( ! current_user_can( 'delete_users' ) )
   206 	if ( ! current_user_can( 'delete_users' ) )
   201 		$errors = new WP_Error( 'edit_users', __( 'You can&#8217;t delete users.' ) );
   207 		$errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to delete users.' ) );
   202 
   208 
   203 	if ( empty($_REQUEST['users']) )
   209 	if ( empty($_REQUEST['users']) )
   204 		$userids = array( intval( $_REQUEST['user'] ) );
   210 		$userids = array( intval( $_REQUEST['user'] ) );
   205 	else
   211 	else
   206 		$userids = array_map( 'intval', (array) $_REQUEST['users'] );
   212 		$userids = array_map( 'intval', (array) $_REQUEST['users'] );
   207 
   213 
   208 	add_action( 'admin_head', 'delete_users_add_js' );
   214 	$users_have_content = false;
       
   215 	if ( $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE post_author IN( " . implode( ',', $userids ) . " ) LIMIT 1" ) ) {
       
   216 		$users_have_content = true;
       
   217 	} elseif ( $wpdb->get_var( "SELECT link_id FROM {$wpdb->links} WHERE link_owner IN( " . implode( ',', $userids ) . " ) LIMIT 1" ) ) {
       
   218 		$users_have_content = true;
       
   219 	}
       
   220 
       
   221 	if ( $users_have_content ) {
       
   222 		add_action( 'admin_head', 'delete_users_add_js' );
       
   223 	}
   209 
   224 
   210 	include( ABSPATH . 'wp-admin/admin-header.php' );
   225 	include( ABSPATH . 'wp-admin/admin-header.php' );
   211 ?>
   226 ?>
   212 <form method="post" name="updateusers" id="updateusers">
   227 <form method="post" name="updateusers" id="updateusers">
   213 <?php wp_nonce_field('delete-users') ?>
   228 <?php wp_nonce_field('delete-users') ?>
   214 <?php echo $referer; ?>
   229 <?php echo $referer; ?>
   215 
   230 
   216 <div class="wrap">
   231 <div class="wrap">
   217 <h2><?php _e('Delete Users'); ?></h2>
   232 <h1><?php _e( 'Delete Users' ); ?></h1>
   218 <?php if ( isset( $_REQUEST['error'] ) ) : ?>
   233 <?php if ( isset( $_REQUEST['error'] ) ) : ?>
   219 	<div class="error">
   234 	<div class="error">
   220 		<p><strong><?php _e( 'ERROR:' ); ?></strong> <?php _e( 'Please select an option.' ); ?></p>
   235 		<p><strong><?php _e( 'ERROR:' ); ?></strong> <?php _e( 'Please select an option.' ); ?></p>
   221 	</div>
   236 	</div>
   222 <?php endif; ?>
   237 <?php endif; ?>
   231 <?php
   246 <?php
   232 	$go_delete = 0;
   247 	$go_delete = 0;
   233 	foreach ( $userids as $id ) {
   248 	foreach ( $userids as $id ) {
   234 		$user = get_userdata( $id );
   249 		$user = get_userdata( $id );
   235 		if ( $id == $current_user->ID ) {
   250 		if ( $id == $current_user->ID ) {
       
   251 			/* translators: 1: user id, 2: user login */
   236 			echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
   252 			echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
   237 		} else {
   253 		} else {
       
   254 			/* translators: 1: user id, 2: user login */
   238 			echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n";
   255 			echo "<li><input type=\"hidden\" name=\"users[]\" value=\"" . esc_attr($id) . "\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n";
   239 			$go_delete++;
   256 			$go_delete++;
   240 		}
   257 		}
   241 	}
   258 	}
   242 	?>
   259 	?>
   243 	</ul>
   260 	</ul>
   244 <?php if ( $go_delete ) : ?>
   261 <?php if ( $go_delete ) :
   245 	<?php if ( 1 == $go_delete ) : ?>
   262 
   246 		<fieldset><p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p>
   263 	if ( ! $users_have_content ) : ?>
   247 	<?php else : ?>
   264 		<input type="hidden" name="delete_option" value="delete" />
   248 		<fieldset><p><legend><?php _e( 'What should be done with content owned by these users?' ); ?></legend></p>
   265 	<?php else: ?>
   249 	<?php endif; ?>
   266 		<?php if ( 1 == $go_delete ) : ?>
   250 	<ul style="list-style:none;">
   267 			<fieldset><p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p>
   251 		<li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" />
   268 		<?php else : ?>
   252 		<?php _e('Delete all content.'); ?></label></li>
   269 			<fieldset><p><legend><?php _e( 'What should be done with content owned by these users?' ); ?></legend></p>
   253 		<li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
   270 		<?php endif; ?>
   254 		<?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
   271 		<ul style="list-style:none;">
   255 		wp_dropdown_users( array( 'name' => 'reassign_user', 'exclude' => array_diff( $userids, array($current_user->ID) ) ) ); ?></li>
   272 			<li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" />
   256 	</ul></fieldset>
   273 			<?php _e('Delete all content.'); ?></label></li>
   257 	<?php
   274 			<li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
       
   275 			<?php echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
       
   276 			wp_dropdown_users( array(
       
   277 				'name' => 'reassign_user',
       
   278 				'exclude' => array_diff( $userids, array( $current_user->ID ) ),
       
   279 				'show' => 'display_name_with_login',
       
   280 			) ); ?></li>
       
   281 		</ul></fieldset>
       
   282 	<?php endif;
   258 	/**
   283 	/**
   259 	 * Fires at the end of the delete users form prior to the confirm button.
   284 	 * Fires at the end of the delete users form prior to the confirm button.
   260 	 *
   285 	 *
   261 	 * @since 4.0.0
   286 	 * @since 4.0.0
       
   287 	 * @since 4.5.0 The `$userids` parameter was added.
   262 	 *
   288 	 *
   263 	 * @param WP_User $current_user WP_User object for the user being deleted.
   289 	 * @param WP_User $current_user WP_User object for the current user.
       
   290 	 * @param array   $userids      Array of IDs for users being deleted.
   264 	 */
   291 	 */
   265 	do_action( 'delete_user_form', $current_user );
   292 	do_action( 'delete_user_form', $current_user, $userids );
   266 	?>
   293 	?>
   267 	<input type="hidden" name="action" value="dodelete" />
   294 	<input type="hidden" name="action" value="dodelete" />
   268 	<?php submit_button( __('Confirm Deletion'), 'secondary' ); ?>
   295 	<?php submit_button( __('Confirm Deletion'), 'primary' ); ?>
   269 <?php else : ?>
   296 <?php else : ?>
   270 	<p><?php _e('There are no valid users selected for deletion.'); ?></p>
   297 	<p><?php _e('There are no valid users selected for deletion.'); ?></p>
   271 <?php endif; ?>
   298 <?php endif; ?>
   272 </div>
   299 </div>
   273 </form>
   300 </form>
   277 
   304 
   278 case 'doremove':
   305 case 'doremove':
   279 	check_admin_referer('remove-users');
   306 	check_admin_referer('remove-users');
   280 
   307 
   281 	if ( ! is_multisite() )
   308 	if ( ! is_multisite() )
   282 		wp_die( __( 'You can&#8217;t remove users.' ) );
   309 		wp_die( __( 'You can&#8217;t remove users.' ), 400 );
   283 
   310 
   284 	if ( empty($_REQUEST['users']) ) {
   311 	if ( empty($_REQUEST['users']) ) {
   285 		wp_redirect($redirect);
   312 		wp_redirect($redirect);
   286 		exit;
   313 		exit;
   287 	}
   314 	}
   288 
   315 
   289 	if ( ! current_user_can( 'remove_users' ) )
   316 	if ( ! current_user_can( 'remove_users' ) )
   290 		wp_die( __( 'You can&#8217;t remove users.' ) );
   317 		wp_die( __( 'Sorry, you are not allowed to remove users.' ), 403 );
   291 
   318 
   292 	$userids = $_REQUEST['users'];
   319 	$userids = $_REQUEST['users'];
   293 
   320 
   294 	$update = 'remove';
   321 	$update = 'remove';
   295  	foreach ( $userids as $id ) {
   322  	foreach ( $userids as $id ) {
   296 		$id = (int) $id;
   323 		$id = (int) $id;
   297 		if ( $id == $current_user->ID && !is_super_admin() ) {
       
   298 			$update = 'err_admin_remove';
       
   299 			continue;
       
   300 		}
       
   301 		if ( !current_user_can('remove_user', $id) ) {
   324 		if ( !current_user_can('remove_user', $id) ) {
   302 			$update = 'err_admin_remove';
   325 			$update = 'err_admin_remove';
   303 			continue;
   326 			continue;
   304 		}
   327 		}
   305 		remove_user_from_blog($id, $blog_id);
   328 		remove_user_from_blog($id, $blog_id);
   312 case 'remove':
   335 case 'remove':
   313 
   336 
   314 	check_admin_referer('bulk-users');
   337 	check_admin_referer('bulk-users');
   315 
   338 
   316 	if ( ! is_multisite() )
   339 	if ( ! is_multisite() )
   317 		wp_die( __( 'You can&#8217;t remove users.' ) );
   340 		wp_die( __( 'You can&#8217;t remove users.' ), 400 );
   318 
   341 
   319 	if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) {
   342 	if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) {
   320 		wp_redirect($redirect);
   343 		wp_redirect($redirect);
   321 		exit();
   344 		exit();
   322 	}
   345 	}
   323 
   346 
   324 	if ( !current_user_can('remove_users') )
   347 	if ( !current_user_can('remove_users') )
   325 		$error = new WP_Error('edit_users', __('You can&#8217;t remove users.'));
   348 		$error = new WP_Error('edit_users', __('Sorry, you are not allowed to remove users.'));
   326 
   349 
   327 	if ( empty($_REQUEST['users']) )
   350 	if ( empty($_REQUEST['users']) )
   328 		$userids = array(intval($_REQUEST['user']));
   351 		$userids = array(intval($_REQUEST['user']));
   329 	else
   352 	else
   330 		$userids = $_REQUEST['users'];
   353 		$userids = $_REQUEST['users'];
   334 <form method="post" name="updateusers" id="updateusers">
   357 <form method="post" name="updateusers" id="updateusers">
   335 <?php wp_nonce_field('remove-users') ?>
   358 <?php wp_nonce_field('remove-users') ?>
   336 <?php echo $referer; ?>
   359 <?php echo $referer; ?>
   337 
   360 
   338 <div class="wrap">
   361 <div class="wrap">
   339 <h2><?php _e('Remove Users from Site'); ?></h2>
   362 <h1><?php _e( 'Remove Users from Site' ); ?></h1>
   340 <p><?php _e('You have specified these users for removal:'); ?></p>
   363 
       
   364 <?php if ( 1 == count( $userids ) ) : ?>
       
   365 	<p><?php _e( 'You have specified this user for removal:' ); ?></p>
       
   366 <?php else : ?>
       
   367 	<p><?php _e( 'You have specified these users for removal:' ); ?></p>
       
   368 <?php endif; ?>
       
   369 
   341 <ul>
   370 <ul>
   342 <?php
   371 <?php
   343 	$go_remove = false;
   372 	$go_remove = false;
   344  	foreach ( $userids as $id ) {
   373  	foreach ( $userids as $id ) {
   345 		$id = (int) $id;
   374 		$id = (int) $id;
   346  		$user = get_userdata( $id );
   375  		$user = get_userdata( $id );
   347 		if ( $id == $current_user->ID && !is_super_admin() ) {
   376 		if ( ! current_user_can( 'remove_user', $id ) ) {
   348 			echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>The current user will not be removed.</strong>'), $id, $user->user_login) . "</li>\n";
   377 			/* translators: 1: user id, 2: user login */
   349 		} elseif ( !current_user_can('remove_user', $id) ) {
   378 			echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>Sorry, you are not allowed to remove this user.</strong>'), $id, $user->user_login) . "</li>\n";
   350 			echo "<li>" . sprintf(__('ID #%1$s: %2$s <strong>You don\'t have permission to remove this user.</strong>'), $id, $user->user_login) . "</li>\n";
       
   351 		} else {
   379 		} else {
       
   380 			/* translators: 1: user id, 2: user login */
   352 			echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n";
   381 			echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1$s: %2$s'), $id, $user->user_login) . "</li>\n";
   353 			$go_remove = true;
   382 			$go_remove = true;
   354 		}
   383 		}
   355  	}
   384  	}
   356  	?>
   385  	?>
   357 </ul>
   386 </ul>
   358 <?php if ( $go_remove ) : ?>
   387 <?php if ( $go_remove ) : ?>
   359 		<input type="hidden" name="action" value="doremove" />
   388 		<input type="hidden" name="action" value="doremove" />
   360 		<?php submit_button( __('Confirm Removal'), 'secondary' ); ?>
   389 		<?php submit_button( __('Confirm Removal'), 'primary' ); ?>
   361 <?php else : ?>
   390 <?php else : ?>
   362 	<p><?php _e('There are no valid users selected for removal.'); ?></p>
   391 	<p><?php _e('There are no valid users selected for removal.'); ?></p>
   363 <?php endif; ?>
   392 <?php endif; ?>
   364 </div>
   393 </div>
   365 </form>
   394 </form>
   369 
   398 
   370 default:
   399 default:
   371 
   400 
   372 	if ( !empty($_GET['_wp_http_referer']) ) {
   401 	if ( !empty($_GET['_wp_http_referer']) ) {
   373 		wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce'), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
   402 		wp_redirect( remove_query_arg( array( '_wp_http_referer', '_wpnonce'), wp_unslash( $_SERVER['REQUEST_URI'] ) ) );
       
   403 		exit;
       
   404 	}
       
   405 
       
   406 	if ( $wp_list_table->current_action() && ! empty( $_REQUEST['users'] ) ) {
       
   407 		$userids = $_REQUEST['users'];
       
   408 		$sendback = wp_get_referer();
       
   409 
       
   410 		/** This action is documented in wp-admin/edit-comments.php */
       
   411 		$sendback = apply_filters( 'handle_bulk_actions-' . get_current_screen()->id, $sendback, $wp_list_table->current_action(), $userids );
       
   412 
       
   413 		wp_safe_redirect( $sendback );
   374 		exit;
   414 		exit;
   375 	}
   415 	}
   376 
   416 
   377 	$wp_list_table->prepare_items();
   417 	$wp_list_table->prepare_items();
   378 	$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
   418 	$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
   396 			}
   436 			}
   397 			$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $delete_count ) ) . '</p></div>';
   437 			$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $delete_count ) ) . '</p></div>';
   398 			break;
   438 			break;
   399 		case 'add':
   439 		case 'add':
   400 			if ( isset( $_GET['id'] ) && ( $user_id = $_GET['id'] ) && current_user_can( 'edit_user', $user_id ) ) {
   440 			if ( isset( $_GET['id'] ) && ( $user_id = $_GET['id'] ) && current_user_can( 'edit_user', $user_id ) ) {
       
   441 				/* translators: %s: edit page url */
   401 				$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( __( 'New user created. <a href="%s">Edit user</a>' ),
   442 				$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( __( 'New user created. <a href="%s">Edit user</a>' ),
   402 					esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
   443 					esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
   403 						self_admin_url( 'user-edit.php?user_id=' . $user_id ) ) ) ) . '</p></div>';
   444 						self_admin_url( 'user-edit.php?user_id=' . $user_id ) ) ) ) . '</p></div>';
   404 			} else {
   445 			} else {
   405 				$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'New user created.' ) . '</p></div>';
   446 				$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'New user created.' ) . '</p></div>';
   441 	foreach ( $messages as $msg )
   482 	foreach ( $messages as $msg )
   442 		echo $msg;
   483 		echo $msg;
   443 } ?>
   484 } ?>
   444 
   485 
   445 <div class="wrap">
   486 <div class="wrap">
   446 <h2>
   487 <h1 class="wp-heading-inline"><?php
   447 <?php
       
   448 echo esc_html( $title );
   488 echo esc_html( $title );
       
   489 ?></h1>
       
   490 
       
   491 <?php
   449 if ( current_user_can( 'create_users' ) ) { ?>
   492 if ( current_user_can( 'create_users' ) ) { ?>
   450 	<a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
   493 	<a href="<?php echo admin_url( 'user-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
   451 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?>
   494 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?>
   452 	<a href="user-new.php" class="add-new-h2"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a>
   495 	<a href="<?php echo admin_url( 'user-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a>
   453 <?php }
   496 <?php }
   454 
   497 
   455 if ( $usersearch )
   498 if ( strlen( $usersearch ) ) {
   456 	printf( '<span class="subtitle">' . __('Search results for &#8220;%s&#8221;') . '</span>', esc_html( $usersearch ) ); ?>
   499 	/* translators: %s: search keywords */
   457 </h2>
   500 	printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );
       
   501 }
       
   502 ?>
       
   503 
       
   504 <hr class="wp-header-end">
   458 
   505 
   459 <?php $wp_list_table->views(); ?>
   506 <?php $wp_list_table->views(); ?>
   460 
   507 
   461 <form method="get">
   508 <form method="get">
   462 
   509 
   463 <?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?>
   510 <?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?>
       
   511 
       
   512 <?php if ( ! empty( $_REQUEST['role'] ) ) { ?>
       
   513 <input type="hidden" name="role" value="<?php echo esc_attr( $_REQUEST['role'] ); ?>" />
       
   514 <?php } ?>
   464 
   515 
   465 <?php $wp_list_table->display(); ?>
   516 <?php $wp_list_table->display(); ?>
   466 </form>
   517 </form>
   467 
   518 
   468 <br class="clear" />
   519 <br class="clear" />