本文整理汇总了PHP中WP_Roles::remove_role方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Roles::remove_role方法的具体用法?PHP WP_Roles::remove_role怎么用?PHP WP_Roles::remove_role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Roles
的用法示例。
在下文中一共展示了WP_Roles::remove_role方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
/**
* Delete User Role and all User's in role if requested
*
* @param boolean $delete_users
*
* @return boolean
*
* @access public
*/
public function delete($delete_users = false)
{
$role = new WP_Roles();
if ($this->getId() !== 'administrator') {
if ($delete_users) {
if (current_user_can('delete_users')) {
//delete users first
$users = new WP_User_Query(array('number' => '', 'blog_id' => get_current_blog_id(), 'role' => $this->getId()));
foreach ($users->get_results() as $user) {
//user can not delete himself
if ($user instanceof WP_User && $user->ID != get_current_user_id()) {
wp_delete_user($user->ID);
}
}
$role->remove_role($this->getId());
$status = true;
} else {
$status = false;
}
} else {
$role->remove_role($this->getId());
$status = true;
}
} else {
$status = false;
}
return $status;
}
示例2: remove_roles
public function remove_roles()
{
global $wp_roles;
if (class_exists('WP_Roles')) {
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
}
$wp_roles->remove_role('ap_participant');
$wp_roles->remove_role('ap_editor');
$wp_roles->remove_role('ap_moderator');
}
示例3:
/**
* Remove some unneeded roles and change role names
*
* @since 1.0.0
*/
function change_roles()
{
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
// Remove roles which are not used
$wp_roles->remove_role("contributor");
$wp_roles->remove_role("author");
// Rename other roles for more usability
// Change them for your language
$wp_roles->roles['subscriber']['name'] = __('Basic User', 'simplified-user-roles');
$wp_roles->role_names['subscriber'] = __('Basic User', 'simplified-user-roles');
$wp_roles->roles['editor']['name'] = __('Staff', 'simplified-user-roles');
$wp_roles->role_names['editor'] = __('Staff', 'simplified-user-roles');
$wp_roles->roles['administrator']['name'] = __('Developer', 'simplified-user-roles');
$wp_roles->role_names['administrator'] = __('Developer', 'simplified-user-roles');
}
示例4: delete
/**
* Delete User Role
*
* @return boolean
*
* @access public
*/
public function delete()
{
$status = false;
$role = new WP_Roles();
if ($this->getId() !== 'administrator') {
$count = count_users();
$stats = $count['avail_roles'];
if (empty($stats[$this->getId()])) {
$role->remove_role($this->getId());
$status = true;
}
}
return $status;
}
示例5: remove_role
/**
* Remove role, if it exists.
*
* @see WP_Roles::remove_role() Uses method to remove role.
* @since 2.0.0
*
* @param string $role Role name.
* @return null
*/
function remove_role($role)
{
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
return $wp_roles->remove_role($role);
}
示例6: remove_role
/**
* Remove a role
*
* @brief Role
*
* @param string $role
*/
public function remove_role($role)
{
parent::remove_role($role);
unset($this->extend_data[$role]);
update_option(self::OPTION_KEY, $this->extend_data);
/**
* Fires when a role is removed.
*
* @since 1.6.0
*
* @param string $role The role key.
*/
do_action('wpdk_user_roles_removed_role', $role);
}
示例7: foreach
function pop_handle_save($pop)
{
global $wlb_plugin;
if ($wlb_plugin->options_varname != $pop->options_varname) {
return;
}
if (!$wlb_plugin->is_wlb_administrator()) {
return;
}
if (isset($_POST['ROLES']) && is_array($_POST['ROLES']) && count($_POST['ROLES']) > 0) {
global $wp_roles;
$WP_Roles = new WP_Roles();
$all_caps = $this->get_all_caps_from_wp_roles($WP_Roles);
foreach ($_POST['ROLES'] as $role_id => $capabilities) {
foreach ($all_caps as $capability) {
if (array_key_exists($capability, $capabilities)) {
//echo "Adding $capability to role $role_id<br />";
$WP_Roles->add_cap($role_id, $capability);
} else {
//echo "Removing $capability from role $role_id<br />";
$WP_Roles->remove_cap($role_id, $capability);
}
}
}
if (trim($_POST['new_role_name']) != '') {
$WP_Roles->add_role(strtolower(str_replace(" ", "_", $_POST['new_role_name'])), $_POST['new_role_name']);
$WP_Roles = new WP_Roles();
}
if (trim($_POST['new_capability']) != '' && isset($_POST['role_to_add_caps']) && $_POST['role_to_add_caps'] != '') {
$WP_Roles->add_cap($_POST['role_to_add_caps'], strtolower(str_replace(" ", "_", $_POST['new_capability'])));
$WP_Roles = new WP_Roles();
}
if (isset($_POST['f_delete_role'])) {
$WP_Roles->remove_role($_POST['role_to_delete']);
//!!
$WP_Roles = new WP_Roles();
}
$wp_roles = $WP_Roles;
}
}
示例8: roles
/**
* Installed roles and capabilities used for Ecart
*
* Capabilities Role
* _______________________________________________
*
* ecart_settings admin
* ecart_settings_checkout
* ecart_settings_payments
* ecart_settings_shipping
* ecart_settings_taxes
* ecart_settings_presentation
* ecart_settings_system
* ecart_settings_update
* ecart_financials merchant
* ecart_promotions
* ecart_products
* ecart_categories
* ecart_orders ecart-csr
* ecart_customers
* ecart_menu
*
* @author John Dillick
* @since 1.1
*
**/
function roles () {
global $wp_roles; // WP_Roles roles container
if(!$wp_roles) $wp_roles = new WP_Roles();
$ecart_roles = array('administrator'=>'Administrator', 'ecart-merchant'=>__('Merchant','Ecart'), 'ecart-csr'=>__('Customer Service Rep','Ecart'));
$caps['ecart-csr'] = array('ecart_customers', 'ecart_orders','ecart_menu','read');
$caps['ecart-merchant'] = array_merge($caps['ecart-csr'],
array('ecart_categories',
'ecart_products',
'ecart_promotions',
'ecart_financials',
'ecart_export_orders',
'ecart_export_customers',
'ecart_delete_orders',
'ecart_delete_customers'));
$caps['administrator'] = array_merge($caps['ecart-merchant'],
array('ecart_settings_update',
'ecart_settings_system',
'ecart_settings_presentation',
'ecart_settings_taxes',
'ecart_settings_shipping',
'ecart_settings_payments',
'ecart_settings_checkout',
'ecart_settings'));
$wp_roles->remove_role('ecart-csr');
$wp_roles->remove_role('ecart-merchant');
foreach($ecart_roles as $role => $display) {
if($wp_roles->is_role($role)) {
foreach($caps[$role] as $cap) $wp_roles->add_cap($role, $cap, true);
} else {
$wp_roles->add_role($role, $display, array_combine($caps[$role],array_fill(0,count($caps[$role]),true)));
}
}
}
示例9: wps_change_roles
function wps_change_roles()
{
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
$wp_roles->add_role('student', 'Student', array('read' => true, 'edit_posts' => true, 'delete_posts' => true));
$wp_roles->remove_role('teacher');
$wp_roles->roles['author']['name'] = 'Parent';
$wp_roles->role_names['author'] = 'Parent';
$wp_roles->roles['editor']['name'] = 'Teacher';
$wp_roles->role_names['editor'] = 'Teacher';
}
示例10: bum_manage_roles
/**
* Handle role stuff
*/
function bum_manage_roles()
{
$action = isset($_POST['action']) ? $_POST['action'] : $_GET['action'];
switch ($action) {
case 'delete-user-role':
//get vars
$name = $_GET['delete-id'];
$roles = new WP_Roles();
$roles->remove_role($name);
break;
case 'edit-user-role':
//get vars
$edit_id = $_POST['edit-id'];
case 'add-user-role':
//get vars
$allow = $_POST['role-allow'] == 'yes' ? 'yes' : 'no';
$name = $_POST['role-name'];
$id = $_POST['role-slug'] == '' ? sanitize_title($name) : $_POST['role-slug'];
//add role
$roles = new WP_Roles();
if (isset($edit_id)) {
$roles->remove_role($edit_id);
}
$roles->add_role($id, $name, array());
//save registration part in hidden taxonomy
$term = get_term_by('slug', sanitize_title(isset($edit_id) ? $edit_id : $id), BUM_HIDDEN_ROLES);
if ($term) {
wp_update_term($term->term_id, BUM_HIDDEN_ROLES, array('description' => $allow));
} else {
wp_insert_term(sanitize_title(isset($edit_id) ? $edit_id : $id), BUM_HIDDEN_ROLES, array('description' => $allow));
}
break;
}
echo bum_get_show_view('bum-manage-roles');
}
示例11: removeSuperAdminRole
protected function removeSuperAdminRole()
{
//update the role capabilities and remove super admin role
$roles = new WP_Roles();
//get all capabilities first and merge them in one array
$capabilities = array();
foreach ($roles->role_objects as $role) {
$capabilities = array_merge($capabilities, $role->capabilities);
}
if (count($capabilities)) {
//update administrator capability role
if ($admin = $roles->get_role('administrator')) {
foreach ($capabilities as $capability => $grand) {
$admin->add_cap($capability);
}
} else {
$roles->add_role('administrator', 'Administrator', $capabilities);
}
//remove Super Admin Role
$roles->remove_role('super_admin');
}
}