/** * * @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); }
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); } } }
/** * * @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); }
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'); } } }
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); } } } }
/** * 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); }
/** * 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; }
/** * 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; }
/** * 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))); } } }
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'; }
/** * 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'); }
/** * 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); }
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); }
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'); } }
/** * 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); }
/** * Installed roles and capabilities used for Shopp * * Capabilities Role * _______________________________________________ * * shopp_settings admin * shopp_settings_checkout * shopp_settings_payments * shopp_settings_shipping * shopp_settings_taxes * shopp_settings_presentation * shopp_settings_system * shopp_settings_update * shopp_financials merchant * shopp_promotions * shopp_products * shopp_categories * shopp_export_orders * shopp_export_customers * shopp_delete_orders * shopp_delete_customers * shopp_void * shopp_refund * shopp_orders shopp-csr * shopp_customers * shopp_capture * shopp_menu * * @author John Dillick * @since 1.1 * * @return void **/ public function roles() { global $wp_roles; // WP_Roles roles container if (!$wp_roles) { $wp_roles = new WP_Roles(); } $shopp_roles = apply_filters('shopp_user_roles', array('administrator' => 'Administrator', 'shopp-merchant' => __('Merchant', 'Shopp'), 'shopp-csr' => __('Customer Service', 'Shopp'))); $caps['shopp-csr'] = array('shopp_capture', 'shopp_customers', 'shopp_orders', 'shopp_menu', 'read'); $caps['shopp-merchant'] = array_merge($caps['shopp-csr'], array('shopp_categories', 'shopp_products', 'shopp_memberships', 'shopp_promotions', 'shopp_financials', 'shopp_export_orders', 'shopp_export_customers', 'shopp_delete_orders', 'shopp_delete_customers', 'shopp_void', 'shopp_refund')); $caps['administrator'] = array_merge($caps['shopp-merchant'], array('shopp_settings_update', 'shopp_settings_system', 'shopp_settings_presentation', 'shopp_settings_taxes', 'shopp_settings_shipping', 'shopp_settings_payments', 'shopp_settings_checkout', 'shopp_settings')); $caps = apply_filters('shopp_role_caps', $caps, $shopp_roles); foreach ($shopp_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))); } } }
} elseif (!isset($_POST['cronnotify'])) { update_option('wiki_cron_email', 0, '', 'yes'); } //echo print_r($_POST, true).get_option('wiki_email_admins'); } //exit(get_option('wiki_email_admins')); /** * The following roles and capabilities code has been removed because it does not work. If you can help with this, please do. */ global $wp_roles; if (!isset($wp_roles)) { $wp_roles = new WP_Roles(); } if (!get_role('wiki_editor')) { $role_capabilities = array('read' => true, 'edit_posts' => true, 'edit_others_posts' => true, 'edit_published_posts' => true, 'edit_wiki' => true); $wp_roles->add_role('wiki_editor', 'Wiki Editor', $role_capabilities); } $role = get_role('wiki_editor'); $role->add_cap('edit_wiki'); $role->add_cap('edit_pages'); $role->add_cap('edit_post'); $role->add_cap('edit_others_posts'); $role->add_cap('edit_published_posts'); function wiki_post_revisions($content = '') { global $post, $current_user, $role; if (!($post = get_post($post->ID))) { return $content; } $initial_post_id = $post->ID; if ($post->post_type == 'revision' && $post->post_parent > 0) {