confirm_delete_users

The WordPress Core confirm delete users function.

Description

confirm_delete_users( (array) $users ); 

Parameters (1)

0. $users (array)
The users.

Usage

  1. if ( !function_exists( 'confirm_delete_users' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ms.php'; 
  3.  
  4. // The users. 
  5. $users = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = confirm_delete_users($users); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ms.php  
  1. function confirm_delete_users( $users ) { 
  2. $current_user = wp_get_current_user(); 
  3. if ( ! is_array( $users ) || empty( $users ) ) { 
  4. return false; 
  5. ?> 
  6. <h1><?php esc_html_e( 'Users' ); ?></h1> 
  7.  
  8. <?php if ( 1 == count( $users ) ) : ?> 
  9. <p><?php _e( 'You have chosen to delete the user from all networks and sites.' ); ?></p> 
  10. <?php else : ?> 
  11. <p><?php _e( 'You have chosen to delete the following users from all networks and sites.' ); ?></p> 
  12. <?php endif; ?> 
  13.  
  14. <form action="users.php?action=dodelete" method="post"> 
  15. <input type="hidden" name="dodelete" /> 
  16. <?php 
  17. wp_nonce_field( 'ms-users-delete' ); 
  18. $site_admins = get_super_admins(); 
  19. $admin_out = '<option value="' . esc_attr( $current_user->ID ) . '">' . $current_user->user_login . '</option>'; ?> 
  20. <table class="form-table"> 
  21. <?php foreach ( ( $allusers = (array) $_POST['allusers'] ) as $user_id ) { 
  22. if ( $user_id != '' && $user_id != '0' ) { 
  23. $delete_user = get_userdata( $user_id ); 
  24.  
  25. if ( ! current_user_can( 'delete_user', $delete_user->ID ) ) { 
  26. wp_die( sprintf( __( 'Warning! User %s cannot be deleted.' ), $delete_user->user_login ) ); 
  27.  
  28. if ( in_array( $delete_user->user_login, $site_admins ) ) { 
  29. wp_die( sprintf( __( 'Warning! User cannot be deleted. The user %s is a network administrator.' ), '<em>' . $delete_user->user_login . '</em>' ) ); 
  30. ?> 
  31. <tr> 
  32. <th scope="row"><?php echo $delete_user->user_login; ?> 
  33. <?php echo '<input type="hidden" name="user[]" value="' . esc_attr( $user_id ) . '" />' . "\n"; ?> 
  34. </th> 
  35. <?php $blogs = get_blogs_of_user( $user_id, true ); 
  36.  
  37. if ( ! empty( $blogs ) ) { 
  38. ?> 
  39. <td><fieldset><p><legend><?php printf( 
  40. /** translators: user login */ 
  41. __( 'What should be done with content owned by %s?' ),  
  42. '<em>' . $delete_user->user_login . '</em>' 
  43. ); ?></legend></p> 
  44. <?php 
  45. foreach ( (array) $blogs as $key => $details ) { 
  46. $blog_users = get_users( array( 'blog_id' => $details->userblog_id, 'fields' => array( 'ID', 'user_login' ) ) ); 
  47. if ( is_array( $blog_users ) && !empty( $blog_users ) ) { 
  48. $user_site = "<a href='" . esc_url( get_home_url( $details->userblog_id ) ) . "'>{$details->blogname}</a>"; 
  49. $user_dropdown = '<label for="reassign_user" class="screen-reader-text">' . __( 'Select a user' ) . '</label>'; 
  50. $user_dropdown .= "<select name='blog[$user_id][$key]' id='reassign_user'>"; 
  51. $user_list = ''; 
  52. foreach ( $blog_users as $user ) { 
  53. if ( ! in_array( $user->ID, $allusers ) ) { 
  54. $user_list .= "<option value='{$user->ID}'>{$user->user_login}</option>"; 
  55. if ( '' == $user_list ) { 
  56. $user_list = $admin_out; 
  57. $user_dropdown .= $user_list; 
  58. $user_dropdown .= "</select>\n"; 
  59. ?> 
  60. <ul style="list-style:none;"> 
  61. <li><?php printf( __( 'Site: %s' ), $user_site ); ?></li> 
  62. <li><label><input type="radio" id="delete_option0" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="delete" checked="checked" /> 
  63. <?php _e( 'Delete all content.' ); ?></label></li> 
  64. <li><label><input type="radio" id="delete_option1" name="delete[<?php echo $details->userblog_id . '][' . $delete_user->ID ?>]" value="reassign" /> 
  65. <?php _e( 'Attribute all content to:' ); ?></label> 
  66. <?php echo $user_dropdown; ?></li> 
  67. </ul> 
  68. <?php 
  69. echo "</fieldset></td></tr>"; 
  70. } else { 
  71. ?> 
  72. <td><fieldset><p><legend><?php _e( 'User has no sites or content and will be deleted.' ); ?></legend></p> 
  73. <?php } ?> 
  74. </tr> 
  75. <?php 
  76.  
  77. ?> 
  78. </table> 
  79. <?php 
  80. /** This action is documented in wp-admin/users.php */ 
  81. do_action( 'delete_user_form', $current_user, $allusers ); 
  82.  
  83. if ( 1 == count( $users ) ) : ?> 
  84. <p><?php _e( 'Once you hit “Confirm Deletion”, the user will be permanently removed.' ); ?></p> 
  85. <?php else : ?> 
  86. <p><?php _e( 'Once you hit “Confirm Deletion”, these users will be permanently removed.' ); ?></p> 
  87. <?php endif; 
  88.  
  89. submit_button( __('Confirm Deletion'), 'primary' ); 
  90. ?> 
  91. </form> 
  92. <?php 
  93. return true;