Skip to content
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

Return immediately from Avatar block's render_callback if $comment is null #40835

Merged
merged 1 commit into from
May 5, 2022

Conversation

michalczaplinski
Copy link
Contributor

@michalczaplinski michalczaplinski commented May 5, 2022

What?

In the Avatar block's render_callback, return '' immediately if $comment is null.

Why?

If the comment is null, accessing $comment->$comment_author will fail.

In theory, the comment should never be null if $block->context['commentId'] is set, but I was able to accidentally get my machine into a state where it did occur.

Testing Instructions

I don't quite know how to reproduce it anymore. On my local machine, using twenty twentytwo, I got this error on the frontend:

Notice: Trying to get property 'comment_author' of non-object in /var/www/html/wp-content/plugins/gutenberg/build/block-library/blocks/avatar.php on line 109

However, this error went away after I've restarted my wp-env environment.

@michalczaplinski michalczaplinski changed the title Return immediately if comment is null in avatar block Return immediately from Avatar block's render_callback if $comment is null May 5, 2022
@michalczaplinski michalczaplinski added [Package] Block library /packages/block-library [Block] Avatar Affects the Avatar Block labels May 5, 2022
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you for the fix 👍🏻

@gziolo gziolo added the [Type] Bug An existing feature does not function as intended label May 5, 2022
@gziolo gziolo merged commit e984e85 into trunk May 5, 2022
@gziolo gziolo deleted the fix/handle-empty-comment-author branch May 5, 2022 08:02
@github-actions github-actions bot added this to the Gutenberg 13.3 milestone May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Avatar Affects the Avatar Block [Package] Block library /packages/block-library [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants