Try adding alt text when rendering local avatars #127
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the Change
As mentioned in #126, it doesn't appear the alt text saved with an attachment is ever used when rendering a local avatar. If someone passes in some custom alt text (for instance, using the 4th argument of
get_avatar
) that is then used as the alt text for the image. But if that argument isn't passed in but the attachment we are rendering has alt text assigned to it, we should use that for the alt text argument.This PR fixes that by adding a check that runs if a local avatar is found AND no custom alt text has been passed in. It then pulls the alt text from the underlying attachment object which will be stored in post meta (if it exists, otherwise just an empty string).
I also added a new method used to get the user ID, to avoid having duplicate code between the existing
get_simple_local_avatar_url
method and the newget_simple_local_avatar_alt
method.Closes #126
Alternate Designs
Right now we default to using the alt text that is passed in and then fallback to the alt text assigned to an image. I think that's the right approach but we could flip those, so the alt text saved with an image would take precedence.
Possible Drawbacks
None
Verification Process
get_avatar
and pass in the 4th argument for the alt textChecklist:
Changelog Entry
Credits
Props @dkotter, @pixelloop