Repository navigation
Description
Description
While working on the PR feedback here, I re-verify the PR changes for low cap users and found the console error that was unrelated to the PR, but still was present. On further debug found the below cause,
Every time a user without manage_options opens the post editor, the console logs a failed request:
GET http://example.com/wp-json/wp/v2/settings?_locale=user 403 (Forbidden)
at preloadResolutions (packages/edit-post/src/index.js:197)
at initializeEditor (packages/edit-post/src/index.js:131)
Nothing visibly breaks - the rejection is swallowed by the catch {} at the end of preloadResolutions() - but every Editor, Author and Contributor sees this 403 console error.
Step-by-step reproduction instructions
- Add a user with the Author role (Editor or Contributor reproduce it equally).
- Log in as that user and open Posts → Add New.
- Open the browser console, or the Network tab filtered on
settings. - A
GET /wp-json/wp/v2/settingsreturns 403.
Administrators never see it, which is why it went unnoticed.
Console Error Details:
index.ts:86 GET http://localhost:8188/wp-json/wp/v2/settings?_locale=user 403 (Forbidden) (anonymous) @ index.ts:86 (anonymous) @ fetch-all-middleware.ts:77 (anonymous) @ index.ts:178 (anonymous) @ http-v1.ts:39 (anonymous) @ index.ts:178 (anonymous) @ namespace-endpoint.ts:26 (anonymous) @ index.ts:178 (anonymous) @ user-locale.ts:19 (anonymous) @ index.ts:178 (anonymous) @ root-url.ts:37 (anonymous) @ namespace-endpoint.ts:26 (anonymous) @ root-url.ts:11 (anonymous) @ index.ts:178 (anonymous) @ nonce.ts:28 (anonymous) @ index.ts:178 (anonymous) @ media-upload.ts:28 (anonymous) @ index.ts:178 (anonymous) @ preloading.ts:63 (anonymous) @ index.ts:178 (anonymous) @ index.ts:183 (anonymous) @ resolvers.js:127 await in (anonymous) (anonymous) @ thunk-middleware.ts:6 (anonymous) @ index.ts:27 (anonymous) @ promise-middleware.ts:17 (anonymous) @ resolvers-cache-middleware.ts:53 (anonymous) @ index.ts:806 setTimeout fulfillSelector @ index.ts:798 (anonymous) @ index.ts:821 (anonymous) @ index.ts:672 (anonymous) @ index.ts:675 (anonymous) @ index.ts:644 preloadResolutions @ index.js:197 initializeEditor @ index.js:131 (anonymous) @ wp-edit-post-js-after:5
Why it happens
wp-admin/edit-form-blocks.phpserver-preloads/wp/v2/settingsfor the post editor.rest_preload_api_request()caches only 200 responses (if ( 200 === $response->status )).WP_REST_Settings_Controller::get_item_permissions_check()returnscurrent_user_can( 'manage_options' ), so for these roles the preload is a 403 and is therefore never cached.preloadResolutions()resolvesroot/siteunconditionally, so with an empty preload cache the request escapes to the network.
For an administrator step 3 yields a 200, the preload cache is populated, and the resolution is served locally without any network request - hence the role-dependent behaviour.
The capability check is already right there, one line below the fetch it should be guarding:
// packages/edit-post/src/index.js
core.getEntityRecord( 'root', 'site' ), // line 197
core.canUser( 'read', { kind: 'root', name: 'site' } ), // line 198Both sit in the same Promise.all, so the gate cannot be applied where it stands.
Regressed in
#78508, which added preloadResolutions(). Before that commit packages/edit-post/src/index.js performed no resolutions at boot, so root/site was only ever fetched by callers that gate it - for example useBlockEditorSettings:
It was added in GB version 23.3.0 and it's present from that version.
const siteSettings = canUser( 'read', { kind: 'root', name: 'site' } )
? getEntityRecord( 'root', 'site' )
: undefined;Suggested fix
preloadResolutions() already has a second stage — "Phase 2: read derived data out of state" — that runs after the first Promise.all settles. Moving the root/site preload there, conditional on the resolved canUser( 'read', … ) value, fixes it in the shape the function already uses:
// Phase 1 keeps the capability check.
core.canUser( 'read', { kind: 'root', name: 'site' } ),
// Phase 2, once it has resolved.
if ( coreSelect.canUser( 'read', { kind: 'root', name: 'site' } ) ) {
tasks.push( core.getEntityRecord( 'root', 'site' ) );
}That costs low-capability users nothing and leaves administrators unaffected, since their settings response is already in the preload cache.
Environment info
- WordPress latest.
- Gutenberg trunk
Please confirm that you have searched existing issues in the repo.
- Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
- Yes
Please confirm which theme type you used for testing.
- Block
- Classic
- Hybrid (e.g. classic with theme.json)
- Not sure
Cc: @ellatrix for review as original author of the PR which shows regression.
Note: I have used claude code to draft the issue description. Have reviewed it myself before posting.
Activity
[-]Post Editor: 403 on /wp/v2/settings at boot for users without manage_options[/-][+]Post Editor: 403 on /wp/v2/settings at boot for users without manage_options cap[/+]