Giter VIP home page Giter VIP logo

access's Introduction

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 Posts โ†’ Access โ†’ Add 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

access's People

Contributors

ryanve avatar polfo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.