-
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
Post Actions: Use entity details for capability checks #63423
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
const { getPostType, canUser } = select( coreStore ); | ||
const resource = getPostType( postType )?.rest_base || ''; | ||
return { | ||
userCanCreatePost: canUser( 'create', resource ), | ||
}; |
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.
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.
So this is a 6.6 bug?
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.
Yes, but it shouldn't affect users. It just makes an extra request.
First, it will call canUser( 'create', '' )
, and then when the post type object is resolved, it will call it correctly.
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.
Ah 👍
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.
Duplicate action is also not included in the core, it is in the plugin only for now, so it should not have an impact on 6.6.
Size Change: -24 B (0%) Total Size: 1.75 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.
Works well and the changes look good, thank you for these updates 👍
Thank you, @jorgefilipecosta! |
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: ellatrix <ellatrix@git.wordpress.org> Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
registry | ||
.select( coreStore ) | ||
.canUser( capability, resource, item.id ) | ||
registry.select( coreStore ).canUser( capability, { |
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.
There's something I don't understand here. how does this value change when it gets resolved. There's nothing triggering a re-render when the value of this selector changes and isEligible
is not an event callback it's something that is called when rendering.
I'm sure we have a hack elsewhere that "hides" the bug, but this is not great.
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.
The original PR (#62589) might have more details, but I agree that this feels super "hacky."
What?
This is a follow-up to #63322.
PR updates user capability checks for post actions to use the updated
canUser
selector.Note: I decided to do this separately from #63415 since
canUser
checks are somewhat convoluted here.Why?
The code should always use the new method when working with entity and user capabilities.
Testing Instructions
Confirm that post actions work as before in post and site editors.
Testing Instructions for Keyboard
Same.
Screenshots or screencast