Skip to content

Latest commit

 

History

History
96 lines (69 loc) · 3.23 KB

README.md

File metadata and controls

96 lines (69 loc) · 3.23 KB

Access is a simple scalable WordPress plugin to control user access via the taxonomy API and user roles/capabilities/IDs.

Usage

Create access terms via PostsAccessAdd New. Choose any name and set its slug to a role, capability, 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.)
  • 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 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
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);
Example Login Form
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);

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
  2. Activate through the Plugins menu in WordPress

Fund

Fund development with tips to @ryanve =)

License: MIT

Copyright (C) 2013 by Ryan Van Etten