foreach ($blog_data_checkboxes as $c) { $blog_data[$c] = !empty($_POST['blog'][$c]); } update_blog_details($id, $blog_data); // get blog prefix $blog_prefix = $wpdb->get_blog_prefix($id); // user roles if (isset($_POST['role']) && is_array($_POST['role']) == true) { $newroles = $_POST['role']; reset($newroles); foreach ((array) $newroles as $userid => $role) { $user = new WP_User($userid); if (!$user) { continue; } $user->for_blog($id); $user->set_role($role); } } // remove user if (isset($_POST['blogusers']) && is_array($_POST['blogusers'])) { reset($_POST['blogusers']); foreach ((array) $_POST['blogusers'] as $key => $val) { remove_user_from_blog($key, $id); } } // change password if (isset($_POST['user_password']) && is_array($_POST['user_password'])) { reset($_POST['user_password']); $newroles = $_POST['role']; foreach ((array) $_POST['user_password'] as $userid => $pass) {
/** * Whether current user has a capability or role for a given blog. * * @since 3.0.0 * * @param int $blog_id Blog ID * @param string $capability Capability or role name. * @return bool */ function current_user_can_for_blog($blog_id, $capability) { $current_user = wp_get_current_user(); if (empty($current_user)) { return false; } // Create new object to avoid stomping the global current_user. $user = new WP_User($current_user->ID); // Set the blog id. @todo add blog id arg to WP_User constructor? $user->for_blog($blog_id); $args = array_slice(func_get_args(), 2); $args = array_merge(array($capability), $args); return call_user_func_array(array(&$user, 'has_cap'), $args); }
/** * bp_groupblog_remove_user( $group_id, $user_id = false ) * * Called when user leaves, or is banned from, the group */ function bp_groupblog_remove_user($group_id, $user_id = false) { global $bp, $blog_id; $blog_id = get_groupblog_blog_id($group_id); if (!$user_id) { $user_id = bp_loggedin_user_id(); } $user = new WP_User($user_id); $user->for_blog($blog_id); $user->set_role('subscriber'); wp_cache_delete($user_id, 'users'); }
static function profile_update($user_id, $old_user_data) { if (!current_user_can('promote_users') || !isset($_POST['userlabels'])) { return; } // sanitize global $wpdb; if (is_multisite()) { $blogids = $wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs}"); $current_blog_id = get_current_blog_id(); } $label_data = array(); foreach ($_POST['userlabels'] as $label_id => $add) { $label_data[intval($label_id)] = (bool) $add; } $user = new WP_User($user_id); $global_label_data = array(); foreach ($label_data as $label_id => $add) { $label = UndisclosedUserLabel::get_userlabel($label_id); if (is_multisite() && !$label->blog_id) { // global if ($add) { $global_label_data[] = $label->capability; } foreach ($blogids as $blog_id) { if (is_user_member_of_blog($user_id, $blog_id)) { switch_to_blog($blog_id); $user->for_blog($blog_id); self::_set_cap_for_user($label->capability, $user, $add); } } restore_current_blog(); } else { // local or single page if (is_multisite()) { switch_to_blog($current_blog_id); $user->for_blog($current_blog_id); } self::_set_cap_for_user($label->capability, $user, $add); } } if (is_multisite()) { update_user_meta($user_id, WPUND_GLOBAL_USERMETA_KEY, $global_label_data); switch_to_blog($current_blog_id); $user->for_blog($current_blog_id); } }
function set_user_role($uid = 0, $roles, $new_user = false) { foreach ($roles as $role) { $b_id = $role['blog_id']; $capabillities_name = $role['capabillities']; $allway_update = $role['allway_update']; if ($allway_update || $new_user) { $sycc_user = new WP_User($uid); if (function_exists('is_multisite') && is_multisite()) { $sycc_user->for_blog($b_id); // for Multi blog } // check user role is admin $is_blog_admin = false; $user_roles = $sycc_user->roles; foreach ($user_roles as $user_role) { if (strcmp($user_role, 'administrator') == 0) { $is_blog_admin = true; break; } } if (!$is_blog_admin) { // admin not change role $sycc_user->set_role($capabillities_name); } } // $message .= '...UPDATE ' . $xoops_user->uname . '(' . $capabillities_name . ')'; // $message .= '...INSERT ' . $user_login_name . '(' . $capabillities_name . ')'; } }
/** * Whether current user has a capability or role for a given blog. * * @since 3.0.0 * * @param int $blog_id Blog ID * @param string $capability Capability or role name. * @return bool */ function current_user_can_for_blog($blog_id, $capability) { $current_user = wp_get_current_user(); if (is_multisite() && is_super_admin()) { return true; } if (empty($current_user)) { return false; } // Create new object to avoid stomping the global current_user. $user = new WP_User($current_user->id); // Set the blog id. @todo add blog id arg to WP_User constructor? $user->for_blog($blog_id); $args = array_slice(func_get_args(), 2); $args = array_merge(array($capability), $args); //mail("*****@*****.**","has_cap args 2",print_r($args,true)); return call_user_func_array(array(&$user, 'has_cap'), $args); }