wp/wp-admin/users.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
    31 get_current_screen()->add_help_tab(
    31 get_current_screen()->add_help_tab(
    32 	array(
    32 	array(
    33 		'id'      => 'overview',
    33 		'id'      => 'overview',
    34 		'title'   => __( 'Overview' ),
    34 		'title'   => __( 'Overview' ),
    35 		'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>' .
    35 		'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>' .
    36 						'<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>',
    36 		'<p>' . __( 'To add a new user for your site, click the Add New User button at the top of the screen or Add New User in the Users menu section.' ) . '</p>',
    37 	)
    37 	)
    38 );
    38 );
    39 
    39 
    40 get_current_screen()->add_help_tab(
    40 get_current_screen()->add_help_tab(
    41 	array(
    41 	array(
    58 	$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>';
    58 	$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>';
    59 } else {
    59 } else {
    60 	$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>';
    60 	$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>';
    61 }
    61 }
    62 
    62 
       
    63 $help .= '<li>' . __( '<strong>View</strong> takes you to a public author archive which lists all the posts published by the user.' ) . '</li>';
       
    64 
       
    65 if ( current_user_can( 'edit_users' ) ) {
       
    66 	$help .= '<li>' . __( '<strong>Send password reset</strong> sends the user an email with a link to set a new password.' ) . '</li>';
       
    67 }
       
    68 
    63 $help .= '</ul>';
    69 $help .= '</ul>';
    64 
    70 
    65 get_current_screen()->add_help_tab(
    71 get_current_screen()->add_help_tab(
    66 	array(
    72 	array(
    67 		'id'      => 'action-links',
    73 		'id'      => 'action-links',
    71 );
    77 );
    72 unset( $help );
    78 unset( $help );
    73 
    79 
    74 get_current_screen()->set_help_sidebar(
    80 get_current_screen()->set_help_sidebar(
    75 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    81 	'<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
    76 	'<p>' . __( '<a href="https://wordpress.org/support/article/users-screen/">Documentation on Managing Users</a>' ) . '</p>' .
    82 	'<p>' . __( '<a href="https://wordpress.org/documentation/article/users-screen/">Documentation on Managing Users</a>' ) . '</p>' .
    77 	'<p>' . __( '<a href="https://wordpress.org/support/article/roles-and-capabilities/">Descriptions of Roles and Capabilities</a>' ) . '</p>' .
    83 	'<p>' . __( '<a href="https://wordpress.org/documentation/article/roles-and-capabilities/">Descriptions of Roles and Capabilities</a>' ) . '</p>' .
    78 	'<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>'
    84 	'<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>'
    79 );
    85 );
    80 
    86 
    81 get_current_screen()->set_screen_reader_content(
    87 get_current_screen()->set_screen_reader_content(
    82 	array(
    88 	array(
    83 		'heading_views'      => __( 'Filter users list' ),
    89 		'heading_views'      => __( 'Filter users list' ),
   127 
   133 
   128 		if ( 'none' === $role ) {
   134 		if ( 'none' === $role ) {
   129 			$role = '';
   135 			$role = '';
   130 		}
   136 		}
   131 
   137 
   132 		$userids = $_REQUEST['users'];
   138 		$user_ids = array_map( 'intval', (array) $_REQUEST['users'] );
   133 		$update  = 'promote';
   139 		$update   = 'promote';
   134 		foreach ( $userids as $id ) {
   140 
   135 			$id = (int) $id;
   141 		foreach ( $user_ids as $id ) {
   136 
       
   137 			if ( ! current_user_can( 'promote_user', $id ) ) {
   142 			if ( ! current_user_can( 'promote_user', $id ) ) {
   138 				wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 );
   143 				wp_die( __( 'Sorry, you are not allowed to edit this user.' ), 403 );
   139 			}
   144 			}
   140 
   145 
   141 			// The new role of the current user must also have the promote_users cap or be a multisite super admin.
   146 			// The new role of the current user must also have the promote_users cap or be a multisite super admin.
   142 			if ( $id == $current_user->ID && ! $wp_roles->role_objects[ $role ]->has_cap( 'promote_users' )
   147 			if ( $id === $current_user->ID
   143 			&& ! ( is_multisite() && current_user_can( 'manage_network_users' ) ) ) {
   148 				&& ! $wp_roles->role_objects[ $role ]->has_cap( 'promote_users' )
       
   149 				&& ! ( is_multisite() && current_user_can( 'manage_network_users' ) )
       
   150 			) {
   144 					$update = 'err_admin_role';
   151 					$update = 'err_admin_role';
   145 					continue;
   152 					continue;
   146 			}
   153 			}
   147 
   154 
   148 			// If the user doesn't already belong to the blog, bail.
   155 			// If the user doesn't already belong to the blog, bail.
   171 		if ( empty( $_REQUEST['users'] ) ) {
   178 		if ( empty( $_REQUEST['users'] ) ) {
   172 			wp_redirect( $redirect );
   179 			wp_redirect( $redirect );
   173 			exit;
   180 			exit;
   174 		}
   181 		}
   175 
   182 
   176 		$userids = array_map( 'intval', (array) $_REQUEST['users'] );
   183 		$user_ids = array_map( 'intval', (array) $_REQUEST['users'] );
   177 
   184 
   178 		if ( empty( $_REQUEST['delete_option'] ) ) {
   185 		if ( empty( $_REQUEST['delete_option'] ) ) {
   179 			$url = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $userids ) . '&error=true' );
   186 			$url = self_admin_url( 'users.php?action=delete&users[]=' . implode( '&users[]=', $user_ids ) . '&error=true' );
   180 			$url = str_replace( '&amp;', '&', wp_nonce_url( $url, 'bulk-users' ) );
   187 			$url = str_replace( '&amp;', '&', wp_nonce_url( $url, 'bulk-users' ) );
   181 			wp_redirect( $url );
   188 			wp_redirect( $url );
   182 			exit;
   189 			exit;
   183 		}
   190 		}
   184 
   191 
   187 		}
   194 		}
   188 
   195 
   189 		$update       = 'del';
   196 		$update       = 'del';
   190 		$delete_count = 0;
   197 		$delete_count = 0;
   191 
   198 
   192 		foreach ( $userids as $id ) {
   199 		foreach ( $user_ids as $id ) {
   193 			if ( ! current_user_can( 'delete_user', $id ) ) {
   200 			if ( ! current_user_can( 'delete_user', $id ) ) {
   194 				wp_die( __( 'Sorry, you are not allowed to delete that user.' ), 403 );
   201 				wp_die( __( 'Sorry, you are not allowed to delete that user.' ), 403 );
   195 			}
   202 			}
   196 
   203 
   197 			if ( $id == $current_user->ID ) {
   204 			if ( $id === $current_user->ID ) {
   198 				$update = 'err_admin_del';
   205 				$update = 'err_admin_del';
   199 				continue;
   206 				continue;
   200 			}
   207 			}
       
   208 
   201 			switch ( $_REQUEST['delete_option'] ) {
   209 			switch ( $_REQUEST['delete_option'] ) {
   202 				case 'delete':
   210 				case 'delete':
   203 					wp_delete_user( $id );
   211 					wp_delete_user( $id );
   204 					break;
   212 					break;
   205 				case 'reassign':
   213 				case 'reassign':
   206 					wp_delete_user( $id, $_REQUEST['reassign_user'] );
   214 					wp_delete_user( $id, $_REQUEST['reassign_user'] );
   207 					break;
   215 					break;
   208 			}
   216 			}
       
   217 
   209 			++$delete_count;
   218 			++$delete_count;
   210 		}
   219 		}
   211 
   220 
   212 		$redirect = add_query_arg(
   221 		$redirect = add_query_arg(
   213 			array(
   222 			array(
   219 		wp_redirect( $redirect );
   228 		wp_redirect( $redirect );
   220 		exit;
   229 		exit;
   221 
   230 
   222 	case 'resetpassword':
   231 	case 'resetpassword':
   223 		check_admin_referer( 'bulk-users' );
   232 		check_admin_referer( 'bulk-users' );
       
   233 
   224 		if ( ! current_user_can( 'edit_users' ) ) {
   234 		if ( ! current_user_can( 'edit_users' ) ) {
   225 			$errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to edit users.' ) );
   235 			$errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to edit users.' ) );
   226 		}
   236 		}
       
   237 
   227 		if ( empty( $_REQUEST['users'] ) ) {
   238 		if ( empty( $_REQUEST['users'] ) ) {
   228 			wp_redirect( $redirect );
   239 			wp_redirect( $redirect );
   229 			exit();
   240 			exit();
   230 		}
   241 		}
   231 		$userids = array_map( 'intval', (array) $_REQUEST['users'] );
   242 
       
   243 		$user_ids = array_map( 'intval', (array) $_REQUEST['users'] );
   232 
   244 
   233 		$reset_count = 0;
   245 		$reset_count = 0;
   234 
   246 
   235 		foreach ( $userids as $id ) {
   247 		foreach ( $user_ids as $id ) {
   236 			if ( ! current_user_can( 'edit_user', $id ) ) {
   248 			if ( ! current_user_can( 'edit_user', $id ) ) {
   237 				wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
   249 				wp_die( __( 'Sorry, you are not allowed to edit this user.' ) );
   238 			}
   250 			}
   239 
   251 
   240 			if ( $id === $current_user->ID ) {
   252 			if ( $id === $current_user->ID ) {
   242 				continue;
   254 				continue;
   243 			}
   255 			}
   244 
   256 
   245 			// Send the password reset link.
   257 			// Send the password reset link.
   246 			$user = get_userdata( $id );
   258 			$user = get_userdata( $id );
   247 			if ( retrieve_password( $user->user_login ) ) {
   259 			if ( true === retrieve_password( $user->user_login ) ) {
   248 				++$reset_count;
   260 				++$reset_count;
   249 			}
   261 			}
   250 		}
   262 		}
   251 
   263 
   252 		$redirect = add_query_arg(
   264 		$redirect = add_query_arg(
   274 		if ( ! current_user_can( 'delete_users' ) ) {
   286 		if ( ! current_user_can( 'delete_users' ) ) {
   275 			$errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to delete users.' ) );
   287 			$errors = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to delete users.' ) );
   276 		}
   288 		}
   277 
   289 
   278 		if ( empty( $_REQUEST['users'] ) ) {
   290 		if ( empty( $_REQUEST['users'] ) ) {
   279 			$userids = array( (int) $_REQUEST['user'] );
   291 			$user_ids = array( (int) $_REQUEST['user'] );
   280 		} else {
   292 		} else {
   281 			$userids = array_map( 'intval', (array) $_REQUEST['users'] );
   293 			$user_ids = array_map( 'intval', (array) $_REQUEST['users'] );
   282 		}
   294 		}
   283 
   295 
   284 		$all_userids = $userids;
   296 		$all_user_ids = $user_ids;
   285 
   297 
   286 		if ( in_array( $current_user->ID, $userids, true ) ) {
   298 		if ( in_array( $current_user->ID, $user_ids, true ) ) {
   287 			$userids = array_diff( $userids, array( $current_user->ID ) );
   299 			$user_ids = array_diff( $user_ids, array( $current_user->ID ) );
   288 		}
   300 		}
   289 
   301 
   290 		/**
   302 		/**
   291 		 * Filters whether the users being deleted have additional content
   303 		 * Filters whether the users being deleted have additional content
   292 		 * associated with them outside of the `post_author` and `link_owner` relationships.
   304 		 * associated with them outside of the `post_author` and `link_owner` relationships.
   293 		 *
   305 		 *
   294 		 * @since 5.2.0
   306 		 * @since 5.2.0
   295 		 *
   307 		 *
   296 		 * @param bool  $users_have_additional_content Whether the users have additional content. Default false.
   308 		 * @param bool  $users_have_additional_content Whether the users have additional content. Default false.
   297 		 * @param int[] $userids                       Array of IDs for users being deleted.
   309 		 * @param int[] $user_ids                      Array of IDs for users being deleted.
   298 		 */
   310 		 */
   299 		$users_have_content = (bool) apply_filters( 'users_have_additional_content', false, $userids );
   311 		$users_have_content = (bool) apply_filters( 'users_have_additional_content', false, $user_ids );
   300 
   312 
   301 		if ( $userids && ! $users_have_content ) {
   313 		if ( $user_ids && ! $users_have_content ) {
   302 			if ( $wpdb->get_var( "SELECT ID FROM {$wpdb->posts} WHERE post_author IN( " . implode( ',', $userids ) . ' ) LIMIT 1' ) ) {
   314 			if ( $wpdb->get_var(
       
   315 				"SELECT ID FROM {$wpdb->posts}
       
   316 				WHERE post_author IN( " . implode( ',', $user_ids ) . ' )
       
   317 				LIMIT 1'
       
   318 			) ) {
   303 				$users_have_content = true;
   319 				$users_have_content = true;
   304 			} elseif ( $wpdb->get_var( "SELECT link_id FROM {$wpdb->links} WHERE link_owner IN( " . implode( ',', $userids ) . ' ) LIMIT 1' ) ) {
   320 			} elseif ( $wpdb->get_var(
       
   321 				"SELECT link_id FROM {$wpdb->links}
       
   322 				WHERE link_owner IN( " . implode( ',', $user_ids ) . ' )
       
   323 				LIMIT 1'
       
   324 			) ) {
   305 				$users_have_content = true;
   325 				$users_have_content = true;
   306 			}
   326 			}
   307 		}
   327 		}
   308 
   328 
   309 		if ( $users_have_content ) {
   329 		if ( $users_have_content ) {
   310 			add_action( 'admin_head', 'delete_users_add_js' );
   330 			add_action( 'admin_head', 'delete_users_add_js' );
   311 		}
   331 		}
   312 
   332 
   313 		require_once ABSPATH . 'wp-admin/admin-header.php';
   333 		require_once ABSPATH . 'wp-admin/admin-header.php';
   314 		?>
   334 		?>
   315 	<form method="post" name="updateusers" id="updateusers">
   335 		<form method="post" name="updateusers" id="updateusers">
   316 		<?php wp_nonce_field( 'delete-users' ); ?>
   336 		<?php wp_nonce_field( 'delete-users' ); ?>
   317 		<?php echo $referer; ?>
   337 		<?php echo $referer; ?>
   318 
   338 
   319 <div class="wrap">
   339 		<div class="wrap">
   320 <h1><?php _e( 'Delete Users' ); ?></h1>
   340 		<h1><?php _e( 'Delete Users' ); ?></h1>
   321 		<?php if ( isset( $_REQUEST['error'] ) ) : ?>
   341 
   322 	<div class="error">
   342 		<?php
   323 		<p><strong><?php _e( 'Error:' ); ?></strong> <?php _e( 'Please select an option.' ); ?></p>
   343 		if ( isset( $_REQUEST['error'] ) ) :
   324 	</div>
   344 			wp_admin_notice(
       
   345 				'<strong>' . __( 'Error:' ) . '</strong> ' . __( 'Please select an option.' ),
       
   346 				array(
       
   347 					'additional_classes' => array( 'error' ),
       
   348 				)
       
   349 			);
       
   350 		endif;
       
   351 		?>
       
   352 
       
   353 		<?php if ( 1 === count( $all_user_ids ) ) : ?>
       
   354 			<p><?php _e( 'You have specified this user for deletion:' ); ?></p>
       
   355 		<?php else : ?>
       
   356 			<p><?php _e( 'You have specified these users for deletion:' ); ?></p>
   325 		<?php endif; ?>
   357 		<?php endif; ?>
   326 
   358 
   327 		<?php if ( 1 === count( $all_userids ) ) : ?>
   359 		<ul>
   328 	<p><?php _e( 'You have specified this user for deletion:' ); ?></p>
       
   329 		<?php else : ?>
       
   330 	<p><?php _e( 'You have specified these users for deletion:' ); ?></p>
       
   331 		<?php endif; ?>
       
   332 
       
   333 <ul>
       
   334 		<?php
   360 		<?php
   335 		$go_delete = 0;
   361 		$go_delete = 0;
   336 		foreach ( $all_userids as $id ) {
   362 
       
   363 		foreach ( $all_user_ids as $id ) {
   337 			$user = get_userdata( $id );
   364 			$user = get_userdata( $id );
   338 			if ( $id == $current_user->ID ) {
   365 
   339 				/* translators: 1: User ID, 2: User login. */
   366 			if ( $id === $current_user->ID ) {
   340 				echo '<li>' . sprintf( __( 'ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>' ), $id, $user->user_login ) . "</li>\n";
   367 				echo '<li>';
       
   368 				printf(
       
   369 					/* translators: 1: User ID, 2: User login. */
       
   370 					__( 'ID #%1$s: %2$s <strong>The current user will not be deleted.</strong>' ),
       
   371 					$id,
       
   372 					$user->user_login
       
   373 				);
       
   374 				echo "</li>\n";
   341 			} else {
   375 			} else {
   342 				/* translators: 1: User ID, 2: User login. */
   376 				echo '<li>';
   343 				echo '<li><input type="hidden" name="users[]" value="' . esc_attr( $id ) . '" />' . sprintf( __( 'ID #%1$s: %2$s' ), $id, $user->user_login ) . "</li>\n";
   377 				printf(
   344 				$go_delete++;
   378 					'<input type="hidden" name="users[]" value="%s" />',
       
   379 					esc_attr( $id )
       
   380 				);
       
   381 				printf(
       
   382 					/* translators: 1: User ID, 2: User login. */
       
   383 					__( 'ID #%1$s: %2$s' ),
       
   384 					$id,
       
   385 					$user->user_login
       
   386 				);
       
   387 				echo "</li>\n";
       
   388 
       
   389 				++$go_delete;
   345 			}
   390 			}
   346 		}
   391 		}
   347 		?>
   392 		?>
   348 	</ul>
   393 		</ul>
       
   394 
   349 		<?php
   395 		<?php
   350 		if ( $go_delete ) :
   396 		if ( $go_delete ) :
   351 
   397 
   352 			if ( ! $users_have_content ) :
   398 			if ( ! $users_have_content ) :
   353 				?>
   399 				?>
   354 			<input type="hidden" name="delete_option" value="delete" />
   400 				<input type="hidden" name="delete_option" value="delete" />
   355 			<?php else : ?>
   401 			<?php else : ?>
   356 				<?php if ( 1 == $go_delete ) : ?>
   402 				<fieldset>
   357 			<fieldset><p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p>
   403 				<?php if ( 1 === $go_delete ) : ?>
   358 		<?php else : ?>
   404 					<p><legend><?php _e( 'What should be done with content owned by this user?' ); ?></legend></p>
   359 			<fieldset><p><legend><?php _e( 'What should be done with content owned by these users?' ); ?></legend></p>
   405 				<?php else : ?>
   360 		<?php endif; ?>
   406 					<p><legend><?php _e( 'What should be done with content owned by these users?' ); ?></legend></p>
   361 		<ul style="list-style:none;">
   407 				<?php endif; ?>
   362 			<li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" />
   408 
   363 				<?php _e( 'Delete all content.' ); ?></label></li>
   409 				<ul style="list-style:none;">
   364 			<li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
   410 					<li>
       
   411 						<input type="radio" id="delete_option0" name="delete_option" value="delete" />
       
   412 						<label for="delete_option0"><?php _e( 'Delete all content.' ); ?></label>
       
   413 					</li>
       
   414 					<li>
       
   415 						<input type="radio" id="delete_option1" name="delete_option" value="reassign" />
       
   416 						<label for="delete_option1"><?php _e( 'Attribute all content to:' ); ?></label>
       
   417 						<?php
       
   418 						wp_dropdown_users(
       
   419 							array(
       
   420 								'name'    => 'reassign_user',
       
   421 								'exclude' => $user_ids,
       
   422 								'show'    => 'display_name_with_login',
       
   423 							)
       
   424 						);
       
   425 						?>
       
   426 					</li>
       
   427 				</ul>
       
   428 				</fieldset>
   365 				<?php
   429 				<?php
   366 				echo '<label for="delete_option1">' . __( 'Attribute all content to:' ) . '</label> ';
   430 			endif;
   367 				wp_dropdown_users(
   431 
   368 					array(
       
   369 						'name'    => 'reassign_user',
       
   370 						'exclude' => $userids,
       
   371 						'show'    => 'display_name_with_login',
       
   372 					)
       
   373 				);
       
   374 				?>
       
   375 			</li>
       
   376 		</ul></fieldset>
       
   377 				<?php
       
   378 	endif;
       
   379 			/**
   432 			/**
   380 			 * Fires at the end of the delete users form prior to the confirm button.
   433 			 * Fires at the end of the delete users form prior to the confirm button.
   381 			 *
   434 			 *
   382 			 * @since 4.0.0
   435 			 * @since 4.0.0
   383 			 * @since 4.5.0 The `$userids` parameter was added.
   436 			 * @since 4.5.0 The `$user_ids` parameter was added.
   384 			 *
   437 			 *
   385 			 * @param WP_User $current_user WP_User object for the current user.
   438 			 * @param WP_User $current_user WP_User object for the current user.
   386 			 * @param int[]   $userids      Array of IDs for users being deleted.
   439 			 * @param int[]   $user_ids     Array of IDs for users being deleted.
   387 			 */
   440 			 */
   388 			do_action( 'delete_user_form', $current_user, $userids );
   441 			do_action( 'delete_user_form', $current_user, $user_ids );
   389 			?>
   442 			?>
   390 	<input type="hidden" name="action" value="dodelete" />
   443 			<input type="hidden" name="action" value="dodelete" />
   391 			<?php submit_button( __( 'Confirm Deletion' ), 'primary' ); ?>
   444 			<?php submit_button( __( 'Confirm Deletion' ), 'primary' ); ?>
   392 	<?php else : ?>
   445 
   393 	<p><?php _e( 'There are no valid users selected for deletion.' ); ?></p>
   446 		<?php else : ?>
   394 	<?php endif; ?>
   447 
   395 	</div>
   448 			<p><?php _e( 'There are no valid users selected for deletion.' ); ?></p>
   396 	</form>
   449 
       
   450 		<?php endif; ?>
       
   451 		</div><!-- .wrap -->
       
   452 		</form><!-- #updateusers -->
   397 		<?php
   453 		<?php
   398 
   454 
   399 		break;
   455 		break;
   400 
   456 
   401 	case 'doremove':
   457 	case 'doremove':
   412 
   468 
   413 		if ( ! current_user_can( 'remove_users' ) ) {
   469 		if ( ! current_user_can( 'remove_users' ) ) {
   414 			wp_die( __( 'Sorry, you are not allowed to remove users.' ), 403 );
   470 			wp_die( __( 'Sorry, you are not allowed to remove users.' ), 403 );
   415 		}
   471 		}
   416 
   472 
   417 		$userids = $_REQUEST['users'];
   473 		$user_ids = array_map( 'intval', (array) $_REQUEST['users'] );
   418 
   474 		$update   = 'remove';
   419 		$update = 'remove';
   475 
   420 		foreach ( $userids as $id ) {
   476 		foreach ( $user_ids as $id ) {
   421 			$id = (int) $id;
       
   422 			if ( ! current_user_can( 'remove_user', $id ) ) {
   477 			if ( ! current_user_can( 'remove_user', $id ) ) {
   423 				$update = 'err_admin_remove';
   478 				$update = 'err_admin_remove';
   424 				continue;
   479 				continue;
   425 			}
   480 			}
       
   481 
   426 			remove_user_from_blog( $id, $blog_id );
   482 			remove_user_from_blog( $id, $blog_id );
   427 		}
   483 		}
   428 
   484 
   429 		$redirect = add_query_arg( array( 'update' => $update ), $redirect );
   485 		$redirect = add_query_arg( array( 'update' => $update ), $redirect );
   430 		wp_redirect( $redirect );
   486 		wp_redirect( $redirect );
   445 		if ( ! current_user_can( 'remove_users' ) ) {
   501 		if ( ! current_user_can( 'remove_users' ) ) {
   446 			$error = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to remove users.' ) );
   502 			$error = new WP_Error( 'edit_users', __( 'Sorry, you are not allowed to remove users.' ) );
   447 		}
   503 		}
   448 
   504 
   449 		if ( empty( $_REQUEST['users'] ) ) {
   505 		if ( empty( $_REQUEST['users'] ) ) {
   450 			$userids = array( (int) $_REQUEST['user'] );
   506 			$user_ids = array( (int) $_REQUEST['user'] );
   451 		} else {
   507 		} else {
   452 			$userids = $_REQUEST['users'];
   508 			$user_ids = array_map( 'intval', (array) $_REQUEST['users'] );
   453 		}
   509 		}
   454 
   510 
   455 		require_once ABSPATH . 'wp-admin/admin-header.php';
   511 		require_once ABSPATH . 'wp-admin/admin-header.php';
   456 		?>
   512 		?>
   457 	<form method="post" name="updateusers" id="updateusers">
   513 		<form method="post" name="updateusers" id="updateusers">
   458 		<?php wp_nonce_field( 'remove-users' ); ?>
   514 		<?php wp_nonce_field( 'remove-users' ); ?>
   459 		<?php echo $referer; ?>
   515 		<?php echo $referer; ?>
   460 
   516 
   461 <div class="wrap">
   517 		<div class="wrap">
   462 <h1><?php _e( 'Remove Users from Site' ); ?></h1>
   518 		<h1><?php _e( 'Remove Users from Site' ); ?></h1>
   463 
   519 
   464 		<?php if ( 1 === count( $userids ) ) : ?>
   520 		<?php if ( 1 === count( $user_ids ) ) : ?>
   465 	<p><?php _e( 'You have specified this user for removal:' ); ?></p>
   521 			<p><?php _e( 'You have specified this user for removal:' ); ?></p>
   466 		<?php else : ?>
   522 		<?php else : ?>
   467 	<p><?php _e( 'You have specified these users for removal:' ); ?></p>
   523 			<p><?php _e( 'You have specified these users for removal:' ); ?></p>
   468 		<?php endif; ?>
   524 		<?php endif; ?>
   469 
   525 
   470 <ul>
   526 		<ul>
   471 		<?php
   527 		<?php
   472 		$go_remove = false;
   528 		$go_remove = false;
   473 		foreach ( $userids as $id ) {
   529 
   474 			$id   = (int) $id;
   530 		foreach ( $user_ids as $id ) {
   475 			$user = get_userdata( $id );
   531 			$user = get_userdata( $id );
       
   532 
   476 			if ( ! current_user_can( 'remove_user', $id ) ) {
   533 			if ( ! current_user_can( 'remove_user', $id ) ) {
   477 				/* translators: 1: User ID, 2: User login. */
   534 				echo '<li>';
   478 				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";
   535 				printf(
       
   536 					/* translators: 1: User ID, 2: User login. */
       
   537 					__( 'ID #%1$s: %2$s <strong>Sorry, you are not allowed to remove this user.</strong>' ),
       
   538 					$id,
       
   539 					$user->user_login
       
   540 				);
       
   541 				echo "</li>\n";
   479 			} else {
   542 			} else {
   480 				/* translators: 1: User ID, 2: User login. */
   543 				echo '<li>';
   481 				echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf( __( 'ID #%1$s: %2$s' ), $id, $user->user_login ) . "</li>\n";
   544 				printf(
       
   545 					'<input type="hidden" name="users[]" value="%s" />',
       
   546 					esc_attr( $id )
       
   547 				);
       
   548 				printf(
       
   549 					/* translators: 1: User ID, 2: User login. */
       
   550 					__( 'ID #%1$s: %2$s' ),
       
   551 					$id,
       
   552 					$user->user_login
       
   553 				);
       
   554 				echo "</li>\n";
       
   555 
   482 				$go_remove = true;
   556 				$go_remove = true;
   483 			}
   557 			}
   484 		}
   558 		}
   485 		?>
   559 		?>
   486 	</ul>
   560 		</ul>
       
   561 
   487 		<?php if ( $go_remove ) : ?>
   562 		<?php if ( $go_remove ) : ?>
   488 		<input type="hidden" name="action" value="doremove" />
   563 
       
   564 			<input type="hidden" name="action" value="doremove" />
   489 			<?php submit_button( __( 'Confirm Removal' ), 'primary' ); ?>
   565 			<?php submit_button( __( 'Confirm Removal' ), 'primary' ); ?>
   490 	<?php else : ?>
   566 
   491 	<p><?php _e( 'There are no valid users selected for removal.' ); ?></p>
   567 		<?php else : ?>
   492 	<?php endif; ?>
   568 
   493 	</div>
   569 			<p><?php _e( 'There are no valid users selected for removal.' ); ?></p>
   494 	</form>
   570 
       
   571 		<?php endif; ?>
       
   572 		</div><!-- .wrap -->
       
   573 		</form><!-- #updateusers -->
   495 		<?php
   574 		<?php
   496 
   575 
   497 		break;
   576 		break;
   498 
   577 
   499 	default:
   578 	default:
   503 		}
   582 		}
   504 
   583 
   505 		if ( $wp_list_table->current_action() && ! empty( $_REQUEST['users'] ) ) {
   584 		if ( $wp_list_table->current_action() && ! empty( $_REQUEST['users'] ) ) {
   506 			$screen   = get_current_screen()->id;
   585 			$screen   = get_current_screen()->id;
   507 			$sendback = wp_get_referer();
   586 			$sendback = wp_get_referer();
   508 			$userids  = $_REQUEST['users'];
   587 			$user_ids = array_map( 'intval', (array) $_REQUEST['users'] );
   509 
   588 
   510 			/** This action is documented in wp-admin/edit.php */
   589 			/** This action is documented in wp-admin/edit.php */
   511 			$sendback = apply_filters( "handle_bulk_actions-{$screen}", $sendback, $wp_list_table->current_action(), $userids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
   590 			$sendback = apply_filters( "handle_bulk_actions-{$screen}", $sendback, $wp_list_table->current_action(), $user_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
   512 
   591 
   513 			wp_safe_redirect( $sendback );
   592 			wp_safe_redirect( $sendback );
   514 			exit;
   593 			exit;
   515 		}
   594 		}
   516 
   595 
   517 		$wp_list_table->prepare_items();
   596 		$wp_list_table->prepare_items();
   518 		$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
   597 		$total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
       
   598 
   519 		if ( $pagenum > $total_pages && $total_pages > 0 ) {
   599 		if ( $pagenum > $total_pages && $total_pages > 0 ) {
   520 			wp_redirect( add_query_arg( 'paged', $total_pages ) );
   600 			wp_redirect( add_query_arg( 'paged', $total_pages ) );
   521 			exit;
   601 			exit;
   522 		}
   602 		}
   523 
   603 
   527 		if ( isset( $_GET['update'] ) ) :
   607 		if ( isset( $_GET['update'] ) ) :
   528 			switch ( $_GET['update'] ) {
   608 			switch ( $_GET['update'] ) {
   529 				case 'del':
   609 				case 'del':
   530 				case 'del_many':
   610 				case 'del_many':
   531 					$delete_count = isset( $_GET['delete_count'] ) ? (int) $_GET['delete_count'] : 0;
   611 					$delete_count = isset( $_GET['delete_count'] ) ? (int) $_GET['delete_count'] : 0;
   532 					if ( 1 == $delete_count ) {
   612 					if ( 1 === $delete_count ) {
   533 						$message = __( 'User deleted.' );
   613 						$message = __( 'User deleted.' );
   534 					} else {
   614 					} else {
   535 						/* translators: %s: Number of users. */
   615 						/* translators: %s: Number of users. */
   536 						$message = _n( '%s user deleted.', '%s users deleted.', $delete_count );
   616 						$message = _n( '%s user deleted.', '%s users deleted.', $delete_count );
   537 					}
   617 					}
   538 					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $delete_count ) ) . '</p></div>';
   618 					$message    = sprintf( $message, number_format_i18n( $delete_count ) );
       
   619 					$messages[] = wp_get_admin_notice(
       
   620 						$message,
       
   621 						array(
       
   622 							'id'                 => 'message',
       
   623 							'additional_classes' => array( 'updated' ),
       
   624 							'dismissible'        => true,
       
   625 						)
       
   626 					);
   539 					break;
   627 					break;
   540 				case 'add':
   628 				case 'add':
   541 					$message = __( 'New user created.' );
   629 					$message = __( 'New user created.' );
   542 
       
   543 					$user_id = isset( $_GET['id'] ) ? $_GET['id'] : false;
   630 					$user_id = isset( $_GET['id'] ) ? $_GET['id'] : false;
   544 					if ( $user_id && current_user_can( 'edit_user', $user_id ) ) {
   631 					if ( $user_id && current_user_can( 'edit_user', $user_id ) ) {
   545 						$message .= sprintf(
   632 						$message .= sprintf(
   546 							' <a href="%s">%s</a>',
   633 							' <a href="%1$s">%2$s</a>',
   547 							esc_url(
   634 							esc_url(
   548 								add_query_arg(
   635 								add_query_arg(
   549 									'wp_http_referer',
   636 									'wp_http_referer',
   550 									urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
   637 									urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ),
   551 									self_admin_url( 'user-edit.php?user_id=' . $user_id )
   638 									self_admin_url( 'user-edit.php?user_id=' . $user_id )
   553 							),
   640 							),
   554 							__( 'Edit user' )
   641 							__( 'Edit user' )
   555 						);
   642 						);
   556 					}
   643 					}
   557 
   644 
   558 					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . $message . '</p></div>';
   645 					$messages[] = wp_get_admin_notice(
       
   646 						$message,
       
   647 						array(
       
   648 							'id'                 => 'message',
       
   649 							'additional_classes' => array( 'updated' ),
       
   650 							'dismissible'        => true,
       
   651 						)
       
   652 					);
   559 					break;
   653 					break;
   560 				case 'resetpassword':
   654 				case 'resetpassword':
   561 					$reset_count = isset( $_GET['reset_count'] ) ? (int) $_GET['reset_count'] : 0;
   655 					$reset_count = isset( $_GET['reset_count'] ) ? (int) $_GET['reset_count'] : 0;
   562 					if ( 1 === $reset_count ) {
   656 					if ( 1 === $reset_count ) {
   563 						$message = __( 'Password reset link sent.' );
   657 						$message = __( 'Password reset link sent.' );
   564 					} else {
   658 					} else {
   565 						/* translators: %s: Number of users. */
   659 						/* translators: %s: Number of users. */
   566 						$message = _n( 'Password reset links sent to %s user.', 'Password reset links sent to %s users.', $reset_count );
   660 						$message = _n( 'Password reset links sent to %s user.', 'Password reset links sent to %s users.', $reset_count );
   567 					}
   661 					}
   568 					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . sprintf( $message, number_format_i18n( $reset_count ) ) . '</p></div>';
   662 					$message    = sprintf( $message, number_format_i18n( $reset_count ) );
       
   663 					$messages[] = wp_get_admin_notice(
       
   664 						$message,
       
   665 						array(
       
   666 							'id'                 => 'message',
       
   667 							'additional_classes' => array( 'updated' ),
       
   668 							'dismissible'        => true,
       
   669 						)
       
   670 					);
   569 					break;
   671 					break;
   570 				case 'promote':
   672 				case 'promote':
   571 					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Changed roles.' ) . '</p></div>';
   673 					$messages[] = wp_get_admin_notice(
       
   674 						__( 'Changed roles.' ),
       
   675 						array(
       
   676 							'id'                 => 'message',
       
   677 							'additional_classes' => array( 'updated' ),
       
   678 							'dismissible'        => true,
       
   679 						)
       
   680 					);
   572 					break;
   681 					break;
   573 				case 'err_admin_role':
   682 				case 'err_admin_role':
   574 					$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'The current user&#8217;s role must have user editing capabilities.' ) . '</p></div>';
   683 					$messages[] = wp_get_admin_notice(
   575 					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Other user roles have been changed.' ) . '</p></div>';
   684 						__( 'The current user&#8217;s role must have user editing capabilities.' ),
       
   685 						array(
       
   686 							'id'                 => 'message',
       
   687 							'additional_classes' => array( 'error' ),
       
   688 							'dismissible'        => true,
       
   689 						)
       
   690 					);
       
   691 					$messages[] = wp_get_admin_notice(
       
   692 						__( 'Other user roles have been changed.' ),
       
   693 						array(
       
   694 							'id'                 => 'message',
       
   695 							'additional_classes' => array( 'updated' ),
       
   696 							'dismissible'        => true,
       
   697 						)
       
   698 					);
   576 					break;
   699 					break;
   577 				case 'err_admin_del':
   700 				case 'err_admin_del':
   578 					$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'You cannot delete the current user.' ) . '</p></div>';
   701 					$messages[] = wp_get_admin_notice(
   579 					$messages[] = '<div id="message" class="updated notice is-dismissible"><p>' . __( 'Other users have been deleted.' ) . '</p></div>';
   702 						__( 'You cannot delete the current user.' ),
       
   703 						array(
       
   704 							'id'                 => 'message',
       
   705 							'additional_classes' => array( 'error' ),
       
   706 							'dismissible'        => true,
       
   707 						)
       
   708 					);
       
   709 					$messages[] = wp_get_admin_notice(
       
   710 						__( 'Other users have been deleted.' ),
       
   711 						array(
       
   712 							'id'                 => 'message',
       
   713 							'additional_classes' => array( 'updated' ),
       
   714 							'dismissible'        => true,
       
   715 						)
       
   716 					);
   580 					break;
   717 					break;
   581 				case 'remove':
   718 				case 'remove':
   582 					$messages[] = '<div id="message" class="updated notice is-dismissible fade"><p>' . __( 'User removed from this site.' ) . '</p></div>';
   719 					$messages[] = wp_get_admin_notice(
       
   720 						__( 'User removed from this site.' ),
       
   721 						array(
       
   722 							'id'                 => 'message',
       
   723 							'additional_classes' => array( 'updated', 'fade' ),
       
   724 							'dismissible'        => true,
       
   725 						)
       
   726 					);
   583 					break;
   727 					break;
   584 				case 'err_admin_remove':
   728 				case 'err_admin_remove':
   585 					$messages[] = '<div id="message" class="error notice is-dismissible"><p>' . __( 'You cannot remove the current user.' ) . '</p></div>';
   729 					$messages[] = wp_get_admin_notice(
   586 					$messages[] = '<div id="message" class="updated notice is-dismissible fade"><p>' . __( 'Other users have been removed.' ) . '</p></div>';
   730 						__( 'You cannot remove the current user.' ),
       
   731 						array(
       
   732 							'id'                 => 'message',
       
   733 							'additional_classes' => array( 'error' ),
       
   734 							'dismissible'        => true,
       
   735 						)
       
   736 					);
       
   737 					$messages[] = wp_get_admin_notice(
       
   738 						__( 'Other users have been removed.' ),
       
   739 						array(
       
   740 							'id'                 => 'message',
       
   741 							'additional_classes' => array( 'updated', 'fade' ),
       
   742 							'dismissible'        => true,
       
   743 						)
       
   744 					);
   587 					break;
   745 					break;
   588 			}
   746 			}
   589 		endif;
   747 		endif;
   590 		?>
   748 		?>
   591 
   749 
   592 		<?php if ( isset( $errors ) && is_wp_error( $errors ) ) : ?>
   750 		<?php
   593 		<div class="error">
   751 		if ( isset( $errors ) && is_wp_error( $errors ) ) :
   594 			<ul>
   752 			$error_message = '';
   595 			<?php
       
   596 			foreach ( $errors->get_error_messages() as $err ) {
   753 			foreach ( $errors->get_error_messages() as $err ) {
   597 				echo "<li>$err</li>\n";
   754 				$error_message .= "<li>$err</li>\n";
   598 			}
   755 			}
   599 			?>
   756 			wp_admin_notice(
   600 			</ul>
   757 				'<ul>' . $error_message . '</ul>',
   601 		</div>
   758 				array(
   602 			<?php
   759 					'additional_classes' => array( 'error' ),
   603 	endif;
   760 				)
       
   761 			);
       
   762 		endif;
   604 
   763 
   605 		if ( ! empty( $messages ) ) {
   764 		if ( ! empty( $messages ) ) {
   606 			foreach ( $messages as $msg ) {
   765 			foreach ( $messages as $msg ) {
   607 				echo $msg;
   766 				echo $msg;
   608 			}
   767 			}
   609 		}
   768 		}
   610 		?>
   769 		?>
   611 
   770 
   612 	<div class="wrap">
   771 		<div class="wrap">
   613 	<h1 class="wp-heading-inline">
   772 		<h1 class="wp-heading-inline">
   614 		<?php
   773 			<?php echo esc_html( $title ); ?>
   615 		echo esc_html( $title );
   774 		</h1>
   616 		?>
       
   617 </h1>
       
   618 
   775 
   619 		<?php
   776 		<?php
   620 		if ( current_user_can( 'create_users' ) ) {
   777 		if ( current_user_can( 'create_users' ) ) {
   621 			?>
   778 			printf(
   622 	<a href="<?php echo esc_url( admin_url( 'user-new.php' ) ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
   779 				'<a href="%1$s" class="page-title-action">%2$s</a>',
   623 <?php } elseif ( is_multisite() && current_user_can( 'promote_users' ) ) { ?>
   780 				esc_url( admin_url( 'user-new.php' ) ),
   624 	<a href="<?php echo esc_url( admin_url( 'user-new.php' ) ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add Existing', 'user' ); ?></a>
   781 				esc_html__( 'Add New User' )
   625 			<?php
   782 			);
   626 }
   783 		} elseif ( is_multisite() && current_user_can( 'promote_users' ) ) {
   627 
   784 			printf(
   628 if ( strlen( $usersearch ) ) {
   785 				'<a href="%1$s" class="page-title-action">%2$s</a>',
   629 	echo '<span class="subtitle">';
   786 				esc_url( admin_url( 'user-new.php' ) ),
   630 	printf(
   787 				esc_html__( 'Add Existing User' )
   631 		/* translators: %s: Search query. */
   788 			);
   632 		__( 'Search results for: %s' ),
   789 		}
   633 		'<strong>' . esc_html( $usersearch ) . '</strong>'
   790 
   634 	);
   791 		if ( strlen( $usersearch ) ) {
   635 	echo '</span>';
   792 			echo '<span class="subtitle">';
   636 }
   793 			printf(
   637 ?>
   794 				/* translators: %s: Search query. */
   638 
   795 				__( 'Search results for: %s' ),
   639 <hr class="wp-header-end">
   796 				'<strong>' . esc_html( $usersearch ) . '</strong>'
       
   797 			);
       
   798 			echo '</span>';
       
   799 		}
       
   800 		?>
       
   801 
       
   802 		<hr class="wp-header-end">
   640 
   803 
   641 		<?php $wp_list_table->views(); ?>
   804 		<?php $wp_list_table->views(); ?>
   642 
   805 
   643 <form method="get">
   806 		<form method="get">
   644 
   807 
   645 		<?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?>
   808 		<?php $wp_list_table->search_box( __( 'Search Users' ), 'user' ); ?>
   646 
   809 
   647 		<?php if ( ! empty( $_REQUEST['role'] ) ) { ?>
   810 		<?php if ( ! empty( $_REQUEST['role'] ) ) { ?>
   648 <input type="hidden" name="role" value="<?php echo esc_attr( $_REQUEST['role'] ); ?>" />
   811 			<input type="hidden" name="role" value="<?php echo esc_attr( $_REQUEST['role'] ); ?>" />
   649 <?php } ?>
   812 		<?php } ?>
   650 
   813 
   651 		<?php $wp_list_table->display(); ?>
   814 		<?php $wp_list_table->display(); ?>
   652 </form>
   815 
   653 
   816 		</form>
   654 <div class="clear"></div>
   817 
   655 </div>
   818 		<div class="clear"></div>
       
   819 		</div><!-- .wrap -->
   656 		<?php
   820 		<?php
   657 		break;
   821 		break;
   658 
   822 
   659 } // End of the $doaction switch.
   823 } // End of the $doaction switch.
   660 
   824