[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-admin/network/ -> users.php (source)

   1  <?php
   2  /**
   3   * Multisite users administration panel.
   4   *
   5   * @package WordPress
   6   * @subpackage Multisite
   7   * @since 3.0.0
   8   */
   9  
  10  /** Load WordPress Administration Bootstrap */
  11  require_once( dirname( __FILE__ ) . '/admin.php' );
  12  
  13  if ( ! current_user_can( 'manage_network_users' ) ) {
  14      wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  15  }
  16  
  17  if ( isset( $_GET['action'] ) ) {
  18      /** This action is documented in wp-admin/network/edit.php */
  19      do_action( 'wpmuadminedit' );
  20  
  21      switch ( $_GET['action'] ) {
  22          case 'deleteuser':
  23              if ( ! current_user_can( 'manage_network_users' ) ) {
  24                  wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  25              }
  26  
  27              check_admin_referer( 'deleteuser' );
  28  
  29              $id = intval( $_GET['id'] );
  30              if ( $id != '0' && $id != '1' ) {
  31                  $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
  32                  $title             = __( 'Users' );
  33                  $parent_file       = 'users.php';
  34                  require_once( ABSPATH . 'wp-admin/admin-header.php' );
  35                  echo '<div class="wrap">';
  36                  confirm_delete_users( $_POST['allusers'] );
  37                  echo '</div>';
  38                  require_once( ABSPATH . 'wp-admin/admin-footer.php' );
  39              } else {
  40                  wp_redirect( network_admin_url( 'users.php' ) );
  41              }
  42              exit();
  43  
  44          case 'allusers':
  45              if ( ! current_user_can( 'manage_network_users' ) ) {
  46                  wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  47              }
  48  
  49              if ( ( isset( $_POST['action'] ) || isset( $_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) {
  50                  check_admin_referer( 'bulk-users-network' );
  51  
  52                  $doaction     = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
  53                  $userfunction = '';
  54  
  55                  foreach ( (array) $_POST['allusers'] as $user_id ) {
  56                      if ( ! empty( $user_id ) ) {
  57                          switch ( $doaction ) {
  58                              case 'delete':
  59                                  if ( ! current_user_can( 'delete_users' ) ) {
  60                                      wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
  61                                  }
  62                                  $title       = __( 'Users' );
  63                                  $parent_file = 'users.php';
  64                                  require_once( ABSPATH . 'wp-admin/admin-header.php' );
  65                                  echo '<div class="wrap">';
  66                                  confirm_delete_users( $_POST['allusers'] );
  67                                  echo '</div>';
  68                                  require_once( ABSPATH . 'wp-admin/admin-footer.php' );
  69                                  exit();
  70  
  71                              case 'spam':
  72                                  $user = get_userdata( $user_id );
  73                                  if ( is_super_admin( $user->ID ) ) {
  74                                      wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
  75                                  }
  76  
  77                                  $userfunction = 'all_spam';
  78                                  $blogs        = get_blogs_of_user( $user_id, true );
  79                                  foreach ( (array) $blogs as $details ) {
  80                                      if ( $details->userblog_id != get_network()->site_id ) { // main blog not a spam !
  81                                          update_blog_status( $details->userblog_id, 'spam', '1' );
  82                                      }
  83                                  }
  84                                  update_user_status( $user_id, 'spam', '1' );
  85                                  break;
  86  
  87                              case 'notspam':
  88                                  $userfunction = 'all_notspam';
  89                                  $blogs        = get_blogs_of_user( $user_id, true );
  90                                  foreach ( (array) $blogs as $details ) {
  91                                      update_blog_status( $details->userblog_id, 'spam', '0' );
  92                                  }
  93  
  94                                  update_user_status( $user_id, 'spam', '0' );
  95                                  break;
  96                          }
  97                      }
  98                  }
  99  
 100                  if ( ! in_array( $doaction, array( 'delete', 'spam', 'notspam' ), true ) ) {
 101                      $sendback = wp_get_referer();
 102  
 103                      $user_ids = (array) $_POST['allusers'];
 104                      /** This action is documented in wp-admin/network/site-themes.php */
 105                      $sendback = apply_filters( 'handle_network_bulk_actions-' . get_current_screen()->id, $sendback, $doaction, $user_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
 106  
 107                      wp_safe_redirect( $sendback );
 108                      exit();
 109                  }
 110  
 111                  wp_safe_redirect(
 112                      add_query_arg(
 113                          array(
 114                              'updated' => 'true',
 115                              'action'  => $userfunction,
 116                          ),
 117                          wp_get_referer()
 118                      )
 119                  );
 120              } else {
 121                  $location = network_admin_url( 'users.php' );
 122  
 123                  if ( ! empty( $_REQUEST['paged'] ) ) {
 124                      $location = add_query_arg( 'paged', (int) $_REQUEST['paged'], $location );
 125                  }
 126                  wp_redirect( $location );
 127              }
 128              exit();
 129  
 130          case 'dodelete':
 131              check_admin_referer( 'ms-users-delete' );
 132              if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) ) {
 133                  wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
 134              }
 135  
 136              if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
 137                  foreach ( $_POST['blog'] as $id => $users ) {
 138                      foreach ( $users as $blogid => $user_id ) {
 139                          if ( ! current_user_can( 'delete_user', $id ) ) {
 140                              continue;
 141                          }
 142  
 143                          if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][ $blogid ][ $id ] ) {
 144                              remove_user_from_blog( $id, $blogid, $user_id );
 145                          } else {
 146                              remove_user_from_blog( $id, $blogid );
 147                          }
 148                      }
 149                  }
 150              }
 151              $i = 0;
 152              if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) ) {
 153                  foreach ( $_POST['user'] as $id ) {
 154                      if ( ! current_user_can( 'delete_user', $id ) ) {
 155                          continue;
 156                      }
 157                      wpmu_delete_user( $id );
 158                      $i++;
 159                  }
 160              }
 161  
 162              if ( $i == 1 ) {
 163                  $deletefunction = 'delete';
 164              } else {
 165                  $deletefunction = 'all_delete';
 166              }
 167  
 168              wp_redirect(
 169                  add_query_arg(
 170                      array(
 171                          'updated' => 'true',
 172                          'action'  => $deletefunction,
 173                      ),
 174                      network_admin_url( 'users.php' )
 175                  )
 176              );
 177              exit();
 178      }
 179  }
 180  
 181  $wp_list_table = _get_list_table( 'WP_MS_Users_List_Table' );
 182  $pagenum       = $wp_list_table->get_pagenum();
 183  $wp_list_table->prepare_items();
 184  $total_pages = $wp_list_table->get_pagination_arg( 'total_pages' );
 185  
 186  if ( $pagenum > $total_pages && $total_pages > 0 ) {
 187      wp_redirect( add_query_arg( 'paged', $total_pages ) );
 188      exit;
 189  }
 190  $title       = __( 'Users' );
 191  $parent_file = 'users.php';
 192  
 193  add_screen_option( 'per_page' );
 194  
 195  get_current_screen()->add_help_tab(
 196      array(
 197          'id'      => 'overview',
 198          'title'   => __( 'Overview' ),
 199          'content' =>
 200              '<p>' . __( 'This table shows all users across the network and the sites to which they are assigned.' ) . '</p>' .
 201              '<p>' . __( 'Hover over any user on the list to make the edit links appear. The Edit link on the left will take you to their Edit User profile page; the Edit link on the right by any site name goes to an Edit Site screen for that site.' ) . '</p>' .
 202              '<p>' . __( 'You can also go to the user&#8217;s profile page by clicking on the individual username.' ) . '</p>' .
 203              '<p>' . __( 'You can sort the table by clicking on any of the table headings and switch between list and excerpt views by using the icons above the users list.' ) . '</p>' .
 204              '<p>' . __( 'The bulk action will permanently delete selected users, or mark/unmark those selected as spam. Spam users will have posts removed and will be unable to sign up again with the same email addresses.' ) . '</p>' .
 205              '<p>' . __( 'You can make an existing user an additional super admin by going to the Edit User profile page and checking the box to grant that privilege.' ) . '</p>',
 206      )
 207  );
 208  
 209  get_current_screen()->set_help_sidebar(
 210      '<p><strong>' . __( 'For more information:' ) . '</strong></p>' .
 211      '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>' ) . '</p>' .
 212      '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>'
 213  );
 214  
 215  get_current_screen()->set_screen_reader_content(
 216      array(
 217          'heading_views'      => __( 'Filter users list' ),
 218          'heading_pagination' => __( 'Users list navigation' ),
 219          'heading_list'       => __( 'Users list' ),
 220      )
 221  );
 222  
 223  require_once( ABSPATH . 'wp-admin/admin-header.php' );
 224  
 225  if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( $_REQUEST['action'] ) ) {
 226      ?>
 227      <div id="message" class="updated notice is-dismissible"><p>
 228          <?php
 229          switch ( $_REQUEST['action'] ) {
 230              case 'delete':
 231                  _e( 'User deleted.' );
 232                  break;
 233              case 'all_spam':
 234                  _e( 'Users marked as spam.' );
 235                  break;
 236              case 'all_notspam':
 237                  _e( 'Users removed from spam.' );
 238                  break;
 239              case 'all_delete':
 240                  _e( 'Users deleted.' );
 241                  break;
 242              case 'add':
 243                  _e( 'User added.' );
 244                  break;
 245          }
 246          ?>
 247      </p></div>
 248      <?php
 249  }
 250  ?>
 251  <div class="wrap">
 252      <h1 class="wp-heading-inline"><?php esc_html_e( 'Users' ); ?></h1>
 253  
 254      <?php
 255      if ( current_user_can( 'create_users' ) ) :
 256          ?>
 257          <a href="<?php echo network_admin_url( 'user-new.php' ); ?>" class="page-title-action"><?php echo esc_html_x( 'Add New', 'user' ); ?></a>
 258                              <?php
 259      endif;
 260  
 261      if ( strlen( $usersearch ) ) {
 262          /* translators: %s: search keywords */
 263          printf( '<span class="subtitle">' . __( 'Search results for &#8220;%s&#8221;' ) . '</span>', esc_html( $usersearch ) );
 264      }
 265      ?>
 266  
 267      <hr class="wp-header-end">
 268  
 269      <?php $wp_list_table->views(); ?>
 270  
 271      <form method="get" class="search-form">
 272          <?php $wp_list_table->search_box( __( 'Search Users' ), 'all-user' ); ?>
 273      </form>
 274  
 275      <form id="form-user-list" action="users.php?action=allusers" method="post">
 276          <?php $wp_list_table->display(); ?>
 277      </form>
 278  </div>
 279  
 280  <?php require_once( ABSPATH . 'wp-admin/admin-footer.php' ); ?>


Generated: Mon Jul 22 01:00:03 2019 Cross-referenced by PHPXref 0.7.1