-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Site Editor: Check user permissions before rendering export menu item #69971
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
Conversation
'targetHints' => array( | ||
'allow' => current_user_can( 'export' ) ? array( 'GET' ) : array(), | ||
), |
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.
Ideally, this should use the same method as self
links, but I went with KISS for now 😄 Maybe in the future we can introduce a flag to opt-in targetHints
generation for any rel link.
@TimothyBJacobs, what do you think?
gutenberg/lib/compat/wordpress-6.7/class-gutenberg-rest-server.php
Lines 86 to 90 in accde16
// Prefer targetHints that were specifically designated by the developer. | |
if ( isset( $attributes['targetHints']['allow'] ) ) { | |
$data[ $rel ][] = $attributes; | |
continue; | |
} |
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 Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @jonnynews. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. 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 targetHints = | ||
select( coreStore ).getCurrentTheme()?._links?.[ | ||
'wp:export-theme' | ||
]?.[ 0 ]?.targetHints ?? {}; | ||
|
||
return !! targetHints.allow?.includes( 'GET' ); |
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.
Dropped is_block_theme
theme condition check; this link is only available for block themes. See PHP response filter.
Size Change: +41 B (0%) Total Size: 1.85 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.
LGTM.
Thank you, @spacedmonkey! |
c7b80b4
to
4f1ec55
Compare
Flaky tests detected in 4f1ec55. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/14831730488
|
…WordPress#69971) Co-authored-by: Mamaduka <[email protected]> Co-authored-by: spacedmonkey <[email protected]> Co-authored-by: t-hamano <[email protected]> Co-authored-by: unsalkorkmaz <[email protected]>
What?
Closes #46661.
Supersedes #69107.
Related https://core.trac.wordpress.org/ticket/57379.
PR adds a user capability check for the Export feature in the Site Editor. Users without export capabilities will not be able to use this feature.
How
Add a new link relation for the export endpoint and provide the required data for capability checks via
targetHints
. Suggested initially by @TimothyBJacobs - https://core.trac.wordpress.org/ticket/57379#comment:10.Testing Instructions
export
cap for Administrators -wp cap remove administrator export
.wp role reset administrator
Testing Instructions for Keyboard
Same.
Screenshots or screencast