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

Top Posts: allow one to customize avatar image options w/ filter #13117

Merged
merged 1 commit into from
Jul 29, 2019

Conversation

jeherve
Copy link
Member

@jeherve jeherve commented Jul 23, 2019

Changes proposed in this Pull Request:

The jetpack_top_posts_widget_image_options filter allows third-parties to specify custom image options, including the fallback_to_avatars parameter. However we currently do not use the value that comes from the filter when we actually fetch the image. That fixes it.

Testing instructions:

  • Create a new post without any image, and make sure it appears as one of the most visited posts in the Top Posts widget you add to your sidebar.
  • By default, the post should show the author's Gravatar.
  • Now add the following code snippet to your site:
function jeherve_custom_top_posts_images( $get_image_options ) {
        $get_image_options['fallback_to_avatars'] = false;
  
        return $get_image_options;
}
add_filter( 'jetpack_top_posts_widget_image_options', 'jeherve_custom_top_posts_images' );
  • The Gravatar should disappear.

Proposed changelog entry for your changes:

  • Top Posts: allow one to customize avatar image options with a filter.

The jetpack_top_posts_widget_image_options filter allows third-parties to specify custom image options, including the fallback_to_avatars parameter. However we currently do not use the value that comes from the filter when we actually fetch the image. That fixes it.
@jeherve jeherve added [Type] Bug When a feature is broken and / or not performing as intended [Feature] Extra Sidebar Widgets [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Pri] Low labels Jul 23, 2019
@jeherve jeherve added this to the 7.6 milestone Jul 23, 2019
@jeherve jeherve requested a review from a team July 23, 2019 16:55
@jeherve jeherve self-assigned this Jul 23, 2019
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello jeherve! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D30721-code before merging this PR. Thank you!

@jetpackbot
Copy link

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: August 6, 2019.
Scheduled code freeze: July 30, 2019

Generated by 🚫 dangerJS against 72d66bb

Copy link
Contributor

@brbrr brbrr left a comment

Choose a reason for hiding this comment

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

For some reason, I can not make gravatar image to disappear when using Image List or Image Grid display options. Text List option does not display images by default. Maybe am I doing something wrong?

I tried adding jeherve_custom_top_posts_images filter via Snippets plugin and into mu-plugin directly.

Copy link
Contributor

@brbrr brbrr left a comment

Choose a reason for hiding this comment

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

I made it work with JN site. unfortunately, it seems it does not work as advertised:

  • I can see a bunch of PHP Warning: Illegal string offset 'src' in /srv/users/userf429d970/apps/userf429d970/public/wp-content/plugins/jetpack-dev/modules/widgets/top-posts.php on line 372
  • widget code tries to render an image since it follows the grid / image formatting, but since image is null - it renders broken image icon.

I think we should render a text-only formatting in this case

@jeherve
Copy link
Member Author

jeherve commented Jul 25, 2019

@brbrr Yes, that is one of the reasons we have that fallback in the first place.

If someone gets rid of that fallback, I think it's reasonable to expect that they would have another fallback in place instead, such as a function hooked into jetpack_images_get_images as explained here:
https://developer.jetpack.com/hooks/jetpack_images_get_images/

I think we can add a better handling of errors when no image can be found, but I think that belongs in a different PR.

Copy link
Contributor

@brbrr brbrr left a comment

Choose a reason for hiding this comment

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

Make sense. LGTM!

@brbrr brbrr added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. labels Jul 25, 2019
@jeherve jeherve merged commit f6c80e9 into master Jul 29, 2019
@jeherve jeherve deleted the fix/top-posts-filter-image-options branch July 29, 2019 08:24
@matticbot matticbot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Jul 29, 2019
jeherve added a commit that referenced this pull request Jul 29, 2019
jeherve added a commit that referenced this pull request Jul 30, 2019
* Add initial changelog / testing list changes for 7.6

* Update stable tag to 7.5.3

* changelog: add #12957

* Changelog: add #12932

* Changelog: add #12867

* Changelog: add #12823

* changelog: add #12969

* changelog: add #13012

* changelog: add #12974

* Changelog: add #13059

* Changelog: add #13079

* Changelog: add #12924

* changelog: add #12954

* Changelog: add #12959

* Changelog: add #12977

* Changelog: add #12830

* Changelog: add #12926

* Changelog: add #12958

* Changelog: add #12999

* Changelog: add #13077

* Changelog: add #13083

* Changelog: add #13087

* Changelog: add #13110

* Changelog: add #13116

* Changelog: add #13117

* Changelog: add #12821

* Changelog: add #13120

* changelog: add #13139

* Changelog: add #13143

* Changelog: add #13147

* Testing list: add section about sync
jeherve added a commit that referenced this pull request Jul 30, 2019
* Add initial changelog / testing list changes for 7.6

* Update stable tag to 7.5.3

* changelog: add #12957

* Changelog: add #12932

* Changelog: add #12867

* Changelog: add #12823

* changelog: add #12969

* changelog: add #13012

* changelog: add #12974

* Changelog: add #13059

* Changelog: add #13079

* Changelog: add #12924

* changelog: add #12954

* Changelog: add #12959

* Changelog: add #12977

* Changelog: add #12830

* Changelog: add #12926

* Changelog: add #12958

* Changelog: add #12999

* Changelog: add #13077

* Changelog: add #13083

* Changelog: add #13087

* Changelog: add #13110

* Changelog: add #13116

* Changelog: add #13117

* Changelog: add #12821

* Changelog: add #13120

* changelog: add #13139

* Changelog: add #13143

* Changelog: add #13147

* Testing list: add section about sync
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extra Sidebar Widgets [Pri] Low Touches WP.com Files [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants