Skip to content

Commit db58031

Browse files
ntsekourasMamadukadavidsword
authored andcommitted
Fields: Fix AuthorView for users who can't edit users (WordPress#83498)
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org> Co-authored-by: davidsword <davidsword@git.wordpress.org>
1 parent be59398 commit db58031

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎packages/fields/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Bug Fixes
6+
7+
- `AuthorView`: Fetch the author through the users list in the `view` context, so users who can't edit other users still see the author's name and avatar, including for authors without published posts. ([#83498](https://github.com/WordPress/gutenberg/pull/83498))
8+
59
## 0.48.0 (2026-09-23)
610

711
### Enhancements

‎packages/fields/src/fields/author/author-view.tsx‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
} from '@wordpress/components';
99
import { useSelect } from '@wordpress/data';
1010
import { store as coreStore } from '@wordpress/core-data';
11+
import type { User } from '@wordpress/core-data';
1112
import type { BasePostWithEmbeddedAuthor } from '../../types';
1213

1314
function AuthorView( { item }: { item: BasePostWithEmbeddedAuthor } ) {
@@ -24,12 +25,18 @@ function AuthorView( { item }: { item: BasePostWithEmbeddedAuthor } ) {
2425
if ( ! shouldFetch ) {
2526
return null;
2627
}
27-
const { getEntityRecord } = select( coreStore );
28-
// This doesn't make extra REST requests because the records are
29-
// already in the store from the field's getElements function.
30-
return authorId
31-
? getEntityRecord( 'root', 'user', authorId )
32-
: null;
28+
const { getEntityRecords } = select( coreStore );
29+
// Query the collection with `who: 'authors'` instead of calling
30+
// `getEntityRecord`, because the single user endpoint denies
31+
// access to authors without published posts for users who can't
32+
// list users. See https://core.trac.wordpress.org/ticket/56429.
33+
return (
34+
getEntityRecords< User >( 'root', 'user', {
35+
include: [ authorId ],
36+
who: 'authors',
37+
context: 'view',
38+
} )?.[ 0 ] ?? null
39+
);
3340
},
3441
[ authorId, shouldFetch ]
3542
);

0 commit comments

Comments
 (0)