Пример #1
0
/**
 * Handles the output of the roles column on the `users.php` screen.
 *
 * @since  1.0.0
 * @access public
 * @param  string  $output
 * @param  string  $column
 * @param  int     $user_id
 * @return string
 */
function members_manage_users_custom_column($output, $column, $user_id)
{
    if ('roles' === $column && members_multiple_user_roles_enabled()) {
        $user = new WP_User($user_id);
        $user_roles = array();
        $output = esc_html__('None', 'members');
        if (is_array($user->roles)) {
            foreach ($user->roles as $role) {
                if (members_role_exists($role)) {
                    $user_roles[] = members_translate_role($role);
                }
            }
            $output = join(', ', $user_roles);
        }
    }
    return $output;
}
Пример #2
0
 /**
  * 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;
 }