check_permissions(); $wp_list_table->prepare_items(); $action = $wp_list_table->current_action(); $id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0; if ( ! $id ) wp_die( __('Invalid site ID.') ); $details = get_blog_details( $id ); if ( $details->site_id != $wpdb->siteid ) wp_die( __( 'You do not have permission to access this page.' ) ); $is_main_site = is_main_site( $id ); // get blog prefix $blog_prefix = $wpdb->get_blog_prefix( $id ); // @todo This is a hack. Eventually, add API to WP_Roles allowing retrieval of roles for a particular blog. if ( ! empty($wp_roles->use_db) ) { $editblog_roles = get_blog_option( $id, "{$blog_prefix}user_roles" ); } else { // Roles are stored in memory, not the DB. $editblog_roles = $wp_roles->roles; } $action = $wp_list_table->current_action(); if ( $action ) { switch_to_blog( $id ); switch ( $action ) { case 'newuser': $user = $_POST['user']; if ( !is_array( $_POST['user'] ) || empty( $user['username'] ) || empty( $user['email'] ) ) { $update = 'err_new'; } else { $password = wp_generate_password( 12, false); $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) ); if ( false == $user_id ) { $update = 'err_new_dup'; } else { wp_new_user_notification( $user_id, $password ); add_user_to_blog( $id, $user_id, $_POST['new_role'] ); $update = 'newuser'; } } break; case 'adduser': if ( !empty( $_POST['newuser'] ) ) { $update = 'adduser'; $newuser = $_POST['newuser']; $userid = $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $newuser ) ); if ( $userid ) { $user = $wpdb->get_var( "SELECT user_id FROM " . $wpdb->usermeta . " WHERE user_id='$userid' AND meta_key='{$blog_prefix}capabilities'" ); if ( $user == false ) add_user_to_blog( $id, $userid, $_POST['new_role'] ); else $update = 'err_add_member'; } else { $update = 'err_add_notfound'; } } else { $update = 'err_add_notfound'; } break; case 'remove': if ( !current_user_can('remove_users') ) die(__('You can’t remove users.')); $update = 'remove'; if ( isset( $_REQUEST['users'] ) ) { $userids = $_REQUEST['users']; foreach ( $userids as $user_id ) { $user_id = (int) $user_id; remove_user_from_blog( $user_id, $id ); } } elseif ( isset( $_GET['user'] ) ) { remove_user_from_blog( $_GET['user'] ); } else { $update = 'err_remove'; } break; case 'promote': $editable_roles = get_editable_roles(); if ( empty( $editable_roles[$_REQUEST['new_role']] ) ) wp_die(__('You can’t give users that role.')); if ( isset( $_REQUEST['users'] ) ) { $userids = $_REQUEST['users']; $update = 'promote'; foreach ( $userids as $user_id ) { $user_id = (int) $user_id; // If the user doesn't already belong to the blog, bail. if ( !is_user_member_of_blog( $user_id ) ) wp_die(__('Cheatin’ uh?')); $user = new WP_User( $user_id ); $user->set_role( $_REQUEST['new_role'] ); } } else { $update = 'err_promote'; } break; } restore_current_blog(); wp_redirect( add_query_arg( 'update', $update, wp_get_referer() ) ); exit(); } if ( isset( $_GET['action'] ) && 'update-site' == $_GET['action'] ) { wp_redirect( wp_get_referer() ); exit(); } add_screen_option( 'per_page', array( 'label' => _x( 'Users', 'users per page (screen options)' ) ) ); $title = sprintf( __('Edit Site: %s'), get_blogaddress_by_id($id)); $parent_file = 'sites.php'; $submenu_file = 'sites.php'; require('../admin-header.php'); ?>
' . __( 'User added.' ) . '
' . __( 'User is already a member of this site.' ) . '
' . __( 'Enter the username of an existing user.' ) . '
' . __( 'Changed roles.' ) . '
' . __( 'Select a user to change role.' ) . '
' . __( 'User removed from this site.' ) . '
' . __( 'Select a user to remove.' ) . '
' . __( 'User created.' ) . '
' . __( 'Enter the username and email.' ) . '
' . __( 'Duplicated username or email address.' ) . '