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