本文整理汇总了PHP中WP_User::remove_role方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_User::remove_role方法的具体用法?PHP WP_User::remove_role怎么用?PHP WP_User::remove_role使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_User
的用法示例。
在下文中一共展示了WP_User::remove_role方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function bp_course_convert_customer_to_student($order_id)
{
$order = new WC_Order($order_id);
if ($order->user_id > 0) {
$user = new WP_User($order->user_id);
$user->remove_role('customer');
$user->add_role('student');
}
}
示例2:
function update_marketplace_seller_roles($user_id)
{
$user = new WP_User($user_id);
$user->remove_role('owner');
echo get_option('default_role');
exit;
$user->add_role('administrator');
}
示例3: acui_import_users
//.........这里部分代码省略.........
$data[0] = "User already exists as: " . $user_object->user_login . "<br/>(in this CSV file is called: " . $username . ")";
$problematic_row = true;
if (!empty($password)) {
wp_set_password($password, $user_id);
}
$created = false;
} elseif (email_exists($email) && $allow_multiple_accounts == "allowed") {
// if the email is registered and repeated emails are allowed
if (empty($password)) {
// if user not exist and password is empty but the column is set, it will be generated
$password = wp_generate_password();
}
$hacked_email = acui_hack_email($email);
$user_id = wp_create_user($username, $password, $hacked_email);
acui_hack_restore_remapped_email_address($user_id, $email);
} else {
if (empty($password)) {
// if user not exist and password is empty but the column is set, it will be generated
$password = wp_generate_password();
}
$user_id = wp_create_user($username, $password, $email);
}
if (is_wp_error($user_id)) {
// in case the user is generating errors after this checks
$error_string = $user_id->get_error_message();
echo '<script>alert("Problems with user: ' . $username . ', we are going to skip. \\r\\nError: ' . $error_string . '");</script>';
continue;
}
$users_registered[] = $user_id;
$user_object = new WP_User($user_id);
if (!(in_array("administrator", acui_get_roles($user_id), FALSE) || is_multisite() && is_super_admin($user_id))) {
$default_roles = $user_object->roles;
foreach ($default_roles as $default_role) {
$user_object->remove_role($default_role);
}
if (is_array($role)) {
foreach ($role as $single_role) {
$user_object->add_role($single_role);
}
} else {
$user_object->add_role($role);
}
}
// WP Members activation
if ($activate_users_wp_members == "activate") {
update_user_meta($user_id, "active", true);
}
if ($columns > 2) {
for ($i = 2; $i < $columns; $i++) {
if (!empty($data)) {
if (strtolower($headers[$i]) == "password") {
// passwords -> continue
continue;
} else {
if (in_array($headers[$i], $wp_users_fields)) {
// wp_user data
if (empty($data[$i]) && $empty_cell_action == "leave") {
continue;
} else {
wp_update_user(array('ID' => $user_id, $headers[$i] => $data[$i]));
}
} elseif (strtolower($headers[$i]) == "wp-access-areas" && is_plugin_active('wp-access-areas/wp-access-areas.php')) {
// wp-access-areas
$active_labels = array_map('trim', explode("#", $data[$i]));
foreach ($wpaa_labels as $wpa_label) {
if (in_array($wpa_label->cap_title, $active_labels)) {
示例4: array
//.........这里部分代码省略.........
if ($password) {
wp_set_auth_cookie($user->ID, true);
wp_set_current_user($user->ID, $userdata['user_login']);
do_action('wp_login', $userdata['user_login']);
} else {
$this->signal_error(__('Username already in use and password incorrect!', 'edd_fes'));
}
} else {
$userdata['role'] = 'subscriber';
$userdata['user_registered'] = date('Y-m-d H:i:s');
$user_id = wp_insert_user($userdata);
if (is_wp_error($user_id)) {
$this->signal_error($user_id->get_error_message());
}
wp_new_user_notification($user_id);
$user = new WP_User($user_id);
$user_login = $userdata['user_login'];
// log the new user in
wp_set_auth_cookie($user_id, true);
wp_set_current_user($user_id, $user_login);
do_action('wp_login', $user_login);
}
}
}
}
// at this point should have user_id
$user_id = get_current_user_id();
// if auto approved
if ((bool) EDD_FES()->helper->get_option('fes-auto-approve-vendors', true)) {
$role = 'frontend_vendor';
// save app data to vendor
$counter = 0;
foreach ($meta_vars as $meta) {
if ($meta['name'] == 'password') {
unset($meta_vars[$counter]);
}
$counter++;
}
$this->update_user_meta($meta_vars, $user_id);
// email user
$to = apply_filters('fes_registration_form_frontend_vendor_to', $userdata['user_email'], $userdata);
$from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
$from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
$subject = apply_filters('fes_registration_form_to_vendor_accepted_subject', __('Application Accepted', 'edd_fes'));
$message = EDD_FES()->helper->get_option('fes-vendor-new-auto-vendor-email', '');
$type = "user";
$id = $user_id;
$args = array('permissions' => 'fes-vendor-new-auto-vendor-email-toggle');
EDD_FES()->emails->send_email($to, $from_name, $from_email, $subject, $message, $type, $id, $args);
// add frontend_vendor role
$user->add_role('frontend_vendor');
// remove pending_vendor role
$user->remove_role('pending_vendor');
// redirect to dashboard
$response = array('success' => true, 'redirect_to' => get_permalink(EDD_FES()->helper->get_option('fes-vendor-dashboard-page', false)), 'message' => __('Your Application has been Approved!', 'edd_fes'), 'is_post' => true);
do_action('fes_registration_form_frontend_vendor', $user_id, $userdata);
$response = apply_filters('fes_register_form_frontend_vendor', $response, $user_id, $form_id, $_REQUEST);
echo json_encode($response);
exit;
// else pending vendor
} else {
// save app data to vendor
$counter = 0;
foreach ($meta_vars as $meta) {
if ($meta['name'] == 'password') {
unset($meta_vars[$counter]);
}
$counter++;
}
$this->update_user_meta($meta_vars, $user_id);
// email admin
$to = apply_filters('fes_registration_form_pending_vendor_to_admin', edd_get_admin_notice_emails(), $userdata);
$from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
$from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
$subject = apply_filters('fes_registration_form_to_admin_subject', __('New Vendor Application Received', 'edd_fes'));
$message = EDD_FES()->helper->get_option('fes-admin-new-app-email', '');
$type = "user";
$id = $user_id;
$args = array('permissions' => 'fes-admin-new-app-email-toggle');
EDD_FES()->emails->send_email($to, $from_name, $from_email, $subject, $message, $type, $id, $args);
// email user
$to = apply_filters('fes_registration_form_pending_vendor_to', $userdata['user_email'], $userdata);
$from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
$from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
$subject = apply_filters('fes_registration_form_to_vendor_received_subject', __('Application Received', 'edd_fes'));
$message = EDD_FES()->helper->get_option('fes-vendor-new-app-email', '');
$type = "user";
$id = $user_id;
$args = array('permissions' => 'fes-vendor-new-app-email-toggle');
EDD_FES()->emails->send_email($to, $from_name, $from_email, $subject, $message, $type, $id, $args);
// add pending vendor cap
$user->add_role('pending_vendor');
// redirect to app under view
$response = array('success' => true, 'redirect_to' => get_permalink(EDD_FES()->helper->get_option('fes-vendor-dashboard-page', false)), 'message' => __('Application Submitted', 'edd_fes'), 'is_post' => true);
do_action('fes_registration_form_pending_vendor', $user_id, $userdata);
$response = apply_filters('fes_register_form_pending_vendor', $response, $user_id, $form_id, $_REQUEST);
echo json_encode($response);
exit;
}
}
示例5: isset
function process_bulk_action()
{
$ids = isset($_GET['vendor']) ? $_GET['vendor'] : false;
if (empty($ids)) {
return;
}
if (!is_array($ids)) {
$ids = array($ids);
}
$current_action = $_GET['action'];
foreach ($ids as $id) {
if ('approve_vendor' === $current_action) {
if ($id < 2) {
break;
}
if (user_can($id, 'fes_is_admin') || user_can($id, 'frontend_vendor')) {
break;
}
if (!user_can($id, 'pending_vendor')) {
break;
}
$user = new WP_User($id);
$user->remove_role('pending_vendor');
$user->add_role('frontend_vendor');
$from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
$from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
$subject = apply_filters('fes_application_approved_message_subj', __('Application Approved', 'edd_fes'), 0);
$message = EDD_FES()->helper->get_option('fes-vendor-app-approved-email', '');
$type = "user";
$args['permissions'] = 'fes-vendor-app-approved-email-toggle';
EDD_FES()->emails->send_email($user->user_email, $from_name, $from_email, $subject, $message, $type, $id, $args);
do_action('fes_approve_vendor_admin', $id);
if (isset($_GET['redirect']) && $_GET['redirect'] == '2') {
wp_redirect(admin_url('admin.php?page=fes-vendors&vendor=' . $id . '&action=edit&approved=2'));
exit;
}
}
if ('revoke_vendor' === $current_action) {
if ($id < 2) {
break;
}
if (!(user_can($id, 'fes_is_admin') || user_can($id, 'frontend_vendor'))) {
break;
}
$user = new WP_User($id);
$user->remove_role('frontend_vendor');
$user->remove_cap('fes_is_admin');
$user->add_role('subscriber');
// remove all their posts
$args = array('post_type' => 'download', 'author' => $id, 'posts_per_page' => -1, 'fields' => 'ids', 'post_status' => 'any');
$query = new WP_Query($args);
foreach ($query->posts as $id) {
wp_delete_post($id, false);
}
$to = $user->user_email;
$from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
$from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
$subject = apply_filters('fes_application_revoked_message_subj', __('Application Revoked', 'edd_fes'), 0);
$message = EDD_FES()->helper->get_option('fes-vendor-app-revoked-email', '');
$type = "user";
$id = $id;
$args['permissions'] = 'fes-vendor-app-revoked-email-toggle';
EDD_FES()->emails->send_email($to, $from_name, $from_email, $subject, $message, $type, $id, $args);
do_action('fes_revoke_vendor_admin', $id);
}
if ('decline_vendor' === $current_action) {
if ($id < 2) {
break;
}
if (user_can($id, 'fes_is_admin') || user_can($id, 'frontend_vendor')) {
break;
}
if (!user_can($id, 'pending_vendor')) {
break;
}
$user = new WP_User($id);
$user->remove_role('pending_vendor');
$to = $user->user_email;
$from_name = isset($edd_options['from_name']) ? $edd_options['from_name'] : get_bloginfo('name');
$from_email = isset($edd_options['from_email']) ? $edd_options['from_email'] : get_option('admin_email');
$subject = apply_filters('fes_application_declined_message_subj', __('Application Declined', 'edd_fes'), 0);
$message = EDD_FES()->helper->get_option('fes-vendor-app-declined-email', '');
$type = "user";
$id = $id;
$args['permissions'] = 'fes-vendor-app-declined-email-toggle';
EDD_FES()->emails->send_email($to, $from_name, $from_email, $subject, $message, $type, $id, $args);
do_action('fes_decline_vendor_admin', $id);
}
if ('suspend_vendor' === $current_action) {
if ($id < 2) {
break;
}
if (user_can($id, 'pending_vendor')) {
break;
}
if (user_can($id, 'suspended_vendor')) {
break;
}
$user = new WP_User($id);
$user->remove_role('frontend_vendor');
//.........这里部分代码省略.........
示例6: foreach
/* Send role deleted message. */
add_action('members_pre_edit_roles_form', 'members_message_role_deleted');
/* Get the default role. */
$default_role = get_option('default_role');
/* Get the role we want to delete. */
$role = $_GET['role'];
/* Get all users with the role to be deleted. */
$wp_user_search = new WP_User_Search('', '', $role);
$change_users = $wp_user_search->get_results();
/* If there are users with the role we're deleting, loop through them, remove the role, and set the default role. */
if (isset($change_users) && is_array($change_users)) {
foreach ($change_users as $move_user) {
$new_user = new WP_User($move_user);
/* If the user has the role, remove it and set the default. Do we need this check? */
if ($new_user->has_cap($role)) {
$new_user->remove_role($role);
$new_user->set_role($default_role);
}
}
}
/* Remove the role. */
remove_role($role);
/* Load the edit roles page. */
require_once 'edit-roles.php';
break;
/* If a role has been updated. Is this needed still? */
/* If a role has been updated. Is this needed still? */
case 'role-updated':
/* Set some default variables. */
$title = __('Edit Role', 'members');
$role = $_GET['role'];
示例7: foreach
/**
* delete a given role from wordpress
* R22
* @param str $role
*/
function delete_role($role)
{
global $wp_roles, $iwg_rolemanagement;
if ($_POST['confirm']) {
$iwg_rolemanagement->check_admin_ref('iwg_rolemanager_delete_role_' . $role);
// no: underscore, space
// yes: minus
$role_name = $iwg_rolemanagement->check_input($role, null, false, false, true);
if (!$role_name) {
$iwg_rolemanagement->error_number += 1000;
$iwg_rolemanagement->handle_error();
}
$defaultrole = get_option('default_role');
if ($role_name == $defaultrole) {
//LAZY CODE ALERT! we should give the option of changing the default role
$iwg_rolemanagement->error_number = 1020;
$iwg_rolemanagement->handle_error();
}
//remove the role from all the users
$uids_with_role = $iwg_rolemanagement->get_all_userids_with_role($role_name);
if (count($uids_with_role) > 0) {
foreach ($uids_with_role as $id) {
$user = new WP_User($id);
$user->roles = $iwg_rolemanagement->fill_array_keys_with_true($user->roles);
//if this role removal would end them up with no roles, assign the default role instead of removing
if (count($user->roles) <= 1) {
$user->add_role($defaultrole);
$user->roles = $iwg_rolemanagement->fill_array_keys_with_true($user->roles);
}
$user->remove_role($role_name);
}
}
$wp_roles->remove_role($role_name);
header('Location: ' . $this->manage_roles_uri . '&role-deleted=true');
}
}
示例8: save_profile_update
/**
* Save for user role adding
*
* @param $user_id int
*/
public function save_profile_update($user_id)
{
global $wp_roles;
if (!is_super_admin() && !current_user_can('backwpup_admin')) {
return;
}
if (empty($user_id)) {
return;
}
if (!isset($_POST['backwpup_role'])) {
return;
}
// get BackWPup roles
$backwpup_roles = array();
foreach (array_keys($wp_roles->roles) as $role) {
if (!strstr($role, 'backwpup_')) {
continue;
}
$backwpup_roles[] = $role;
}
//get user for adding/removing role
$user = new WP_User($user_id);
//remove BackWPup role from user
foreach ($user->roles as $role) {
if (!strstr($role, 'backwpup_')) {
continue;
}
$user->remove_role($role);
}
//add new role to user
if (!empty($_POST['backwpup_role']) && in_array($_POST['backwpup_role'], $backwpup_roles)) {
$user->add_role($_POST['backwpup_role']);
}
return;
}
示例9: gmgt_add_user
//.........这里部分代码省略.........
}
if (isset($data['begin_date'])) {
$usermetadata['begin_date'] = $data['begin_date'];
}
if (isset($data['end_date'])) {
$usermetadata['end_date'] = $data['end_date'];
}
if (isset($data['first_payment_date'])) {
$usermetadata['first_payment_date'] = $data['first_payment_date'];
}
if (isset($data['member_convert'])) {
$roledata['role'] = $data['member_convert'];
}
}
if (isset($data['username'])) {
$userdata['user_login'] = $data['username'];
}
if (isset($data['email'])) {
$userdata['user_email'] = $data['email'];
}
$userdata['user_nicename'] = NULL;
$userdata['user_url'] = NULL;
if (isset($data['first_name'])) {
$userdata['display_name'] = $data['first_name'] . " " . $data['last_name'];
}
if ($data['password'] != "") {
$userdata['user_pass'] = $data['password'];
}
if ($data['action'] == 'edit') {
$userdata['ID'] = $data['user_id'];
$user_id = wp_update_user($userdata);
if (!empty($roledata)) {
$u = new WP_User($user_id);
$u->remove_role('member');
$u->add_role('staff_member');
}
$returnans = update_user_meta($user_id, 'first_name', $data['first_name']);
$returnans = update_user_meta($user_id, 'last_name', $data['last_name']);
foreach ($usermetadata as $key => $val) {
$returnans = update_user_meta($user_id, $key, $val);
}
if (isset($data['group_id'])) {
if (!empty($data['group_id'])) {
if ($this->member_exist_ingrouptable($user_id)) {
$this->delete_member_from_grouptable($user_id);
}
foreach ($data['group_id'] as $id) {
$group_data['group_id'] = $id;
$group_data['member_id'] = $user_id;
$group_data['created_date'] = date("Y-m-d");
$group_data['created_by'] = get_current_user_id();
$wpdb->insert($table_gmgt_groupmember, $group_data);
}
}
}
return $user_id;
} else {
$user_id = wp_insert_user($userdata);
$user = new WP_User($user_id);
$user->set_role($data['role']);
if ($data['role'] == 'member') {
$usermetadata['membership_status'] = "Continue";
}
foreach ($usermetadata as $key => $val) {
$returnans = add_user_meta($user_id, $key, $val, true);
}
示例10: wpcf_access_delete_role_ajax
/**
* Deletes custom role.
*/
public static function wpcf_access_delete_role_ajax()
{
if (!current_user_can('manage_options')) {
_e('There are security problems. You do not have permissions.', 'wpcf-access');
die;
}
if (!isset($_POST['wpnonce']) || !wp_verify_nonce($_POST['wpnonce'], 'wpcf-access-error-pages')) {
die('verification failed');
}
if (in_array(strtolower(trim($_POST['wpcf_access_delete_role'])), Access_Helper::wpcf_get_default_roles())) {
$error = 'true';
$output = '<div class="error toolset-alert toolset-alert-error js-toolset-alert">' . __('Role can not be deleted', 'wpcf-access') . '</div>';
} else {
$delete_role = sanitize_text_field($_POST['wpcf_access_delete_role']);
TAccess_Loader::load('CLASS/Admin_Edit');
$model = TAccess_Loader::get('MODEL/Access');
$access_roles = $model->getAccessRoles();
if ($_POST['wpcf_reassign'] != 'ignore') {
$users = get_users('role=' . $delete_role);
foreach ($users as $user) {
$user = new WP_User($user->ID);
$user->add_role(Access_Helper::wpcf_esc_like($_POST['wpcf_reassign']));
$user->remove_role($delete_role);
}
}
remove_role($delete_role);
if (isset($access_roles[$delete_role])) {
unset($access_roles[$delete_role]);
}
$model->updateAccessRoles($access_roles);
$error = 'false';
$output = Access_Admin_Edit::wpcf_access_admin_set_custom_roles_level_form(Access_Helper::wpcf_get_editable_roles());
}
echo json_encode(array('error' => $error, 'output' => $output));
die;
}
示例11: role_update
/**
* Callback function for handling user role changes. Note that we needed to execute this function
* on a different hook, `profile_update`. Using the normal hooks on the edit user screen won't work
* because WP will wipe out the role.
*
* @since 1.0.0
* @access public
* @param int $user_id
* @return void
*/
public function role_update($user_id)
{
// If the current user can't promote users or edit this particular user, bail.
if (!current_user_can('promote_users') || !current_user_can('edit_user', $user_id)) {
return;
}
// Is this a role change?
if (!isset($_POST['members_new_user_roles_nonce']) || !wp_verify_nonce($_POST['members_new_user_roles_nonce'], 'new_user_roles')) {
return;
}
// Create a new user object.
$user = new WP_User($user_id);
// If we have an array of roles.
if (!empty($_POST['members_user_roles'])) {
// Get the current user roles.
$old_roles = (array) $user->roles;
// Sanitize the posted roles.
$new_roles = array_map('members_sanitize_role', $_POST['members_user_roles']);
// Loop through the posted roles.
foreach ($new_roles as $new_role) {
// If the user doesn't already have the role, add it.
if (!in_array($new_role, (array) $user->roles)) {
$user->add_role($new_role);
}
}
// Loop through the current user roles.
foreach ($old_roles as $old_role) {
// If the role is editable and not in the new roles array, remove it.
if (members_is_role_editable($old_role) && !in_array($old_role, $new_roles)) {
$user->remove_role($old_role);
}
}
// If the posted roles are empty.
} else {
// Loop through the current user roles.
foreach ((array) $user->roles as $old_role) {
// Remove the role if it is editable.
if (members_is_role_editable($old_role)) {
$user->remove_role($old_role);
}
}
}
}
示例12: _upgrade_user_roles
private function _upgrade_user_roles()
{
global $wpdb;
$query = $wpdb->prepare("\n\t\t\tSELECT um.*\n\t\t\tFROM {$wpdb->users} u\n\t\t\tINNER JOIN {$wpdb->usermeta} um ON um.user_id = u.ID AND um.meta_key = %s\n\t\t\tWHERE um.meta_value LIKE %s\n\t\t", 'wp_capabilities', '%"lpr\\_teacher"%');
if ($rows = $wpdb->get_results($query)) {
foreach ($rows as $row) {
$user = new WP_User($row->user_id);
$user->remove_role('lpr_teacher');
$user->add_role('lp_teacher');
}
}
remove_role('lpr_teacher');
}
示例13: isset
/**
* LazyestAdmin::remove_user()
*
* @since 1.1.0
* @param int $user_id
* @param string $type user role to remove
* @return void
*/
function remove_user($user_id, $type = 'none')
{
$nonce = $_REQUEST['_wpnonce'];
$lg_settings = isset($_REQUEST['lg_settings']) ? $_REQUEST['lg_settings'] : 0;
$from_settings = wp_verify_nonce($lg_settings, 'settings');
$from_admin = wp_verify_nonce($nonce, 'lg_manage_gallery');
if ($from_admin || $from_settings) {
if ('none' == $type) {
return;
}
$user = new WP_User($user_id);
$user->remove_role("lazyest_{$type}");
switch ($type) {
case 'author':
$user->remove_cap('edit_lazyest_fields');
$user->remove_cap('lazyest_author');
case 'editor':
$user->remove_cap('upload_lazyest_files');
$user->remove_cap('create_lazyest_folder');
$user->remove_cap('lazyest_editor');
break;
case 'manager':
$user->remove_cap('manage_lazyest_files');
$user->remove_cap('lazyest_manager');
default:
break;
}
unset($user);
} else {
wp_die(esc_html__('You are not allowed to remove users from Lazyest Gallery', 'lazyest-gallery'));
}
}
示例14: lti_update
function lti_update($choice)
{
global $blog_id, $wpdb;
// Add users
$add_users = unserialize($_SESSION[LTI_SESSION_PREFIX . 'provision']);
foreach ($add_users as $new_u) {
$result = wp_insert_user(array('user_login' => $new_u->username, 'user_nicename' => $new_u->username, 'first_name' => $new_u->firstname, 'last_name' => $new_u->lastname, 'user_url' => 'http://', 'display_name' => $new_u->fullname));
if (is_wp_error($result)) {
$_SESSION[LTI_SESSION_PREFIX . 'error'] .= $new_u->username . ":" . $result->get_error_message() . "<br />";
continue;
}
// Sort out role in blog
$role = 'author';
if ($new_u->staff === TRUE) {
$role = 'administrator';
}
// Add newly created users to blog and set role
add_user_to_blog($blog_id, $result, $role);
if (is_wp_error($result)) {
$_SESSION[LTI_SESSION_PREFIX . 'error'] .= $new_u->username . ":" . $result->get_error_message() . "<br />";
}
}
// Existing users that require adding to blog
$add_to_blog = unserialize($_SESSION[LTI_SESSION_PREFIX . 'new_to_blog']);
foreach ($add_to_blog as $new_u) {
$role = 'author';
if ($new_u->staff === TRUE) {
$role = 'administrator';
}
add_user_to_blog($blog_id, $new_u->id, $role);
if (is_wp_error($result)) {
$_SESSION[LTI_SESSION_PREFIX . 'error'] .= $new_u->username . ":" . $result->get_error_message() . "<br />";
}
}
// Changed name
$changed = unserialize($_SESSION[LTI_SESSION_PREFIX . 'changed']);
foreach ($changed as $change) {
wp_update_user(array('ID' => $change->id, 'first_name' => $change->firstname, 'last_name' => $change->lastname, 'display_name' => $change->fullname));
}
// Changed role (most probably administrator -> author, author -> administrator)
$changed_role = unserialize($_SESSION[LTI_SESSION_PREFIX . 'role_changed']);
foreach ($changed_role as $changed) {
$user = new WP_User($changed->id, '', $blog_id);
$user->add_role($changed->role_changed);
if ($changed->role_changed == 'administrator') {
$user->remove_role('author');
$user->remove_role('subscriber');
}
if ($changed->role_changed == 'author') {
$user->remove_role('administrator');
$user->remove_role('subscriber');
}
if ($changed->role_changed == 'subscriber') {
$user->remove_role('administrator');
$user->remove_role('author');
}
}
// Remove users from blog but not WP as could be members of
// other blogs. Could check and handle?
if ($choice == 'delete') {
$delete = unserialize($_SESSION[LTI_SESSION_PREFIX . 'remove']);
foreach ($delete as $del) {
$user = get_user_by('login', $del->username);
remove_user_from_blog($user->ID, $blog_id);
if (is_wp_error($result)) {
$_SESSION[LTI_SESSION_PREFIX . 'error'] .= $new_u->username . ":" . $result->get_error_message() . "<br />";
}
}
}
global $wpdb;
// Get the consumer
$consumer = new LTI_Tool_Consumer($_SESSION[LTI_SESSION_PREFIX . 'key'], array($wpdb->base_prefix));
$resource = new LTI_Resource_Link($consumer, $_SESSION[LTI_SESSION_PREFIX . 'resourceid']);
if ($resource->hasSettingService()) {
$resource->doSettingService(LTI_Resource_Link::EXT_WRITE, date('d-M-Y H:i'));
}
}
示例15: foreach
function admin_delete($id, $obj)
{
global $wp_roles;
$id = $obj->id;
if (!isset($obj->data[$id])) {
return $obj->error(__('Role not found, it cannot be deleted.', 'pods'));
}
$default_role = get_option('default_role');
if ($id == $default_role) {
return $obj->error(sprintf(__('You cannot remove the <strong>%s</strong> role, you must set a new default role for the site first.', 'pods'), $obj->data[$id]['name']));
}
$wp_user_search = new WP_User_Search('', '', $id);
$users = $wp_user_search->get_results();
if (!empty($users) && is_array($users)) {
foreach ($users as $user) {
$user_object = new WP_User($user);
if ($user_object->has_cap($id)) {
$user_object->remove_role($id);
$user_object->set_role($default_role);
}
}
}
remove_role($id);
$roles = array();
foreach ($wp_roles->role_objects as $key => $role) {
$count = $this->count_users($key);
$roles[$key] = array('id' => $key, 'label' => $wp_roles->role_names[$key], 'name' => $key, 'capabilities' => count((array) $role->capabilities), 'users' => sprintf(_n('%s User', '%s Users', $count, 'pods'), $count));
if ($default_role == $key) {
$roles[$key]['label'] .= ' (site default)';
}
if (0 < $count && pods_is_admin(array('list_users'))) {
$roles[$key]['users'] .= '<br /><a href="' . admin_url(esc_url('users.php?role=' . $key)) . '">' . __('View Users', 'pods') . '</a>';
}
}
$name = $obj->data[$id]['label'] . ' (' . $obj->data[$id]['name'] . ')';
$obj->data = $roles;
$obj->total = count($roles);
$obj->total_found = count($roles);
$obj->message('<strong>' . $name . '</strong> ' . __('role removed from site.', 'pods'));
}