本文整理汇总了PHP中WP_Roles::add_role方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_Roles::add_role方法的具体用法?PHP WP_Roles::add_role怎么用?PHP WP_Roles::add_role使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_Roles
的用法示例。
在下文中一共展示了WP_Roles::add_role方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: add
/**
*
* @return type
*/
public function add()
{
$name = trim(aam_Core_Request::post('name'));
$roles = new WP_Roles();
$role_id = 'aamrole_' . uniqid();
if ($roles->add_role($role_id, $name)) {
$response = array('status' => 'success', 'role' => $role_id);
} else {
$response = array('status' => 'failure');
}
return json_encode($response);
}
示例2: add_dentix_caps_to_admin
public function add_dentix_caps_to_admin()
{
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
//create a new role, based on the subscriber role
$subscriber = $wp_roles->get_role('subscriber');
$wp_roles->add_role('dentist', __('Dentist', 'dentix'), $subscriber->capabilities);
$caps = array('read', 'read_patient', 'read_private_patients', 'edit_patients', 'edit_private_patients', 'edit_published_patients', 'edit_others_patients', 'publish_patients', 'delete_patients', 'delete_private_patients', 'delete_published_patients', 'delete_others_patients', 'upload_files');
$roles = array(get_role('administrator'), get_role('dentist'));
foreach ($roles as $role) {
foreach ($caps as $cap) {
$role->add_cap($cap);
}
}
}
示例3: add
/**
*
* @return type
*/
public function add()
{
$name = trim(aam_Core_Request::post('name'));
$roles = new WP_Roles();
$role_id = 'aamrole_' . uniqid();
//if inherited role is set get capabilities from it
$parent = trim(aam_Core_Request::post('inherit'));
if ($parent && $roles->get_role($parent)) {
$caps = $roles->get_role($parent)->capabilities;
} else {
$caps = array();
}
if ($roles->add_role($role_id, $name, $caps)) {
$response = array('status' => 'success', 'role' => $role_id);
} else {
$response = array('status' => 'failure');
}
return json_encode($response);
}
示例4: wpdm_cal_create_new_role
function wpdm_cal_create_new_role()
{
global $wpdb;
$option_name = "{$wpdb->prefix}user_roles";
$roles = maybe_unserialize(get_option($option_name));
$nrk = preg_replace('/([^a-z,0-9]+)/is', '_', strtolower($_POST['wpdm_cal_new_role']));
if (!@array_key_exists($nrk, $roles) && $nrk != '') {
$role_obj = new WP_Roles();
$role_obj->add_role($nrk, $_POST['wpdm_cal_new_role'], array('read' => 1, 'level_0' => 1));
echo $_POST['wpdm_cal_new_role'];
die;
} else {
if (@array_key_exists($nrk, $roles)) {
die('Role name already exists');
}
if ($nrk == '') {
die('Invalid Role name');
}
}
}
示例5: orbis_update_roles
function orbis_update_roles($roles)
{
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
foreach ($roles as $role => $data) {
if (isset($data['display_name'], $data['capabilities'])) {
$display_name = $data['display_name'];
$capabilities = $data['capabilities'];
if ($wp_roles->is_role($role)) {
foreach ($capabilities as $cap => $grant) {
$wp_roles->add_cap($role, $cap, $grant);
}
} else {
$wp_roles->add_role($role, $display_name, $capabilities);
}
}
}
}
示例6: add_role
/**
* Add role, if it does not exist.
*
* @see WP_Roles::add_role() Uses method to add role.
* @since 2.0.0
*
* @param string $role Role name.
* @param string $display_name Display name for role.
* @param array $capabilities List of capabilities, e.g. array( 'edit_posts' => true, 'delete_posts' => false );
* @return null|WP_Role WP_Role object if role is added, null if already exists.
*/
function add_role($role, $display_name, $capabilities = array())
{
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
return $wp_roles->add_role($role, $display_name, $capabilities);
}
示例7: add_role
/**
* Updates the list of roles, if the role doesn't already exist.
*
* The capabilities are defined in the following format `array( 'read' => true );`
* To explicitly deny a role a capability you set the value for that capability to false.
*
* In this overide method you can extends the capapilities array with format
* `array( 'read' => true, 'description' => 'Thsi capability allow access to...' );`
*
* @brief Add role name with capabilities to list.
*
* @param string $role Role name.
* @param string $display_name Role display name.
* @param array $capabilities Optional. List of role capabilities in the above format.
* @param string $description Optional. An extend description for this role.
* @param string $owner Optional. Owner of this role
*
* @note This method override the WP_Roles method to extend
*
* @return null|WP_Role
*/
public function add_role($role, $display_name, $capabilities = array(), $description = '', $owner = '')
{
// Normalize caps
$caps = array();
foreach ($capabilities as $cap) {
$caps[$cap] = true;
}
// Ask to parent
$role_object = parent::add_role($role, $display_name, $caps);
// Stability
if (!is_null($role_object)) {
if (!isset($this->extend_data[$role])) {
$this->extend_data[$role] = array($display_name, $description, $owner);
}
update_option(self::OPTION_KEY, $this->extend_data);
/**
* Fires when a role is added.
*
* @since 1.6.0
*
* @param string $role The role key.
* @param array $extend The array with extend data for this role
*/
do_action('wpdk_user_roles_added_role', $role, $this->extend_data[$role]);
}
return $role_object;
}
示例8: array
/**
* Create a brand new role, with its capabilities. The add_role from parent is simply made more secure.
*
* @brief Create a brand new role
*
* @since 0.0.1
*
* @param string $sRoleName - role name/key in DB and in the whole system
* @param string $sRoleLabel - label of role in WordPress environment ( i.e. in user settings ).
* @param array $aCapabilities (optional) Array of capabilities for this role. Default to array().
*
* @return mixed WP_Role|WPDKError : the new role, or the error occurred.
*
*/
function add_role($sRoleName, $sRoleLabel, $aCapabilities = array())
{
// check about role syntax
if (empty($sRoleName) || empty($sRoleLabel)) {
return new WPDKError('WPDKRoles', __('Role data cannot be empty.', WPDK_TEXTDOMAIN));
}
// check about role data length
if (strlen($sRoleName) >= self::MAX_LENGTH_OF_ROLE_DATA || strlen($sRoleLabel) >= self::MAX_LENGTH_OF_ROLE_DATA) {
return new WPDKError('WPDKRoles', sprintf(__('Role data cannot be more than %s chars.', WPDK_TEXTDOMAIN), self::MAX_LENGTH_OF_ROLE_DATA));
}
// role name/key can contain only letters, digits and some other chars
if (1 == preg_match('/[^a-zA-Z0-9_\\-]+/', $sRoleName)) {
return new WPDKError('WPDKRoles', __('Role name can contain only letters, digits, \'_\' and \'-\' chars.', WPDK_TEXTDOMAIN));
}
// this role must be UNIQ in the whole WP system
if (TRUE == $this->is_role($sRoleName)) {
return new WPDKError('WPDKRoles', sprintf(__("Can't create two roles with the same name '%s'.", WPDK_TEXTDOMAIN), $sRoleName));
}
// create the role
$cRole = parent::add_role($sRoleName, $sRoleLabel, $aCapabilities);
// update options with extended data about role and return - role has a prefix to distinguish from cap
// return self::update_extended_data( self::ROLE_KEY_PREFIX . $sRoleName, $aNewData );
return $cRole;
}
示例9: 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)));
}
}
}
示例10: 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';
}
示例11: 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');
}
示例12: ajax_add
/**
* Handle the Add Role AJAX
*
* @param $params
* @return mixed|void
*/
public function ajax_add($params)
{
global $wp_roles;
$role_name = pods_var_raw('role_name', $params);
$role_label = pods_var_raw('role_label', $params);
$params->capabilities = (array) pods_var_raw('capabilities', $params, array());
$params->custom_capabilities = (array) pods_var_raw('custom_capabilities', $params, array());
$params->custom_capabilities = array_filter(array_unique($params->custom_capabilities));
$capabilities = array();
foreach ($params->capabilities as $capability => $x) {
if (empty($capability) || true !== (bool) $x) {
continue;
}
$capabilities[esc_attr($capability)] = true;
}
foreach ($params->custom_capabilities as $x => $capability) {
if (empty($capability) || '--1' == $x) {
continue;
}
$capabilities[esc_attr($capability)] = true;
}
if (empty($role_name)) {
return pods_error(__('Role name is required', 'pods'));
}
if (empty($role_label)) {
return pods_error(__('Role label is required', 'pods'));
}
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
return $wp_roles->add_role($role_name, $role_label, $capabilities);
}
示例13: cloneUserRole
function cloneUserRole()
{
global $wp_roles;
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
$adm = $wp_roles->get_role('editor');
// Adding a new role with all admin caps.
$wp_roles->add_role('doctor', 'Doctor', $adm->capabilities);
}
示例14: 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');
}
}
示例15: add
/**
* Add New Role
*
* @return string
*
* @access public
*/
public function add()
{
$name = trim(aam_Core_Request::post('name'));
$roles = new WP_Roles();
if (aam_Core_ConfigPress::getParam('aam.native_role_id') === 'true') {
$role_id = strtolower($name);
} else {
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// SIGOES //////////////////////////////////////////////////////////////////////////
//$role_id = 'aamrole_' . uniqid(); // QUITA EL CODIGO DEL ROL EN WP_CAPABILITIES
$role_id = $name;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
}
//if inherited role is set get capabilities from it
$parent = trim(aam_Core_Request::post('inherit'));
if ($parent && $roles->get_role($parent)) {
$caps = $roles->get_role($parent)->capabilities;
} else {
$caps = array();
}
if ($roles->add_role($role_id, $name, $caps)) {
$response = array('status' => 'success', 'role' => $role_id);
} else {
$response = array('status' => 'failure');
}
return json_encode($response);
}