';
//if saving network options...
if ( isset($_POST['setnetworkopt'] ) ) {
setNetworkOptions();
echo '
';
echo '
'.__('Network settings have been updated.','amulang').'
';
echo '
';
}
//if resetting network options...
if ( isset($_POST['resetnetworksettings'] ) ) {
amu_reset_network_options();
echo '
';
echo '
'.__('Network settings have been reset.','amulang').'
';
echo '
';
}
//show network settings options
echo '
'.__('Add Multiple Users (Network)','amulang').'
';
echo '
'.__('These options allow you to control global access, functions and options on subsites of your current network.','amulang').'
';
echo '
';
echo '
';
$infotype = 'networksettings';
showPluginInfo($infotype);
echo '
';
echo '';
}
/*
* RESET NETWORK OPTIONS FUNCTION
* Resets network options to default
*/
function amu_reset_network_options() {
global $wpdb;
update_site_option( 'amu_is_network', 'yes' );
update_site_option( 'amu_subadminaccess', 'yes' );
update_site_option( 'amu_addexistingaccess', 'yes' );
update_site_option( 'amu_emailcopies', '' );
}
/*
* SAVE NETWORK OPTIONS FUNCTION
* Saves network options in site options
*/
function setNetworkOptions() {
global $wpdb;
if ( isset($_POST['net_allowadmins'] ) ) {
$netAllowAdmins = 'yes';
} else {
$netAllowAdmins = 'no';
}
if ( isset($_POST['net_addexist'] ) ) {
$netAllowAddEx = 'yes';
} else {
$netAllowAddEx = 'no';
}
$netgetcopies = trim($_POST['net_getcopies']);
update_site_option( 'amu_subadminaccess', $netAllowAdmins );
update_site_option( 'amu_addexistingaccess', $netAllowAddEx );
update_site_option( 'amu_emailcopies', $netgetcopies );
}
/*
* ADD EXISTING USERS TO SITE INTERFACE AND FUNCTION
* interface to add users to site from network list
*/
function amu_addfromnet() {
//test again for admin priviledges
if (!current_user_can('manage_options') ) {
wp_die( __('You do not have sufficient permissions to access this page.') );
}
//set network options if they don't exist
amu_set_default_network_options();
//test if disabled by superadmin
if ( is_multisite() ) {
if (get_site_option('amu_subadminaccess')) {
if (get_site_option('amu_subadminaccess') == 'no') {
if (!current_user_can('manage_network') ) {
wp_die( __('Access to AMU functions have been disabled by the Network Administrator.') );
}
}
}
}
//test if disabled by superadmin
if ( is_multisite() ) {
if (get_site_option('amu_addexistingaccess')) {
if (get_site_option('amu_addexistingaccess') == 'no') {
if (!current_user_can('manage_network') ) {
wp_die( __('Access to this function has been disabled by the Network Administrator.') );
}
}
}
}
//when accessing amu, set options if they don't exist
amu_set_defaultoptions();
//begin wrap class
echo '';
echo '
';
echo '
'.__('Add Multiple Users - Add from Network','amulang').'
';
//if no post made, show interface and helpers
if (empty($_POST) ) {
$userListError = '';
amuGetUserListHead($userListError);
amuShowNetworkUsers();
$infotype = 'addexistusers';
showPluginInfo($infotype);
//otherwise, run add existing function
} else if ( isset($_POST['addexistingusers'] ) ) {
amuAddNetworkUsers();
//else throw error
} else {
echo '
'.__('Unknown request. Please select the Add from Network option to try again.','amulang').'
';
}
echo '
';
echo '
';
}
function amuAddNetworkUsers() {
global $wpdb, $blog_id;
$mainsite = SITE_ID_CURRENT_SITE;
//times it should loop based on highest user's id
$existing_procs = intval($_POST['existprocs']);
//set overall role value
$allExistingToRole = $_POST['existingToRole'];
echo '';
//run loop as many times as necessary
for ($i = 1; $i <= $existing_procs; $i++) {
if(isset($_POST['adduser_'.$i])) {
//send confirmation if set...
if (isset($_POST['notifyExistingUser']) ) {
//get user's info
$user_details = get_userdata($i);
if($allExistingToRole == 'notset') {
$thisAddRole = $_POST['setrole_'.$i];
} else {
$thisAddRole = $_POST['existingToRole'];
}
$newuser_key = substr( md5( $blog_id.$user_details->ID ), 0, 10 );
add_option( 'new_user_' . $newuser_key, array( 'user_id' => $user_details->ID, 'email' => $user_details->user_email, 'role' => $thisAddRole ) );
$message = __( 'Hi,
You\'ve been invited to join \'%1$s\' at
%2$s with the role of %3$s.
Please click the following link to confirm the invite:
%4$s','amulang' );
wp_mail( $user_details->user_email, sprintf( __( '[%s] Joining confirmation' ), get_option( 'blogname' ) ), sprintf($message, get_option('blogname'), site_url(), $thisAddRole, site_url("/newbloguser/$newuser_key/")));
//notification line
echo '
'.__('User','amulang').' '.$user_details->user_login.' '.__('has been sent a confirmation email.','amulang').'
';
} else {
$user_details = get_userdata($i);
//if is main site just give them a role
if($blog_id == $mainsite) {
$wp_user_object = new WP_User($i);
if($allExistingToRole == 'notset') {
$wp_user_object->set_role($_POST['setrole_'.$i]);
} else {
$wp_user_object->set_role($_POST['existingToRole']);
}
unset($wp_user_object);
//or if subsite, add them to blog
} else {
if($allExistingToRole == 'notset') {
add_existing_user_to_blog( array( 'user_id' => $i, 'role' => $_POST['setrole_'.$i] ) );
} else {
add_existing_user_to_blog( array( 'user_id' => $i, 'role' => $_POST['existingToRole'] ) );
}
}
//notification line
echo '
'.__('User','amulang').' '.$user_details->user_login.' '.__('has been added to the site.','amulang').'
';
}
}
}
echo '
';
}
/*
* SHOW NETWORK USERS
* interface to select users to add to site
*/
function amuShowNetworkUsers() {
echo '