Access is a simple scalable WordPress plugin to control user access via the taxonomy API and user roles/capabilities/IDs.
Create access terms via Posts → Access → Add New. Choose any name and set its slug to a role, capability, or user ID.
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.
- Viewing an access-controlled singular item. (Its 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.
Use a hook to display a login form and/or message to inform users that they can log in to access more content.
'@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
add_filter('@access:message', function($message, $grants, $denies) {
if (is_user_logged_in()) return;
$url = admin_url();
return "<a href='$url'>Login</a> to view additional content.";
}, 10, 3);
add_filter('@access:message', function($message, $grants, $denies) {
if (is_user_logged_in()) return;
$form = "<h3>Login</h3>" . wp_login_form(array('echo' => 0));
return "<div class='loop-login'>$form</div>";
}, 10, 3);
For CSS purposes, messages are wrapped in a div.access-message
with an applicable contextual class.
Requires: PHP 5.3+
- Upload to the
/wp-content/plugins/
directory - Activate through the Plugins menu in WordPress
Fund development with tips to @ryanve =)
License: MIT
Copyright (C) 2013 by Ryan Van Etten