-
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
Template Part: Add check if create action should be allowed #63623
Conversation
Size Change: +72 B (0%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
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. |
Thanks, @t-hamano! I'll try to test this properly tomorrow. Re-caps issue: The "templates" endpoint is probably doing |
canCreateTemplatePart: canUser( 'create', { | ||
kind: 'postType', | ||
name: 'wp_template_part', | ||
} ), |
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.
At this point, it seems like you can't modify the user caps required to create a template part, and anyone who can access this page will have edit_theme_options
capabilities. This makes the current check redundant.
Templates endpoint permission check:
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 fix here makes sense, and since we're doing similar checks in other places, like the pattern list view, I think it's good to land.
I left a general note regarding template and template part capabilities, which probably should be improved in the core.
@Mamaduka Thanks for the review!
Thanks for looking into this. As suggested in #61637, I think it's expected that in the future the site editor will be accessible to users without the |
Fixes #58344
What?
This PR allows the creation of new template parts in a template part block only if the following conditions are met:
Why?
Creating template parts is not the intended behavior if the theme is not a block theme or if the user does not have the permissions.
How?
I added a check similar to the Add New Pattern button dropdown.
Another approach would be to not allow the insertion of template part blocks if the current theme is not a block theme, but I did allow the insertion of template part blocks because there might be edge cases where users want to nest template parts.
Testing Instructions
http://localhost:8889/wp-admin
and activate theEmptyhybrid
theme.🤔 About User Capabilities
Regarding user capabilities, I've come across an issue where we might not be able to disable the capability to create template parts.
I removed the
create_posts
capability via the code below to test this PR:But strangely,
canUser
always returnstrue
only for template parts:This issue may need to be investigated separately.