/** * Creates a new role object. * * @since 1.0.0 * @access public * @global object $wp_roles * @param string $role * @return void */ public function __construct($role) { global $wp_roles; // Get the WP role object. $_role = get_role($role); // Set the slug. $this->slug = $_role->name; // Set the role name. if (isset($wp_roles->role_names[$role])) { $this->name = members_translate_role($role); } // Check whether the role is editable. $editable_roles = function_exists('get_editable_roles') ? get_editable_roles() : apply_filters('editable_roles', $wp_roles->roles); $this->is_editable = array_key_exists($role, $editable_roles); // Loop through the role's caps. foreach ((array) $_role->capabilities as $cap => $grant) { // Validate any boolean grant/denied in case they are stored as strings. $grant = members_validate_boolean($grant); // Add to all caps array. $this->caps[$cap] = $grant; // If a granted cap. if (true === $grant) { $this->granted_caps[] = $cap; } elseif (false === $grant) { $this->denied_caps[] = $cap; } } // Remove user levels from granted/denied caps. $this->granted_caps = members_remove_old_levels($this->granted_caps); $this->denied_caps = members_remove_old_levels($this->denied_caps); // Remove hidden caps from granted/denied caps. $this->granted_caps = members_remove_hidden_caps($this->granted_caps); $this->denied_caps = members_remove_hidden_caps($this->denied_caps); // Set the cap count. $this->granted_cap_count = count($this->granted_caps); $this->denied_cap_count = count($this->denied_caps); // Check if we have caps. $this->has_caps = 0 < $this->granted_cap_count; }
/** * Register a new object. * * @since 1.0.0 * @access public * @param string $name * @param array $args { * @type string $label Internationalized text label. * @type string $icon Dashicon icon in the form of `dashicons-icon-name`. * @type array $caps Array of capabilities in the group. * @type bool $merge_added Whether to merge this caps into the added caps array. * @type bool $diff_added Whether to remove previously-added caps from this group. * } * @return void */ public function __construct($name, $args = array()) { $name = sanitize_key($name); $defaults = array('label' => '', 'icon' => 'dashicons-admin-generic', 'caps' => array('read'), 'merge_added' => true, 'diff_added' => false); $this->args = wp_parse_args($args, $defaults); $this->args['name'] = $name; $this->args['caps'] = members_remove_hidden_caps($this->args['caps']); }
/** * Register a new object. * * @since 1.0.0 * @access public * @param string $name * @param array $args { * @type string $label Internationalized text label. * @type string $icon Dashicon icon in the form of `dashicons-icon-name`. * @type array $caps Array of capabilities in the group. * @type bool $merge_added Whether to merge this caps into the added caps array. * @type bool $diff_added Whether to remove previously-added caps from this group. * } * @return void */ public function __construct($name, $args = array()) { foreach (array_keys(get_object_vars($this)) as $key) { if (isset($args[$key])) { $this->{$key} = $args[$key]; } } $this->name = sanitize_key($name); $this->caps = members_remove_hidden_caps($this->caps); }