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

Allow developers to select which user permissions are necessary to authenticate API calls #200

Open
brachypelma opened this issue Mar 20, 2023 · 1 comment · May be fixed by #203
Open

Comments

@brachypelma
Copy link

This is somewhat related to this closed issue.

I noticed that the Font Awesome plugin's REST API route (defined in class-fontawesome-api-controller.php) uses the following to authenticate calls to its API endpoint

return current_user_can( 'manage_options' ) || current_user_can( 'edit_posts' );

While this allows admins and post editor/authors to access the FA menu in Gutenberg when authoring site content, it has some unfortunate restrictions. To illustrate, here is my scenario:

A WordPress site I am working on has a number of custom content types (events, news stories, magazine issues) and corresponding custom user roles for each custom content type (so we have users who can only edit event posts, or only edit news story posts, e.g.). These custom content type specific authors are not admins, so none of them have the manage_options capability. Moreover, since each custom role is siloed off into editing just content of a specific type (i.e. not posts), they do not have the edit_posts capability either.

For cases like these, it would be useful to be able to specify additional capabilities that could authenticate API calls. As it stands, it looks like manage_options and edit_posts are hard-coded.

Is there a way to override this authentication logic? If not, do you think this would be a good feature to add?

@brachypelma brachypelma changed the title Allow users to select which user permissions are necessary to enable API calls Allow developers to select which user permissions are necessary to enable API calls Mar 20, 2023
@brachypelma brachypelma changed the title Allow developers to select which user permissions are necessary to enable API calls Allow developers to select which user permissions are necessary to authenticate API calls Mar 20, 2023
@mlwilkerson mlwilkerson linked a pull request Jul 11, 2023 that will close this issue
@mlwilkerson
Copy link
Member

Hi @brachypelma, I think that's a fine idea. I propose PR #203 to resolve it. Would that work for you?

Here's an example of how it might be used in a functions.php

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 a pull request may close this issue.

2 participants