Widgets: add missing internet-defense-league widget#7030
Conversation
jeherve
left a comment
There was a problem hiding this comment.
I left a few comments of things that could be fixed.
| function __construct() { | ||
| parent::__construct( | ||
| 'internet_defense_league_widget', | ||
| apply_filters( 'jetpack_widget_name_widget', esc_html__( 'Internet Defense League', 'jetpack' ) ), |
There was a problem hiding this comment.
jetpack_widget_name is the right filter name here, and you'll need to add a docblock in front of that filter. Something like /** This filter is documented in modules/widgets/facebook-likebox.php */
There was a problem hiding this comment.
I'm curious, why not link to a doc page or simply copy the doc here?
/**
* Filter the name of a widget included in the Extra Sidebar Widgets module.
*
* @module widgets
*
* @since 2.1.2
*
* @param string $widget_name Widget title.
*/
There was a problem hiding this comment.
@gwwar We only include the full docblock once, so the parser doesn't create multiple entries for the same hook. That's how WordPress Core works as well.
| 'internet_defense_league_widget', | ||
| apply_filters( 'jetpack_widget_name_widget', esc_html__( 'Internet Defense League', 'jetpack' ) ), | ||
| array( | ||
| 'description' => __( 'Show your support for the Internet Defense League.', 'internetdefenseleague' ), |
There was a problem hiding this comment.
You'll need to use the jetpack textdomain everywhere in that file, so strings can be picked up and translated.
There was a problem hiding this comment.
Does this look about right in d340db8 ?
| // When enabling campaigns other than 'none' or empty, change $no_current to false above. | ||
| $this->campaigns = array( | ||
| '' => __( 'All current and future campaigns', 'internetdefenseleague' ), | ||
| // 'nsa' => __( 'NSA Protest on July 4th, 2013', 'internetdefenseleague' ), |
There was a problem hiding this comment.
Since this doesn't apply anymore, you can remove it I think.
There was a problem hiding this comment.
Oh good catch, it looks like we can hide the Don't display a badge (just the campaign) option as well.
| array( | ||
| 'description' => __( 'Show your support for the Internet Defense League.', 'internetdefenseleague' ), | ||
| ) | ||
| ); |
There was a problem hiding this comment.
I would suggest enabling Customizer's Selective Refresh, as mentioned here:
https://github.com/Automattic/jetpack/blob/master/docs/coding-guidelines.md#widgets
There was a problem hiding this comment.
The widget is very simple, so it appears that adding the flag is enough in 7b37c44. Let me know if I missed anything though.
| echo $args['before_widget']; | ||
| echo '<p><a href="https://internetdefenseleague.org/"><img src="' . esc_url( 'https://internetdefenseleague.org/images/badges/final/' . $instance['badge'] . '.png' ) . '" alt="Member of The Internet Defense League" style="max-width: 100%; height: auto;" /></a></p>'; | ||
| echo $args['after_widget']; | ||
| do_action( 'jetpack_stats_extra', 'widget_view', 'internet_defense_league' ); |
There was a problem hiding this comment.
Could you add a docblock before the action? /** This action is already documented in modules/widgets/gravatar-profile.php */ should do.
| $instance['badge'] = $this->defaults['badge']; | ||
| } | ||
| echo $args['before_widget']; | ||
| echo '<p><a href="https://internetdefenseleague.org/"><img src="' . esc_url( 'https://internetdefenseleague.org/images/badges/final/' . $instance['badge'] . '.png' ) . '" alt="Member of The Internet Defense League" style="max-width: 100%; height: auto;" /></a></p>'; |
There was a problem hiding this comment.
How about serving that image with Photon, thanks to jetpack_photon_url()?
There was a problem hiding this comment.
| $this->campaign = $instance['campaign']; | ||
| $this->variant = $instance['variant']; | ||
| add_action( 'wp_footer', array( $this, 'footer_script' ) ); | ||
| do_action( 'jetpack_stats_extra', 'widget_view', 'internet_defense_league' ); |
There was a problem hiding this comment.
Instead of adding the same action twice, how about placing it at the end of the widget output, so it's always triggered when the widget is in use, and always triggered only once?
| } | ||
|
|
||
| public function footer_script() { | ||
| if ( ! isset( $this->campaigns[ $this->campaign ] ) ) |
There was a problem hiding this comment.
You'll need to add opening and closing brackets here, as per the WP coding standards:
https://make.wordpress.org/core/handbook/best-practices/coding-standards/php/#brace-style
| if ( ! isset( $this->campaigns[ $this->campaign ] ) ) | ||
| $this->campaign = $this->defaults['campaign']; | ||
|
|
||
| if ( ! isset( $this->variants[ $this->variant ] ) ) |
|
|
||
| **************************************************************************/ | ||
|
|
||
| class Internet_Defense_League_Widget extends WP_Widget { |
There was a problem hiding this comment.
Maybe we could prefix it with Jetpack_ to avoid any potential conflicts with other plugins or themes that may use the same class name?
|
Thanks for the detailed review @jeherve 👍 This is ready for another look when folks have time. |
| parent::__construct( | ||
| 'internet_defense_league_widget', | ||
| /** This filter is documented in modules/widgets/facebook-likebox.php */ | ||
| apply_filters( 'jetpack_widget_name_widget', esc_html__( 'Internet Defense League', 'jetpack' ) ), |
There was a problem hiding this comment.
the correct filter name is jetpack_widget_name
| ); | ||
|
|
||
| if ( $this->no_current === false ) { | ||
| $this->badges[ 'none' ] = __( 'Don\'t display a badge (just the campaign)', 'jetpack' ); |
There was a problem hiding this comment.
Coding standards say whitespace only for variables in the bracket
|
|
||
| ************************************************************************** | ||
|
|
||
| Plugin Name: Internet Defense League |
There was a problem hiding this comment.
I think we can remove this doc stuff. The format is kinda weird and it's not included in other widgets. Also not a plugin :)
|
Looks great aside from my comments above! |
|
Thanks for the reviews @dereksmart @jeherve! Let me know if I need to tidy anything else |
eliorivero
left a comment
There was a problem hiding this comment.
Thanks for working on this @gwwar! There are some changes that would be great to make before merging.
| } | ||
|
|
||
| function jetpack_internet_defense_league_init() { | ||
| if ( Jetpack::is_active() ) { |
There was a problem hiding this comment.
This widget doesn't require anything from wpcom so it doesn't need a connection. This condition can be removed.
| // Hide first two form fields if no current campaigns. | ||
| if ( false === $this->no_current ) { | ||
| echo '<p><label>'; | ||
| echo __( 'Which Internet Defense League campaign do you want to participate in?', 'jetpack' ) . '<br />'; |
There was a problem hiding this comment.
This and similar instances should use esc_html_e() (or _e() when necessary) instead of echo __()
| $badge_url = esc_url( 'https://internetdefenseleague.org/images/badges/final/' . $instance['badge'] . '.png' ); | ||
| $photon_badge_url = jetpack_photon_url( $badge_url ); | ||
| echo $args['before_widget']; | ||
| echo '<p><a href="https://internetdefenseleague.org/"><img src="' . $photon_badge_url . '" alt="Member of The Internet Defense League" style="max-width: 100%; height: auto;" /></a></p>'; |
There was a problem hiding this comment.
The string Member of The Internet Defense League must be translatable.
| ) | ||
| ); | ||
|
|
||
| // When enabling campaigns other than 'none' or empty, change $no_current to false above. |
There was a problem hiding this comment.
All the code associated to $no_current being false is never used since there's no way for user to change the property, which is always true, so maybe it should be removed.
There was a problem hiding this comment.
I assume this was dev note in case another campaign was to be added, so someone could modify this quickly. If we remove this, we should remove the campaigns array as well since there are no active campaigns to choose from.
| /** This filter is documented in modules/widgets/facebook-likebox.php */ | ||
| apply_filters( 'jetpack_widget_name', esc_html__( 'Internet Defense League', 'jetpack' ) ), | ||
| array( | ||
| 'description' => __( 'Show your support for the Internet Defense League.', 'jetpack' ), |
There was a problem hiding this comment.
We usually use the safer esc_html__() instead of __().
|
@eliorivero updated in f3d2612 |
|
Fantastic! Merging now. |
* Changelog: initial commit for 4.9 release. * Changelog: add #6929 * Changelog: move old changelogs to changelog.txt * Readme: restore deleted release post link. The post is now live. * Changelog: add #6853 * Changelog: add #6856 * Changelog: add #6857 * Changelog: add #6884 * Changelog: add #6885 * Changelog: add #6892 * Changelog: add #6894 * Changelog: add #6898 * Changelog: add #6899 * Changelog: add #6900 * Changelog: add #6909 * Changelog: add #6927 * Changelog: add #6947 * Chagelog: add #6958 * Changelog: add #6961 * Changelog: add #6963 * Changelog: add #6965 * Changelog: add #6986 * Changelog: add #7000 * Changelog: add #7013 * Changelog: add #7015 * Changelog: add #7019 * Changelog: add #7028 * Changelog: add #6998 * Changelog: add #6999 * Changelog: add #7044 * Changelog: add #6881 * Changelog: add #6922 * Changelog: add #6940 * Changelog: add #6962 * Changelog: add #6942 * Changelog: add #6959 * Changelog: add #7018 * Changelog: add #6948 * Changelog: add #6657 * Changelog: add #7030 * Changelog: add #7048 * Changelog: add #7031 * Changelog: add #6990 * Changelog: add #6957 * Changelog: add #7027

This is part of 185-gh-customization
Changes proposed in this Pull Request:
This adds a wpcom widget to Jetpack. This is copied mostly verbatim from wpcom, with some small modifications for stats and the registration of the module.
Testing instructions:
widget_internet_defense_league_widgetwhich might have a shape like