3 * Action handler for Multisite administration panels.
6 * @subpackage Multisite
10 require_once( './admin.php' );
12 if ( ! is_multisite() )
13 wp_die( __( 'Multisite support is not enabled.' ) );
15 if ( empty( $_GET['action'] ) )
16 wp_redirect( admin_url( 'ms-admin.php' ) );
18 do_action( 'wpmuadminedit' , '');
20 if ( isset( $_GET['id' ]) )
21 $id = intval( $_GET['id'] );
22 elseif ( isset( $_POST['id'] ) )
23 $id = intval( $_POST['id'] );
25 switch ( $_GET['action'] ) {
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.' ) );
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' ) ) ) ) );
34 if ( isset($_POST['WPLANG']) && ( '' === $_POST['WPLANG'] || in_array( $_POST['WPLANG'], get_available_languages() ) ) )
35 update_site_option( 'WPLANG', $_POST['WPLANG'] );
37 if ( is_email( $_POST['admin_email'] ) )
38 update_site_option( 'admin_email', $_POST['admin_email'] );
40 $illegal_names = split( ' ', $_POST['illegal_names'] );
41 foreach ( (array) $illegal_names as $name ) {
42 $name = trim( $name );
44 $names[] = trim( $name );
46 update_site_option( 'illegal_names', $names );
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 );
57 update_site_option( 'limited_email_domains', $limited_email );
59 update_site_option( 'limited_email_domains', '' );
62 if ( $_POST['banned_email_domains'] != '' ) {
63 $banned_email_domains = split( "\n", stripslashes( $_POST['banned_email_domains'] ) );
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 );
70 update_site_option( 'banned_email_domains', $banned );
72 update_site_option( 'banned_email_domains', '' );
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;
90 $domain = $current_site->domain;
91 $path = trailingslashit( $current_site->path . $dashboard_blog );
94 $dashboard_blog_id = wpmu_create_blog( $domain, $path, __( 'My Dashboard' ), $current_user->id , array( 'public' => 0 ), $current_site->id );
97 $dashboard_blog_id = $blog_details->blog_id;
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( $var_by_ref = array_keys( $user_meta_value ) ) == 'subscriber' )
108 $move_users[] = $user->user_id;
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 );
118 update_site_option( 'dashboard_blog', $dashboard_blog_id );
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, 'add_new_users' => 0 );
122 foreach ( $checked_options as $option_name => $option_unchecked_value ) {
123 if ( ! isset( $_POST[$option_name] ) )
124 $_POST[$option_name] = $option_unchecked_value;
126 foreach ( $options as $option_name ) {
127 if ( ! isset($_POST[$option_name]) )
129 $value = stripslashes_deep( $_POST[$option_name] );
130 update_site_option( $option_name, $value );
133 // Update more options here
134 do_action( 'update_wpmu_options' );
136 wp_redirect( add_query_arg( 'updated', 'true', admin_url( 'ms-options.php' ) ) );
140 check_admin_referer( 'add-blog', '_wpnonce_add-blog' );
142 if ( ! current_user_can( 'manage_sites' ) )
143 wp_die( __( 'You do not have permission to access this page.' ) );
145 if ( is_array( $_POST['blog'] ) == false )
146 wp_die( __( 'Can’t create an empty site.' ) );
147 $blog = $_POST['blog'];
149 if ( ! preg_match( '/(--)/', $blog['domain'] ) && preg_match( '|^([a-zA-Z0-9-])+$|', $blog['domain'] ) )
150 $domain = strtolower( $blog['domain'] );
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 ) ) );
159 $email = sanitize_email( $blog['email'] );
160 $title = $blog['title'];
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.' ) );
169 if ( is_subdomain_install() ) {
170 $newdomain = $domain . '.' . preg_replace( '|^www\.|', '', $current_site->domain );
173 $newdomain = $current_site->domain;
174 $path = $base . $domain . '/';
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.' ) );
185 wp_new_user_notification( $user_id, $password );
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() ) );
201 wp_die( $id->get_error_message() );
206 check_admin_referer( 'editblog' );
207 if ( ! current_user_can( 'manage_sites' ) )
208 wp_die( __( 'You do not have permission to access this page.' ) );
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' ) ) ) ) );
213 switch_to_blog( $id );
216 $allowedthemes = array();
217 if ( isset($_POST['theme']) && is_array( $_POST['theme'] ) ) {
218 foreach ( $_POST['theme'] as $theme => $val ) {
220 $allowedthemes[$theme] = true;
223 update_option( 'allowedthemes', $allowedthemes );
226 if ( is_array( $_POST['option'] ) ) {
228 $count = count( $_POST['option'] );
229 $skip_options = array( 'allowedthemes' ); // Don't update these options since they are handled elsewhere in the form.
230 foreach ( (array) $_POST['option'] as $key => $val ) {
231 if ( $key === 0 || is_array( $val ) || in_array($key, $skip_options) )
232 continue; // Avoids "0 is a protected WP option and may not be modified" error when edit blog options
234 update_option( $key, stripslashes( $val ) );
236 update_option( $key, stripslashes( $val ), false ); // no need to refresh blog details yet
242 if ( isset( $_POST['update_home_url'] ) && $_POST['update_home_url'] == 'update' ) {
243 $blog_address = get_blogaddress_by_domain( $_POST['blog']['domain'], $_POST['blog']['path'] );
244 if ( get_option( 'siteurl' ) != $blog_address )
245 update_option( 'siteurl', $blog_address );
247 if ( get_option( 'home' ) != $blog_address )
248 update_option( 'home', $blog_address );
251 // rewrite rules can't be flushed during switch to blog
252 delete_option( 'rewrite_rules' );
254 // update blogs table
255 $blog_data = stripslashes_deep( $_POST['blog'] );
256 update_blog_details( $id, $blog_data );
259 $blog_prefix = $wpdb->get_blog_prefix( $id );
262 if ( isset( $_POST['role'] ) && is_array( $_POST['role'] ) == true ) {
263 $newroles = $_POST['role'];
266 foreach ( (array) $newroles as $userid => $role ) {
267 $user = new WP_User( $userid );
268 if ( empty( $user->ID ) )
270 $user->for_blog( $id );
271 $user->set_role( $role );
276 if ( isset( $_POST['blogusers'] ) && is_array( $_POST['blogusers'] ) ) {
277 reset( $_POST['blogusers'] );
278 foreach ( (array) $_POST['blogusers'] as $key => $val )
279 remove_user_from_blog( $key, $id );
283 if ( isset( $_POST['user_password'] ) && is_array( $_POST['user_password'] ) ) {
284 reset( $_POST['user_password'] );
285 $newroles = $_POST['role'];
286 foreach ( (array) $_POST['user_password'] as $userid => $pass ) {
287 unset( $_POST['role'] );
288 $_POST['role'] = $newroles[ $userid ];
290 $cap = $wpdb->get_var( $wpdb->prepare( "SELECT meta_value FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'", $userid ) );
291 $userdata = get_userdata($userid);
292 $_POST['pass1'] = $_POST['pass2'] = $pass;
293 $_POST['email'] = $userdata->user_email;
294 $_POST['rich_editing'] = $userdata->rich_editing;
295 edit_user( $userid );
297 $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = '{$blog_prefix}capabilities' AND meta_value = 'a:0:{}'", $userid ) );
300 unset( $_POST['role'] );
301 $_POST['role'] = $newroles;
305 if ( !empty( $_POST['newuser'] ) ) {
306 $newuser = $_POST['newuser'];
307 $userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) );
309 $user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='{$blog_prefix}capabilities'" );
310 if ( $user == false )
311 add_user_to_blog( $id, $userid, $_POST['new_role'] );
314 do_action( 'wpmu_update_blog_options' );
315 restore_current_blog();
316 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'editblog', 'id' => $id ), wp_get_referer() ) );
320 check_admin_referer('deleteblog');
321 if ( ! current_user_can( 'manage_sites' ) )
322 wp_die( __( 'You do not have permission to access this page.' ) );
324 if ( $id != '0' && $id != $current_site->blog_id )
325 wpmu_delete_blog( $id, true );
327 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'delete' ), wp_get_referer() ) );
332 if ( isset( $_POST['doaction']) || isset($_POST['doaction2'] ) ) {
333 check_admin_referer( 'bulk-ms-sites', '_wpnonce_bulk-ms-sites' );
335 if ( ! current_user_can( 'manage_sites' ) )
336 wp_die( __( 'You do not have permission to access this page.' ) );
338 if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
339 $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
342 foreach ( (array) $_POST['allblogs'] as $key => $val ) {
343 if ( $val != '0' && $val != $current_site->blog_id ) {
344 switch ( $doaction ) {
346 $blogfunction = 'all_delete';
347 wpmu_delete_blog( $val, true );
351 $blogfunction = 'all_spam';
352 update_blog_status( $val, 'spam', '1', 0 );
353 set_time_limit( 60 );
357 $blogfunction = 'all_notspam';
358 update_blog_status( $val, 'spam', '0', 0 );
359 set_time_limit( 60 );
363 wp_die( __( 'You are not allowed to change the current site.' ) );
367 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $blogfunction ), wp_get_referer() ) );
370 wp_redirect( admin_url( 'ms-sites.php' ) );
375 check_admin_referer( 'archiveblog' );
376 if ( ! current_user_can( 'manage_sites' ) )
377 wp_die( __( 'You do not have permission to access this page.' ) );
379 update_blog_status( $id, 'archived', '1' );
380 do_action( 'archive_blog', $id );
381 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'archive' ), wp_get_referer() ) );
385 case 'unarchiveblog':
386 check_admin_referer( 'unarchiveblog' );
387 if ( ! current_user_can( 'manage_sites' ) )
388 wp_die( __( 'You do not have permission to access this page.' ) );
390 do_action( 'unarchive_blog', $id );
391 update_blog_status( $id, 'archived', '0' );
392 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unarchive' ), wp_get_referer() ) );
397 check_admin_referer( 'activateblog' );
398 if ( ! current_user_can( 'manage_sites' ) )
399 wp_die( __( 'You do not have permission to access this page.' ) );
401 update_blog_status( $id, 'deleted', '0' );
402 do_action( 'activate_blog', $id );
403 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'activate' ), wp_get_referer() ) );
407 case 'deactivateblog':
408 check_admin_referer( 'deactivateblog' );
409 if ( ! current_user_can( 'manage_sites' ) )
410 wp_die( __( 'You do not have permission to access this page.' ) );
412 do_action( 'deactivate_blog', $id );
413 update_blog_status( $id, 'deleted', '1' );
414 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'deactivate' ), wp_get_referer() ) );
419 check_admin_referer( 'unspamblog' );
420 if ( ! current_user_can( 'manage_sites' ) )
421 wp_die( __( 'You do not have permission to access this page.' ) );
423 update_blog_status( $id, 'spam', '0' );
424 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'unspam' ), wp_get_referer() ) );
429 check_admin_referer( 'spamblog' );
430 if ( ! current_user_can( 'manage_sites' ) )
431 wp_die( __( 'You do not have permission to access this page.' ) );
433 update_blog_status( $id, 'spam', '1' );
434 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'spam' ), wp_get_referer() ) );
440 if ( ! current_user_can( 'manage_network_themes' ) )
441 wp_die( __( 'You do not have permission to access this page.' ) );
443 if ( is_array( $_POST['theme'] ) ) {
444 $themes = get_themes();
446 $allowed_themes = array();
447 foreach ( (array) $themes as $key => $theme ) {
448 if ( $_POST['theme'][ esc_html( $theme['Stylesheet'] ) ] == 'enabled' )
449 $allowed_themes[ esc_html( $theme['Stylesheet'] ) ] = true;
451 update_site_option( 'allowedthemes', $allowed_themes );
453 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'themes' ), wp_get_referer() ) );
459 if ( !headers_sent() ) {
461 header( 'Content-Type: text/html; charset=utf-8' );
463 if ( $current_site->blog_id == $id )
464 wp_die( __( 'You are not allowed to change the current site.' ) );
466 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
467 <html xmlns="http://www.w3.org/1999/xhtml" <?php if ( function_exists( 'language_attributes' ) ) language_attributes(); ?>>
469 <title><?php _e( 'WordPress › Confirm your action' ); ?></title>
471 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
473 wp_admin_css( 'install', true );
474 wp_admin_css( 'ie', true );
478 <h1 id="logo"><img alt="WordPress" src="<?php echo esc_attr( admin_url( 'images/wordpress-logo.png' ) ); ?>" /></h1>
479 <form action="ms-edit.php?action=<?php echo esc_attr( $_GET['action2'] ) ?>" method="post">
480 <input type="hidden" name="action" value="<?php echo esc_attr( $_GET['action2'] ) ?>" />
481 <input type="hidden" name="id" value="<?php echo esc_attr( $id ); ?>" />
482 <input type="hidden" name="_wp_http_referer" value="<?php echo esc_attr( wp_get_referer() ); ?>" />
483 <?php wp_nonce_field( $_GET['action2'], '_wpnonce', false ); ?>
484 <p><?php echo esc_html( stripslashes( $_GET['msg'] ) ); ?></p>
485 <p class="submit"><input class="button" type="submit" value="<?php _e( 'Confirm' ); ?>" /></p>
494 if ( ! current_user_can( 'manage_network_users' ) )
495 wp_die( __( 'You do not have permission to access this page.' ) );
497 check_admin_referer( 'deleteuser' );
499 if ( $id != '0' && $id != '1' ) {
500 $_POST['allusers'] = array( $id ); // confirm_delete_users() can only handle with arrays
501 $title = __( 'Users' );
502 $parent_file = 'ms-admin.php';
503 require_once( 'admin-header.php' );
504 echo '<div class="wrap">';
505 confirm_delete_users( $_POST['allusers'] );
507 require_once( 'admin-footer.php' );
510 wp_redirect( admin_url( 'ms-users.php' ) );
515 if ( ! current_user_can( 'manage_network_users' ) )
516 wp_die( __( 'You do not have permission to access this page.' ) );
518 if ( isset( $_POST['doaction']) || isset($_POST['doaction2'] ) ) {
519 check_admin_referer( 'bulk-ms-users', '_wpnonce_bulk-ms-users' );
521 if ( $_GET['action'] != -1 || $_POST['action2'] != -1 )
522 $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2'];
524 foreach ( (array) $_POST['allusers'] as $key => $val ) {
525 if ( !empty( $val ) ) {
526 switch ( $doaction ) {
528 $title = __( 'Users' );
529 $parent_file = 'ms-admin.php';
530 require_once( 'admin-header.php' );
531 echo '<div class="wrap">';
532 confirm_delete_users( $_POST['allusers'] );
534 require_once( 'admin-footer.php' );
539 $user = new WP_User( $val );
540 if ( in_array( $user->user_login, get_super_admins() ) )
541 wp_die( sprintf( __( 'Warning! User cannot be modified. The user %s is a network administrator.' ), esc_html( $user->user_login ) ) );
543 $userfunction = 'all_spam';
544 $blogs = get_blogs_of_user( $val, true );
545 foreach ( (array) $blogs as $key => $details ) {
546 if ( $details->userblog_id != $current_site->blog_id ) // main blog not a spam !
547 update_blog_status( $details->userblog_id, 'spam', '1' );
549 update_user_status( $val, 'spam', '1', 1 );
553 $userfunction = 'all_notspam';
554 $blogs = get_blogs_of_user( $val, true );
555 foreach ( (array) $blogs as $key => $details )
556 update_blog_status( $details->userblog_id, 'spam', '0' );
558 update_user_status( $val, 'spam', '0', 1 );
564 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $userfunction ), wp_get_referer() ) );
567 wp_redirect( admin_url( 'ms-users.php' ) );
572 check_admin_referer( 'ms-users-delete' );
573 if ( ! current_user_can( 'manage_network_users' ) )
574 wp_die( __( 'You do not have permission to access this page.' ) );
576 if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) {
577 foreach ( $_POST['blog'] as $id => $users ) {
578 foreach ( $users as $blogid => $user_id ) {
579 if ( ! empty( $_POST['delete'] ) && 'reassign' == $_POST['delete'][$blogid][$id] )
580 remove_user_from_blog( $id, $blogid, $user_id );
582 remove_user_from_blog( $id, $blogid );
587 if ( is_array( $_POST['user'] ) && ! empty( $_POST['user'] ) )
588 foreach( $_POST['user'] as $id ) {
589 wpmu_delete_user( $id );
594 $deletefunction = 'delete';
596 $deletefunction = 'all_delete';
598 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), admin_url( 'ms-users.php' ) ) );
602 check_admin_referer( 'add-user', '_wpnonce_add-user' );
603 if ( ! current_user_can( 'manage_network_users' ) )
604 wp_die( __( 'You do not have permission to access this page.' ) );
606 if ( is_array( $_POST['user'] ) == false )
607 wp_die( __( 'Cannot create an empty user.' ) );
608 $user = $_POST['user'];
609 if ( empty($user['username']) && empty($user['email']) )
610 wp_die( __( 'Missing username and email.' ) );
611 elseif ( empty($user['username']) )
612 wp_die( __( 'Missing username.' ) );
613 elseif ( empty($user['email']) )
614 wp_die( __( 'Missing email.' ) );
616 $password = wp_generate_password();
617 $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
619 if ( false == $user_id )
620 wp_die( __( 'Duplicated username or email address.' ) );
622 wp_new_user_notification( $user_id, $password );
624 if ( get_site_option( 'dashboard_blog' ) == false )
625 add_user_to_blog( $current_site->blog_id, $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
627 add_user_to_blog( get_site_option( 'dashboard_blog' ), $user_id, get_site_option( 'default_user_role', 'subscriber' ) );
629 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => 'add' ), wp_get_referer() ) );
634 wp_redirect( admin_url( 'ms-admin.php' ) );