-
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 Author Block: Show avatar placeholder and size control when no context #47211
Conversation
Size Change: +67 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
Flaky tests detected in ec96ff7. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3937359789
|
const DEFAULT_AVATAR_SIZES = [ 24, 48, 96 ].map( ( size ) => ( { | ||
value: size, | ||
label: `${ size } x ${ size }`, | ||
} ) ); |
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 default value is hard-coded, but the avatar size retrieved by the REST API has a filter hook.
Therefore, if the consumer has changed the size variation on the hook, it may not match the default variation. However, there does not appear to be an endpoint to directly retrieve the result of the rest_get_avatar_sizes() function.
Perhaps we could solve this by making the size resizable, like a regular avatar block.
If you have a better way to do this, please let me know.
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.
I think that the more similar the blocks are, the easier it will be for the users.
🤔 I believe the intention was to switch to using the avatar block inside the post author block. |
I found in #35596 that the Post Author block is scheduled to be split. In that case, would the current Post Author Block be deprecated? Either way, this block is also used in the Twenty Twenty Three theme, so I think a fix is in order. |
} ) ); | ||
|
||
const DEFAULT_AVATAR_URL = | ||
'https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mp&f=y'; |
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.
Is this only used as a fallback?
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.
For example, suppose you inserted this block in Single template. On the front end, the author image would be displayed based on the actual articles. However, in Single template, the actual author image URL cannot be retrieved because the post context doesn't exist.
In such cases, avatars should be displayed as placeholders.
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.
But this remote url will not always be available, for example on closed networks.
I wonder if there were any prior discussions about it during development of the other avatar blocks.
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.
I examined the other blocks and found that the avatarUrl
was being retrieved by __experimentalDiscussionSettings(), so I refactored it in 4b5988e. This URL will be http://1.gravatar.com/avatar/?s=96&d=mm&f=y&r=g
, etc.
I have looked at #38072 and there does not appear to be any discussion on closed networks.
However, since the block pattern is also read from the remote network, that might not need to be taken into account.
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.
Thank you for tracking this down 👍
ec96ff7
to
4b5988e
Compare
The PR works well for me as is. |
Update: I've submitted #55352 to deprecate this block, so I'd like to close this PR. |
Fixes #35693
Fixes #47169
What?
This PR fixes the following two problems when there is no post context in the editor (i.e., when the author ID cannot be found):
Why?
In the current implementation, the avatar size variation relies on the existence of the author ID. The variations are generated from the
avatar_urls
of the information retrieved bygetUser()
.This implementation works as expected as long as it is within the post editor or query loop. However, if this block is placed outside the query context (e.g., in a single template), the avatar size variations would be an empty array and the avatar size dropdown would not render, since the author ID is not present.
As for avatar images, there is no fallback for the absence of the avatar URL, so even if "Show avatar" option is enabled, the avatar image will not be displayed.
I think even when there is no avatar information related with a post, the size should be able to changed and a placeholder image should be displayed.
How?
When no author information is available, the default size variation is used.
As for the avatar placeholder, the default mystery-person is displayed according to Gravatar's document. The request parameter that determines the size (
s=
) includes the selected avatar size.Testing Instructions
In the following context, confirm that the author's avatar or placeholder image and the avatar size control are displayed.