Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ryanve/access

WP plugin to control user access via taxonomy terms
https://github.com/ryanve/access

role-based-access-control role-manager roles wordpress wordpress-plugin wp-plugin

Last synced: about 1 month ago
JSON representation

WP plugin to control user access via taxonomy terms

Awesome Lists containing this project

README

        

# [Access](../../)

#### Access is a simple scalable WordPress plugin to control user access via the [taxonomy API](http://codex.wordpress.org/Taxonomies) and user [roles/capabilities](http://codex.wordpress.org/Roles_and_Capabilities)/IDs.

## Usage

Create access terms via PostsAccessAdd New. Choose any name and set its slug to a [role](http://codex.wordpress.org/Roles_and_Capabilities#Roles), [capability](http://codex.wordpress.org/Roles_and_Capabilities#Capabilities), or user ID.

#### Example Terms


Name
Slug
Restricts By


Members
read
capability


Editors
editor
role


John Doe
47
user ID

Access terms can be added to any post type via Edit (or Quick Edit) similar to how categories are added. Posts with access terms are only seen by users logged in with sufficient capability. Denied posts are excluded from the loop.

## UX

### Contexts

- Viewing an access-controlled singular item. (Its [permalink](http://en.wikipedia.org/wiki/Permalink).)
- Viewing a collection that includes (all or some) access-controlled items. In this case only items that the current user has permission to view are displayed.

### Customization

Use a hook to display a [login form](http://codex.wordpress.org/Function_Reference/wp_login_form) and/or message to inform users that they can log in to access more content.

#### Hooks

##### Filter hooks during the `'loop_start'` action

- `'@access:message'` runs for all cases
- `'@access:message:!denied'` runs if all posts are not denied
- `'@access:message:!limited'` runs if posts are all granted or all denied
- `'@access:message:!granted'` runs if all posts are not granted
- `'@access:message:denied'` runs if all posts are denied
- `'@access:message:limited'` runs if some posts are granted, some denied
- `'@access:message:granted'` runs if all posts are granted

##### Example Message

```php
add_filter('@access:message', function($message, $grants, $denies) {
if (is_user_logged_in()) return;
$url = admin_url();
return "Login to view additional content.";
}, 10, 3);
```

##### Example Login Form

```php
add_filter('@access:message', function($message, $grants, $denies) {
if (is_user_logged_in()) return;
$form = "

Login

" . wp_login_form(array('echo' => 0));
return "";
}, 10, 3);
```

#### CSS

For CSS purposes, messages are wrapped in a `div.access-message` with an applicable contextual class.

## Install

Requires: PHP 5.3+

1. Upload to the `/wp-content/plugins/` directory
1. Activate through the Plugins menu in WordPress

## Fund

Fund development with [tips to @ryanve](https://www.gittip.com/ryanve/) =)

## License: [MIT](http://opensource.org/licenses/MIT)

Copyright (C) 2013 by [Ryan Van Etten](https://github.com/ryanve)