-
Notifications
You must be signed in to change notification settings - Fork 43
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
Fix: Adapt to More Current Avatar Filters #40
Conversation
In fact, we only need to filter the url of the avatar, not the avatar img element. So instead of hook to `get_avatar` filter and override the `get_avatar` function, we hook to `pre_get_avatar_data` filter to manipulate the avatar url and let the core handle the reset. This reduce duplication code and effort to follow core changes.
Pinging @dkotter and @ryanwelcher on this to see if they can review this PR. |
@heyjones - I wanted to check and see if you'd mind giving this PR a review in relation to your PR to see if this approach might also work for your use? |
Sorry for the delay... it maintains the class args I'm passing through the theme! @dinhtungdu I'd recommend possibly running
Aside from that, @jeffpaul as long as you don't see this causing any issues with backwards capability I think it's a really clever solution! |
I really like this method better than continuing support via a pluggable function. |
This is what I was looking for! Thanks 👍 |
Is there an expected timeline for when this PR will be released? |
@MikeNGarrett one item I'd like to see is some test coverage, be that unit tests and/or WP Acceptance tests, before pushing forward with another release. If someone is able to add a PR to increase (heck, add) test coverage then that'd be wonderful. |
simple-local-avatars.php
Outdated
public function get_default_avatar_url( $size ) { | ||
if ( empty( $default ) ) { | ||
$avatar_default = get_option( 'avatar_default' ); | ||
if ( empty( $avatar_default ) ) |
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 know this was just copied from the current codebase but we should make sure any if statements here have brackets { }
at the end of the lines.
simple-local-avatars.php
Outdated
|
||
$host = is_ssl() ? 'https://secure.gravatar.com' : 'http://0.gravatar.com'; | ||
|
||
if ( 'mystery' == $default ) |
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.
Same as above
@dkotter Currently we have a lot of coding style issues, I think it's better to address them in a separated PR after this is merged, does it work for you? |
any update on this? |
@Log1x we have a couple other plugins scheduled for releases ahead of Simple Local Avatars. Getting this PR through review and into a release is on our todo list, just not in the immediate future. If you have an urgent or important need for this specific change, then please reach out to me directly and we discuss... thanks! |
So while using Simple Local Avatars on a project recently, I just needed the image url rather than the whole image tag. I assumed that since I feel that if we update the URL at that stage, we may not be required to override the pluggable |
@dinhtungdu Thank you, I'm seeing the right URL as well if I use the /**
* Filter avatar data early to add avatar url if needed. This filter hooks
* before Gravatar setup to prevent wasted requests.
*
* @since 2.2.0
*
* @param array $args Arguments passed to get_avatar_data(), after processing.
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
* user email, WP_User object, WP_Post object, or WP_Comment object.
*/
public function get_avatar_data( $args, $id_or_email ) {
$simple_local_avatar_url = $this->get_simple_local_avatar_url( $id_or_email, $args['size'] );
if( $simple_local_avatar_url ) {
$args['url'] = $simple_local_avatar_url;
$args['found_avatar'] = true;
}
// Local only mode
if( ! $simple_local_avatar_url && ! empty( $this->options['only'] ) ) {
$args['url'] = $this->get_default_avatar_url( $args['size'] );
}
return $args;
} |
@sumnercreations Can you please test the latest commit and see if your issue is resolved? https://github.com/10up/simple-local-avatars/tree/fix/39 |
After internal discussion and review, it was agreed this was ready for merge so I'm going to get this in and start looking towards what else remains in a 2.2.0 release. |
Description of the Change
pre_get_avatar_data
filter.get_avatar
function that overrides the core one.$args
parameter toget_simple_local_avatar
function.Remove~> added back for backward compat.Simple_Local_Avatars::get_avatar
method.Simple_Local_Avatars::get_avatar_data()
method.Simple_Local_Avatars::get_simple_local_avatar_url()
method.Simple_Local_Avatars::get_default_avatar_url()
method.Benefits
In fact, we only need to filter the url of the avatar, not the avatar
img element. So instead of hooking to
get_avatar
filter and overridingthe
get_avatar
function, we hook topre_get_avatar_data
filter tomanipulate the avatar url and let the core handle the rest. This reduces
duplication code and minimizes effort to follow core changes.
Possible Drawbacks
We need to care about/check for backward compatibility issues.
Verification Process
Check if avatars display correctly when
Local Avatars Only
is enabled/disabled.Checklist:
Applicable Issues
Closes #39
Relates #19