'; echo '
'; //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 '

'.__('Network Settings','amulang').'

'; echo '

'.__('Please refer to the Information at the bottom of this page for more information about these settings.','amulang').'

'; echo '

'.__('Subsite Plugin Access','amulang').'

'; echo '
'; echo '
'; echo '
'; //allow subsite access to plugin echo '
'; echo ' '; echo ' '; echo '
'; //allow access to Add Existing option echo '
'; echo ' '; echo ' '; echo '
'; echo '
'; echo '

'.__('Notifications').'

'; echo '
'; //superadmin get copies of added users echo '
'; echo ' '; echo ' '; } else { echo 'value="" />'; } echo '
'; echo '
'; echo '
'; echo ' '; echo ' '; 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 '

'.__('Results of your new user registrations','amulang').'

'; 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 '
'; //get this blogs id global $wpdb, $blog_id, $wp_roles; $mainsite = SITE_ID_CURRENT_SITE; $check_capabilities = 'wp_'.$blog_id.'_capabilities'; $lastuser = ''; $usertotal = 0; echo '

'.__('Add Network Users Options').'

'; //show users list $allusers = $wpdb->get_results( "SELECT ID, user_login, user_email FROM $wpdb->users ORDER BY ID ASC"); if ($wpdb->num_rows == 0) { echo '

'.__('You have no available users to add.','amulang').'

'; } else { //show multisite options wrapped in genoption echo '
'; if (get_option('amu_setallroles')) { $rolesel = get_option('amu_setallroles'); } else { $rolesel = 'notset'; } $roles = $wp_roles->get_names(); //set all users to this role? echo '
'; echo ' '; echo ' '; echo '
'; //username strict validation option... echo '
'; echo ' '; echo ' '; echo '
'; //end multisite options wrap echo '
'; echo '

'.__('Select network users to add to this site','amulang').':

'; //start fieldset wrap echo '
'; //show check all option echo '
'; echo ''; echo ''; echo '
'; //show user rows foreach ( $allusers as $user ) { //if on main site if($blog_id == $mainsite) { if(!get_user_meta($user->ID, 'wp_capabilities')) { //start print if ($usertotal & 1) { echo '
'; } else { echo '
'; } echo ' '; echo ' '; echo ' '; echo '
'; $lastuser = $user->ID; $usertotal++; } } else { //if on subsite if(!get_user_meta($user->ID, $check_capabilities)) { //start print if ($usertotal & 1) { echo '
'; } else { echo '
'; } echo ' '; echo ' '; echo ' '; echo '
'; $lastuser = $user->ID; $usertotal++; } } } if($usertotal == 0) { echo '
'; echo '
'; echo '

'.__('All users on your Network are already assigned a role on this site.','amulang').'

'; echo '
'; } else { echo ''; echo '
'; //show add button echo '
'; echo ' '; echo '
'; } } echo ''; } /* * HELPER - ADDS HEADING INFORMATION AND ERROR IF EXISTS * interface to add users to site from network list */ function amuGetUserListHead($userListError) { echo '
'; echo $userListError; echo '

'.__('Select the users you wish to add to this site from your Network Users list and click the Add All Users button.','amulang').' '.__('Only users from your Network that are not already added to this site will appear in the list below.','amulang').'

'; echo '
'; } ?>