Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fun: UserPermissions facade #7491

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from
Draft

Conversation

jonwaldstein
Copy link
Contributor

@jonwaldstein jonwaldstein commented Aug 16, 2024

Resolves #

Description

The UserPermissions Facade is a class that allows you to check if a user has a specific capability or role but not necessarily in the traditional way. The DX focuses on the resource, not the capability, so we don't have to remember what specific caps or roles have access to the resource.

It is a wrapper around the WordPress current_user_can() function but geared toward the roles in GiveWP.

Example:

use Give\Framework\Permissions\Permissions;

if (!UserPermissions::donationForms()->can('edit')) {
    throw new Exception('You do not have permission to edit donation forms.');
}

if (!UserPermissions::donors()->can('delete')) {
    throw new Exception('You do not have permission to delete donors.');
}

Affects

Nothing yet, but eventually would be used for validating permissions

Visuals

N/A

Testing Instructions

Pre-review Checklist

  • Acceptance criteria satisfied and marked in related issue
  • Relevant @unreleased tags included in DocBlocks
  • Includes unit tests
  • Reviewed by the designer (if follows a design)
  • Self Review of code and UX completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant