[ Index ]

PHP Cross Reference of WordPress 3.0 beta 1

[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/wp-admin/ -> ms-edit.php (source)

   1  <?php
   2  require_once ( './admin.php' );
   3  
   4  if ( !is_multisite() )
   5      wp_die( __( 'Multisite support is not enabled.' ) );
   6  
   7  do_action( 'wpmuadminedit' , '');
   8  
   9  if ( isset( $_GET['id' ]) )
  10      $id = intval( $_GET['id'] );
  11  elseif ( isset( $_POST['id'] ) )
  12      $id = intval( $_POST['id'] );
  13  
  14  switch ( $_GET['action'] ) {
  15      case 'siteoptions':
  16          check_admin_referer( 'siteoptions' );
  17          if ( ! current_user_can( 'manage_network_options' ) )
  18              wp_die( __( 'You do not have permission to access this page.' ) );
  19  
  20          if ( empty( $_POST ) )
  21              wp_die( sprintf( __( 'You probably need to go back to the <a href="%s">options page</a>.', esc_url( admin_url( 'ms-options.php' ) ) ) ) );
  22  
  23          if ( isset($_POST['WPLANG']) && ( '' === $_POST['WPLANG'] || in_array( $_POST['WPLANG'], get_available_languages() ) ) )
  24              update_site_option( 'WPLANG', $_POST['WPLANG'] );
  25  
  26          if ( is_email( $_POST['admin_email'] ) )
  27              update_site_option( 'admin_email', $_POST['admin_email'] );
  28  
  29          $illegal_names = split( ' ', $_POST['illegal_names'] );
  30          foreach ( (array) $illegal_names as $name ) {
  31              $name = trim( $name );
  32              if ( $name != '' )
  33                  $names[] = trim( $name );
  34          }
  35          update_site_option( 'illegal_names', $names );
  36  
  37          if ( $_POST['limited_email_domains'] != '' ) {
  38              $limited_email_domains = str_replace( ' ', "\n", $_POST['limited_email_domains'] );
  39              $limited_email_domains = split( "\n", stripslashes( $limited_email_domains ) );
  40              $limited_email = array();
  41              foreach ( (array) $limited_email_domains as $domain ) {
  42                      $domain = trim( $domain );
  43                  if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
  44                      $limited_email[] = trim( $domain );
  45              }
  46              update_site_option( 'limited_email_domains', $limited_email );
  47          } else {
  48              update_site_option( 'limited_email_domains', '' );
  49          }
  50  
  51          if ( $_POST['banned_email_domains'] != '' ) {
  52              $banned_email_domains = split( "\n", stripslashes( $_POST['banned_email_domains'] ) );
  53              $banned = array();
  54              foreach ( (array) $banned_email_domains as $domain ) {
  55                  $domain = trim( $domain );
  56                  if ( ! preg_match( '/(--|\.\.)/', $domain ) && preg_match( '|^([a-zA-Z0-9-\.])+$|', $domain ) )
  57                      $banned[] = trim( $domain );
  58              }
  59              update_site_option( 'banned_email_domains', $banned );
  60          } else {
  61              update_site_option( 'banned_email_domains', '' );
  62          }
  63          update_site_option( 'default_user_role', $_POST['default_user_role'] );
  64          if ( trim( $_POST['dashboard_blog_orig'] ) == '' )
  65              $_POST['dashboard_blog_orig'] = $current_site->blog_id;
  66          if ( trim( $_POST['dashboard_blog'] ) == '' ) {
  67              $_POST['dashboard_blog'] = $current_site->blog_id;
  68              $dashboard_blog_id = $current_site->blog_id;
  69          } else {
  70              $dashboard_blog = untrailingslashit( sanitize_user( str_replace( '.', '', str_replace( $current_site->domain . $current_site->path, '', $_POST['dashboard_blog'] ) ) ) );
  71              $blog_details = get_blog_details( $dashboard_blog );
  72              if ( false === $blog_details ) {
  73                  if ( is_numeric( $dashboard_blog ) )
  74                      wp_die( __( 'Dashboard blog_id must be a blog that already exists' ) );
  75                  if ( is_subdomain_install() ) {
  76                      $domain = $dashboard_blog . '.' . $current_site->domain;
  77                      $path = $current_site->path;
  78                  } else {
  79                      $domain = $current_site->domain;
  80                      $path = trailingslashit( $current_site->path . $dashboard_blog );
  81                  }
  82                  $wpdb->hide_errors();
  83                  $dashboard_blog_id = wpmu_create_blog( $domain, $path, __( 'My Dashboard' ), $current_user->id , array( 'public' => 0 ), $current_site->id );
  84                  $wpdb->show_errors();
  85              } else {
  86                  $dashboard_blog_id = $blog_details->blog_id;
  87              }
  88          }
  89          if ( is_wp_error( $dashboard_blog_id ) )
  90              wp_die( __( 'Problem creating dashboard blog: ' ) . $dashboard_blog_id->get_error_message() );
  91          if ( $_POST['dashboard_blog_orig'] != $_POST['dashboard_blog'] ) {
  92              $users = get_users_of_blog( get_site_option( 'dashboard_blog' ) );
  93              $move_users = array();
  94              foreach ( (array)$users as $user ) {
  95                  if ( array_pop( array_keys( unserialize( $user->meta_value ) ) ) == 'subscriber' )
  96                      $move_users[] = $user->user_id;
  97              }
  98              if ( false == empty( $move_users ) ) {
  99                  foreach ( (array)$move_users as $user_id ) {
 100                      remove_user_from_blog($user_id, get_site_option( 'dashboard_blog' ) );
 101                      add_user_to_blog( $dashboard_blog_id, $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
 102                      update_user_meta( $user_id, 'primary_blog', $dashboard_blog_id );
 103                  }
 104              }
 105          }
 106          update_site_option( 'dashboard_blog', $dashboard_blog_id );
 107          // global terms
 108          if ( !global_terms_enabled() && ! empty( $_POST['global_terms_enabled'] ) ) {
 109              require_once ( ABSPATH . 'wp-admin/includes/upgrade.php' );
 110              // create global terms table
 111              install_global_terms();
 112          }
 113          $options = array( 'registrationnotification', 'registration', 'add_new_users', 'menu_items', 'mu_media_buttons', 'upload_space_check_disabled', 'blog_upload_space', 'upload_filetypes', 'site_name', 'first_post', 'first_page', 'first_comment', 'first_comment_url', 'first_comment_author', 'welcome_email', 'welcome_user_email', 'fileupload_maxk', 'admin_notice_feed', 'global_terms_enabled' );
 114          $checked_options = array( 'mu_media_buttons' => array(), 'menu_items' => array(), 'registrationnotification' => 'no', 'upload_space_check_disabled' => 1 );
 115          foreach ( $checked_options as $option_name => $option_unchecked_value ) {
 116              if ( ! isset( $_POST[$option_name] ) )
 117                  $_POST[$option_name] = $option_unchecked_value;
 118          }
 119          foreach ( $options as $option_name ) {
 120              if ( ! isset($_POST[$option_name]) )
 121                  continue;
 122              $value = stripslashes_deep( $_POST[$option_name] );
 123              update_site_option( $option_name, $value );
 124          }
 125  
 126          // Update more options here
 127          do_action( 'update_wpmu_options' );
 128  
 129          wp_redirect( add_query_arg( 'updated', 'true', admin_url( 'ms-options.php' ) ) );
 130          exit();
 131      break;
 132      case 'addblog':
 133          check_admin_referer( 'add-blog' );
 134  
 135          if ( ! current_user_can( 'manage_sites' ) )
 136              wp_die( __( 'You do not have permission to access this page.' ) );
 137  
 138          if ( is_array( $_POST['blog'] ) == false )
 139              wp_die(  __( "Can't create an empty site." ) );
 140          $blog = $_POST['blog'];
 141          $domain = '';
 142          if ( ! preg_match( '/(--)/', $blog['domain'] ) && preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
 143              $domain = strtolower( $blog['domain'] );
 144          $email = sanitize_email( $blog['email'] );
 145          $title = $blog['title'];
 146  
 147          if ( empty( $domain ) )
 148              wp_die( __( 'Missing or invalid site address.' ) );
 149          if ( empty( $email ) )
 150              wp_die( __( 'Missing email address.' ) );
 151          if ( !is_email( $email ) )
 152              wp_die( __( 'Invalid email address.' ) );
 153  
 154          if ( is_subdomain_install() ) {
 155              $newdomain = $domain . '.' . $current_site->domain;
 156              $path = $base;
 157          } else {
 158              $newdomain = $current_site->domain;
 159              $path = $base . $domain . '/';
 160          }
 161  
 162          $password = 'N/A';
 163          $user_id = email_exists($email);
 164          if ( !$user_id ) { // Create a new user with a random password
 165              $password = wp_generate_password();
 166              $user_id = wpmu_create_user( $domain, $password, $email );
 167              if ( false == $user_id )
 168                  wp_die( __( 'There was an error creating the user.' ) );
 169              else
 170                  wp_new_user_notification( $user_id, $password );
 171          }
 172  
 173          $wpdb->hide_errors();
 174          $id = wpmu_create_blog( $newdomain, $path, $title, $user_id , array( 'public' => 1 ), $current_site->id );
 175          $wpdb->show_errors();
 176          if ( !is_wp_error( $id ) ) {
 177              $dashboard_blog = get_dashboard_blog();
 178              if ( get_user_option( 'primary_blog', $user_id ) == $dashboard_blog->blog_id )
 179                  update_user_option( $user_id, 'primary_blog', $id, true );
 180              $content_mail = sprintf( __( "New site created by %1s\n\nAddress: http://%2s\nName: %3s"), $current_user->user_login , $newdomain . $path, stripslashes( $title ) );
 181              wp_mail( get_site_option('admin_email'),  sprintf( __( '[%s] New Site Created' ), $current_site->site_name ), $content_mail, 'From: "Site Admin" <' . get_site_option( 'admin_email' ) . '>' );
 182              wpmu_welcome_notification( $id, $user_id, $password, $title, array( 'public' => 1 ) );
 183              wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'add-blog' ), wp_get_referer() ) );
 184              exit();
 185          } else {
 186              wp_die( $id->get_error_message() );
 187          }
 188      break;
 189  
 190      case 'updateblog':
 191          check_admin_referer( 'editblog' );
 192          if ( ! current_user_can( 'manage_sites' ) )
 193              wp_die( __( 'You do not have permission to access this page.' ) );
 194  
 195          if ( empty( $_POST ) )
 196              wp_die( sprintf( __( 'You probably need to go back to the <a href="%s">sites page</a>', esc_url( admin_url( 'ms-sites.php' ) ) ) ) );
 197  
 198          switch_to_blog( $id );
 199  
 200          // themes
 201          $allowedthemes = array();
 202          if ( isset($_POST['theme']) && is_array( $_POST['theme'] ) ) {
 203              foreach ( $_POST['theme'] as $theme => $val ) {
 204                  if ( 'on' == $val )
 205                      $allowedthemes[$theme] = true;
 206              }
 207          }
 208          update_option( 'allowedthemes',  $allowedthemes );
 209  
 210          // options
 211          if ( is_array( $_POST['option'] ) ) {
 212              $c = 1;
 213              $count = count( $_POST['option'] );
 214              foreach ( (array) $_POST['option'] as $key => $val ) {
 215                  if ( $key === 0 || is_array( $val ) )
 216                      continue; // Avoids "0 is a protected WP option and may not be modified" error when edit blog options
 217                  if ( $c == $count )
 218                      update_option( $key, stripslashes( $val ) );
 219                  else
 220                      update_option( $key, stripslashes( $val ), false ); // no need to refresh blog details yet
 221                  $c++;
 222              }
 223          }
 224  
 225          // home and siteurl
 226          if ( isset( $_POST['update_home_url'] ) && $_POST['update_home_url'] == 'update' ) {
 227              $blog_address = get_blogaddress_by_domain( $_POST['blog']['domain'], $_POST['blog']['path'] );
 228              if ( get_option( 'siteurl' ) !=  $blog_address )
 229                  update_option( 'siteurl', $blog_address );
 230  
 231              if ( get_option( 'home' ) != $blog_address )
 232                  update_option( 'home', $blog_address );
 233          }
 234  
 235          // rewrite rules can't be flushed during switch to blog
 236          delete_option( 'rewrite_rules' );
 237  
 238          // update blogs table
 239          $blog_data = stripslashes_deep( $_POST['blog'] );
 240          update_blog_details( $id, $blog_data );
 241  
 242          // get blog prefix
 243          $blog_prefix = $wpdb->get_blog_prefix( $id );
 244  
 245          // user roles
 246          if ( isset( $_POST['role'] ) && is_array( $_POST['role'] ) == true ) {
 247              $newroles = $_POST['role'];
 248  
 249              reset( $newroles );
 250              foreach ( (array) $newroles as $userid => $role ) {
 251                  $user = new WP_User( $userid );
 252                  if ( ! $user )
 253                      continue;
 254                  $user->for_blog( $id );
 255                  $user->set_role( $role );
 256              }
 257          }
 258  
 259          // remove user
 260          if ( isset( $_POST['blogusers'] ) && is_array( $_POST['blogusers'] ) ) {
 261              reset( $_POST['blogusers'] );
 262              foreach ( (array) $_POST['blogusers'] as $key => $val )
 263                  remove_user_from_blog( $key, $id );
 264          }
 265  
 266          // change password
 267          if ( isset( $_POST['user_password'] ) && is_array( $_POST['user_password'] ) ) {
 268              reset( $_POST['user_password'] );
 269              $newroles = $_POST['role'];
 270              foreach ( (array) $_POST['user_password'] as $userid => $pass ) {
 271                  unset( $_POST['role'] );
 272                  $_POST['role'] = $newroles[ $userid ];
 273                  if ( $pass != '' ) {
 274                      $cap = $wpdb->get_var( "SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = '{$userid}' AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'" );
 275                      $userdata = get_userdata($userid);
 276                      $_POST['pass1'] = $_POST['pass2'] = $pass;
 277                      $_POST['email'] = $userdata->user_email;
 278                      $_POST['rich_editing'] = $userdata->rich_editing;
 279                      edit_user( $userid );
 280                      if ( $cap == null )
 281                          $wpdb->query( "DELETE FROM {$wpdb->usermeta} WHERE user_id = '{$userid}' AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'" );
 282                  }
 283              }
 284              unset( $_POST['role'] );
 285              $_POST['role'] = $newroles;
 286          }
 287  
 288          // add user
 289          if ( !empty( $_POST['newuser'] ) ) {
 290              $newuser = $_POST['newuser'];
 291              $userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) );
 292              if ( $userid ) {
 293                  $user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='{$blog_prefix}capabilities'" );
 294                  if ( $user == false )
 295                      add_user_to_blog( $id, $userid, $_POST['new_role'] );
 296              }
 297          }
 298          do_action( 'wpmu_update_blog_options' );
 299          restore_current_blog();
 300          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'editblog', 'id' => $id ), wp_get_referer() ) );
 301      break;
 302  
 303      case 'deleteblog':
 304          check_admin_referer('deleteblog');
 305          if ( ! current_user_can( 'manage_sites' ) )
 306              wp_die( __( 'You do not have permission to access this page.' ) );
 307  
 308          if ( $id != '0' && $id != $current_site->blog_id )
 309              wpmu_delete_blog( $id, true );
 310  
 311          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'delete' ), wp_get_referer() ) );
 312          exit();
 313      break;
 314  
 315      case 'allblogs':
 316          if ( isset( $_POST['doaction']) || isset($_POST['doaction2'] ) ) {
 317              check_admin_referer( 'bulk-ms-sites' );
 318  
 319              if ( ! current_user_can( 'manage_sites' ) )
 320                  wp_die( __( 'You do not have permission to access this page.' ) );
 321      
 322              if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
 323                  $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
 324  
 325  
 326              foreach ( (array) $_POST['allblogs'] as $key => $val ) {
 327                  if ( $val != '0' && $val != $current_site->blog_id ) {
 328                      switch ( $doaction ) {
 329                          case 'delete':
 330                              $blogfunction = 'all_delete';
 331                              wpmu_delete_blog( $val, true );
 332                          break;
 333  
 334                          case 'spam':
 335                              $blogfunction = 'all_spam';
 336                              update_blog_status( $val, 'spam', '1', 0 );
 337                              set_time_limit( 60 );
 338                          break;
 339  
 340                          case 'notspam':
 341                              $blogfunction = 'all_notspam';
 342                              update_blog_status( $val, 'spam', '0', 0 );
 343                              set_time_limit( 60 );
 344                          break;
 345                      }
 346                  } else {
 347                      wp_die( __( 'You are not allowed to change the current site.' ) );
 348                  }
 349              }
 350  
 351              wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $blogfunction ), wp_get_referer() ) );
 352              exit();
 353          } else {
 354              wp_redirect( admin_url( 'ms-sites.php' ) );
 355          }
 356      break;
 357  
 358      case 'archiveblog':
 359          check_admin_referer( 'archiveblog' );
 360          if ( ! current_user_can( 'manage_sites' ) )
 361              wp_die( __( 'You do not have permission to access this page.' ) );
 362  
 363          update_blog_status( $id, 'archived', '1' );
 364          do_action( 'archive_blog', $id );
 365          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'archive' ), wp_get_referer() ) );
 366          exit();
 367      break;
 368  
 369      case 'unarchiveblog':
 370          check_admin_referer( 'unarchiveblog' );
 371          if ( ! current_user_can( 'manage_sites' ) )
 372              wp_die( __( 'You do not have permission to access this page.' ) );
 373  
 374          do_action( 'unarchive_blog', $id );
 375          update_blog_status( $id, 'archived', '0' );
 376          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unarchive' ), wp_get_referer() ) );
 377          exit();
 378      break;
 379  
 380      case 'activateblog':
 381          check_admin_referer( 'activateblog' );
 382          if ( ! current_user_can( 'manage_sites' ) )
 383              wp_die( __( 'You do not have permission to access this page.' ) );
 384  
 385          update_blog_status( $id, 'deleted', '0' );
 386          do_action( 'activate_blog', $id );
 387          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'activate' ), wp_get_referer() ) );
 388          exit();
 389      break;
 390  
 391      case 'deactivateblog':
 392          check_admin_referer( 'deactivateblog' );
 393          if ( ! current_user_can( 'manage_sites' ) )
 394              wp_die( __( 'You do not have permission to access this page.' ) );
 395  
 396          do_action( 'deactivate_blog', $id );
 397          update_blog_status( $id, 'deleted', '1' );
 398          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'deactivate' ), wp_get_referer() ) );
 399          exit();
 400      break;
 401  
 402      case 'unspamblog':
 403          check_admin_referer( 'unspamblog' );
 404          if ( ! current_user_can( 'manage_sites' ) )
 405              wp_die( __( 'You do not have permission to access this page.' ) );
 406  
 407          update_blog_status( $id, 'spam', '0' );
 408          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unspam' ), wp_get_referer() ) );
 409          exit();
 410      break;
 411  
 412      case 'spamblog':
 413          check_admin_referer( 'spamblog' );
 414          if ( ! current_user_can( 'manage_sites' ) )
 415              wp_die( __( 'You do not have permission to access this page.' ) );
 416  
 417          update_blog_status( $id, 'spam', '1' );
 418          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'spam' ), wp_get_referer() ) );
 419          exit();
 420      break;
 421  
 422      case 'matureblog':
 423          check_admin_referer( 'matureblog' );
 424          if ( ! current_user_can( 'manage_sites' ) )
 425              wp_die( __( 'You do not have permission to access this page.' ) );
 426  
 427          update_blog_status( $id, 'mature', '1' );
 428          do_action( 'mature_blog', $id );
 429          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'mature' ), wp_get_referer() ) );
 430          exit();
 431      break;
 432  
 433      case 'unmatureblog':
 434          check_admin_referer( 'unmatureblog' );
 435          if ( ! current_user_can( 'manage_sites' ) )
 436              wp_die( __( 'You do not have permission to access this page.' ) );
 437  
 438          update_blog_status( $id, 'mature', '0' );
 439          do_action( 'unmature_blog', $id );
 440          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unmature' ), wp_get_referer() ) );
 441          exit();
 442      break;
 443  
 444      // Themes
 445      case 'updatethemes':
 446      if ( ! current_user_can( 'manage_network_themes' ) )
 447          wp_die( __( 'You do not have permission to access this page.' ) );
 448  
 449          if ( is_array( $_POST['theme'] ) ) {
 450              $themes = get_themes();
 451              reset( $themes );
 452              foreach ( (array) $themes as $key => $theme ) {
 453                  if ( $_POST['theme'][ esc_html( $theme['Stylesheet'] ) ] == 'enabled' )
 454                      $allowed_themes[ esc_html( $theme['Stylesheet'] ) ] = true;
 455              }
 456              update_site_option( 'allowedthemes', $allowed_themes );
 457          }
 458          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'themes' ),  wp_get_referer() ) );
 459          exit();
 460      break;
 461  
 462      // Common
 463      case 'confirm':
 464          if ( !headers_sent() ) {
 465              nocache_headers();
 466              header( 'Content-Type: text/html; charset=utf-8' );
 467          }
 468          if ( $current_site->blog_id == $id )    
 469              wp_die( __( 'You are not allowed to change the current site.' ) );
 470          ?>
 471          <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 472          <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
 473              <head>
 474                  <title><?php _e( 'WordPress &rsaquo; Confirm your action' ); ?></title>
 475  
 476                  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 477                  <?php wp_admin_css( 'install', true ); ?>
 478              </head>
 479              <body id="error-page">
 480                  <h1 id="logo"><img alt="WordPress" src="<?php echo esc_attr( admin_url( 'images/wordpress-logo.png' ) ); ?>" /></h1>
 481                  <form action="ms-edit.php?action=<?php echo esc_attr( $_GET['action2'] ) ?>" method="post">
 482                      <input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" />
 483                      <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
 484                      <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
 485                      <?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?>
 486                      <p><?php esc_html_e( stripslashes( $_GET['msg'] ) ); ?></p>
 487                      <p class="submit"><input class="button" type="submit" value="<?php _e( 'Confirm' ); ?>" /></p>
 488                  </form>
 489              </body>
 490          </html>
 491          <?php
 492      break;
 493  
 494      // Users
 495      case 'deleteuser':
 496          if ( ! current_user_can( 'manage_network_users' ) )
 497              wp_die( __( 'You do not have permission to access this page.' ) );
 498  
 499          check_admin_referer( 'deleteuser' );
 500  
 501          if ( $id != '0' && $id != '1' ) {
 502              $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
 503              $title = __( 'Users' ); 
 504              $parent_file = 'ms-admin.php'; 
 505              require_once ( 'admin-header.php' );
 506              echo '<div class="wrap">';
 507              confirm_delete_users( $_POST['allusers'] );
 508              echo '</div>';
 509              require_once ( 'admin-footer.php' );
 510              exit();
 511          } else {
 512              wp_redirect( admin_url( 'ms-users.php' ) );    
 513          }
 514      break;
 515  
 516      case 'allusers':
 517          if ( ! current_user_can( 'manage_network_users' ) )
 518              wp_die( __( 'You do not have permission to access this page.' ) );
 519  
 520          if ( isset( $_POST['doaction']) || isset($_POST['doaction2'] ) ) {
 521              check_admin_referer( 'bulk-ms-users' );
 522  
 523              if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
 524                  $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
 525  
 526              foreach ( (array) $_POST['allusers'] as $key => $val ) {
 527                  if ( !empty( $val ) ) {
 528                      switch ( $doaction ) {
 529                          case 'delete':
 530                              $title = __( 'Users' ); 
 531                              $parent_file = 'ms-admin.php'; 
 532                              require_once ( 'admin-header.php' );
 533                              echo '<div class="wrap">';
 534                              confirm_delete_users( $_POST['allusers'] );
 535                              echo '</div>';
 536                              require_once ( 'admin-footer.php' );
 537                              exit();
 538                             break;
 539  
 540                          case 'superadmin':
 541                              $userfunction = 'add_superadmin';
 542                              grant_super_admin( $val );
 543                          break;
 544  
 545                          case 'notsuperadmin':
 546                              $userfunction = 'remove_superadmin';
 547                              revoke_super_admin( $val );
 548                          break;
 549  
 550                          case 'spam':
 551                              $user = new WP_User( $val );
 552                              if ( in_array( $user->user_login, get_site_option( 'site_admins', array( 'admin' ) ) ) )
 553                                  wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network admnistrator.' ), esc_html( $user->user_login ) ) );
 554  
 555                              $userfunction = 'all_spam';
 556                              $blogs = get_blogs_of_user( $val, true );
 557                              foreach ( (array) $blogs as $key => $details ) {
 558                                  if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
 559                                      update_blog_status( $details->userblog_id, 'spam', '1' );
 560                              }
 561                              update_user_status( $val, 'spam', '1', 1 );
 562                          break;
 563  
 564                          case 'notspam':
 565                              $userfunction = 'all_notspam';
 566                              $blogs = get_blogs_of_user( $val, true );
 567                              foreach ( (array) $blogs as $key => $details ) 
 568                                  update_blog_status( $details->userblog_id, 'spam', '0' );
 569  
 570                              update_user_status( $val, 'spam', '0', 1 );
 571                          break;
 572                      }        
 573                  }            
 574              }
 575  
 576              wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
 577              exit();
 578          } else {
 579              wp_redirect( admin_url( 'ms-users.php' ) );
 580          }
 581      break;
 582  
 583      case 'dodelete':
 584          check_admin_referer( 'ms-users-delete' );
 585          if ( ! current_user_can( 'manage_network_users' ) )
 586              wp_die( __( 'You do not have permission to access this page.' ) );
 587  
 588          if ( is_array( $_POST['blog'] ) && ! empty( $_POST['blog'] ) ) {
 589              foreach ( $_POST['blog'] as $id => $users ) {
 590                  foreach ( $users as $blogid => $user_id ) {
 591                      if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
 592                          remove_user_from_blog( $id, $blogid, $user_id );
 593                      else
 594                          remove_user_from_blog( $id, $blogid );
 595                  }
 596              }
 597          }
 598          $i = 0;
 599          if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
 600              foreach( $_POST['user'] as $id ) {
 601                  wpmu_delete_user( $id );
 602                  $i++;    
 603              }
 604  
 605          if ( $i == 1 )
 606              $deletefunction = 'delete';
 607          else
 608              $deletefunction = 'all_delete';
 609  
 610          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), admin_url( 'ms-users.php' ) ) );
 611      break;
 612  
 613      case 'adduser':
 614          check_admin_referer( 'add-user' );
 615          if ( ! current_user_can( 'manage_network_users' ) )
 616              wp_die( __( 'You do not have permission to access this page.' ) );
 617  
 618          if ( is_array( $_POST['user'] ) == false )
 619              wp_die( __( 'Cannot create an empty user.' ) );
 620          $user = $_POST['user'];
 621          if ( empty($user['username']) && empty($user['email']) )
 622              wp_die( __( 'Missing username and email.' ) );
 623          elseif ( empty($user['username']) )
 624              wp_die( __( 'Missing username.' ) );
 625          elseif ( empty($user['email']) )
 626              wp_die( __( 'Missing email.' ) );
 627  
 628          $password = wp_generate_password();
 629          $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
 630  
 631          if ( false == $user_id )
 632               wp_die( __( 'Duplicated username or email address.' ) );
 633          else
 634              wp_new_user_notification( $user_id, $password );
 635  
 636          if ( get_site_option( 'dashboard_blog' ) == false )
 637              add_user_to_blog( $current_site->blog_id, $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
 638          else
 639              add_user_to_blog( get_site_option( 'dashboard_blog' ), $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
 640  
 641          wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'add' ), wp_get_referer() ) );
 642          exit();
 643      break;
 644  
 645      default:
 646          wp_redirect( admin_url( 'ms-admin.php' ) );
 647      break;
 648  }
 649  ?>


Generated: Mon Apr 5 14:26:09 2010 Cross-referenced by PHPXref 0.7