-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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 Template: Don't fetch settings and templates for non-admin users #42845
Conversation
const siteSettings = canUser( 'read', 'settings' ) | ||
? getEntityRecord( 'root', 'site' ) | ||
: undefined; |
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 settings cannot be marked with a view or public context. Related Core PR: WordPress/wordpress-develop#2985
fetchedTemplates: canCreateTemplates | ||
? getEntityRecords( 'postType', 'wp_template', { | ||
post_type: select( editorStore ).getCurrentPostType(), | ||
per_page: -1, | ||
} ) | ||
: undefined, |
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.
Technically we only want to fetch templates when a user has caps to create them to keep the options
array in sync. See #32744
Size Change: +26 B (0%) Total Size: 1.26 MB
ℹ️ View Unchanged
|
@Mamaduka How do I do this? I logged in as Editor but I don't see the option |
@getdave, what theme are you using? Try with TT1 or TT2. |
Is it such a problem to make the request and receive a 403 error? It means that we're making just one request (a |
It's not a problem to make 403 requests, but if we already know it resolves in one, I think it's better to avoid it.
The P.S. 403 errors usually get reported as bugs. See #29845. |
@noisysocks, should we merge this? |
If the cache is hot and doing this avoids a request then that sounds good to me 👍 |
What?
A follow-up to #42705, also see #42413.
Why?
The editor should check permission before making requests when data isn't available for everyone.
How?
canUser( 'read', 'settings' )
check before fetching site settings.canCreateTemplates
before fetching the templates.Testing Instructions
Screenshots or screencast