-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Editor: Extend PostTrashCheck with canUser() check for delete action #23174
Conversation
Size Change: +77 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good. Do you know how we can test this easily? How can I create such user?
const { getPostType, canUser } = select( 'core' ); | ||
const postId = getCurrentPostId(); | ||
const postType = getPostType( getCurrentPostType() ); | ||
const resource = postType?.[ 'rest_base' ] || ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd have avoided this temporary variable and just used postType in the check line 27.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, resource
is used twice in line 27. Or do mean doing this instead?
postId && postType ? canUser( 'delete', postType[ 'rest_base' ], postId ) : false,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, that's exactly what I meant. It's just a very small detail without importance though.
@youknowriad I have extended the description with four WP-CLI commands to create the role and user for testing. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Description
Fixes #23144.
This is a version which doesn't require a new
action-delete
action on the resource.How has this been tested?
read
andedit_posts
capabilitiesFor testing you can use WP-CLI to create a user "author" with the role "author_only_edit" which can only create/edit draft posts.
Screenshots
Types of changes
Bug fix
Checklist: