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

current_user_can() 'administrator' vs 'manage_options' #327

Closed
apermo opened this issue Jun 15, 2024 · 1 comment · Fixed by #328
Closed

current_user_can() 'administrator' vs 'manage_options' #327

apermo opened this issue Jun 15, 2024 · 1 comment · Fixed by #328

Comments

@apermo
Copy link
Contributor

apermo commented Jun 15, 2024

Hey Alex,

return self::is_main_user() || current_user_can( 'administrator' );

I wonder why you chose to use current_user_can( 'administrator' ), this will only work if the user role is named administrator. In case you create custom roles or rename the given ones, the function will no longer return true. Without testing it, I expect it to already fail for the super_administrator role in a network.

If you have a very specific reason for testing for 'administrator' I propose to add a filter, to be able to customize the capability.

Or replace 'administrator' with 'manage_options'.

I'll be happy to provide a PR, if you just give me your preferred solution.

For reference:

The role name capabilities are set in these two function with the following line.

@akirk
Copy link
Owner

akirk commented Jun 15, 2024

Actually, more generally, I use edit_private_posts as the required role:
https://github.com/akirk/friends/blob/main/includes/class-friends.php#L25

This particular function has_required_privileges() is used in several places where it is about someone that you dedicate as the main user. This is derived from the idea that currently it is somewhat assumed that one person uses the blog (although this might change at some point, see #285) and you can select that user in the friend settings. The Administrator here is just a fallback that I am not sure is actually ever reached.

The main user is selected out of all users who have the edit_private_posts permission only if it has not been selected:

Screenshot 2024-06-15 at 10 09 59

All that said, happy to change this to use manage_options if you'd like to submit a pull request!

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