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

Support WP_User objects #193

Merged
merged 4 commits into from
Feb 3, 2023
Merged

Conversation

mattheu
Copy link
Contributor

@mattheu mattheu commented Jan 30, 2023

Description of the Change

It is expected that I can pass WP_User object to get_avatar, as is documented. But this does not work because get_user_id in Simple_Local_Avatars does not handle this case.

Closes #192

How to test the Change

$user = wp_get_current_user();
echo get_avatar( $user );

Changelog Entry

Fixed - Support passing WP_User to get_avatar.

Credits

Props @mattheu

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@mattheu
Copy link
Contributor Author

mattheu commented Jan 30, 2023

I'm not so familiar with WP_Mock, but I've made some changes so that I can mock a WP_User object. Please advise if there is a better way to do this. Thanks.

@mattheu mattheu changed the title Support user objects Support WP_User objects Jan 31, 2023
Copy link
Member

@faisal-alvi faisal-alvi left a comment

Choose a reason for hiding this comment

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

Minor spacing fixes

tests/phpunit/SimpleLocalAvatarsTest.php Outdated Show resolved Hide resolved
tests/phpunit/SimpleLocalAvatarsTest.php Outdated Show resolved Hide resolved
tests/phpunit/SimpleLocalAvatarsTest.php Outdated Show resolved Hide resolved
tests/phpunit/SimpleLocalAvatarsTest.php Outdated Show resolved Hide resolved
@faisal-alvi
Copy link
Member

@mattheu Awesome! thank you for working on this.

✅ Checked the following code and the avatar works well in the PR branch. Can you please just make those small spacing fixes and we will be good to go!

echo '<h1>WORKS</h1>';
$user = wp_get_current_user();
echo get_avatar( $user->ID );

echo '<h1>DOES NOT WORK</h1>';
$user = wp_get_current_user();
echo get_avatar( $user );

in develop:

image

in this PR:

image

Co-authored-by: Faisal Alvi <faisalalvi33@gmail.com>
@mattheu
Copy link
Contributor Author

mattheu commented Feb 2, 2023

Thanks. Suggestions applied.

Copy link
Member

@faisal-alvi faisal-alvi left a comment

Choose a reason for hiding this comment

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

@mattheu thank you for your efforts! 🚀

@faisal-alvi faisal-alvi merged commit b868527 into 10up:develop Feb 3, 2023
@faisal-alvi faisal-alvi added this to the 2.7.4 milestone Feb 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Not working when WP_User passed to get_avatar
2 participants