PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.1
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.1
16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 All 504 releases
← All changes | modules/widgets/internet-defense-league.php +36 -112 12.0.3 → 16.3-a.1 View file →
@@ -1,6 +1,10 @@
1 1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2 2
3 +if ( ! defined( 'ABSPATH' ) ) {
4 + exit( 0 );
5 +}
6 +
3 7 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
4 8
5 9 /**
6 10 * Jetpack_Internet_Defense_League_Widget main class.
@@ -13,40 +17,8 @@
13 17 */
14 18 public $defaults = array();
15 19
16 20 /**
17 - * Selected display variant.
18 - *
19 - * @var string
20 - */
21 - public $variant;
22 - /**
23 - * Display variants.
24 - *
25 - * @var array
26 - */
27 - public $variants = array();
28 -
29 - /**
30 - * Selected campaign.
31 - *
32 - * @var string
33 - */
34 - public $campaign;
35 - /**
36 - * Campaign options.
37 - *
38 - * @var array
39 - */
40 - public $campaigns = array();
41 - /**
42 - * False when enabling campaigns other than 'none' or empty.
43 - *
44 - * @var bool
45 - */
46 - public $no_current = true;
47 -
48 - /**
49 21 * Selected badge to display.
50 22 *
51 23 * @var string
52 24 */
@@ -71,19 +43,8 @@
71 43 'customize_selective_refresh' => true,
72 44 )
73 45 );
74 46
75 - // When enabling campaigns other than 'none' or empty, change $no_current to false above.
76 - $this->campaigns = array(
77 - '' => esc_html__( 'All current and future campaigns', 'jetpack' ),
78 - 'none' => esc_html__( 'None, just display the badge please', 'jetpack' ),
79 - );
80 -
81 - $this->variants = array(
82 - 'banner' => esc_html__( 'Banner at the top of my site', 'jetpack' ),
83 - 'modal' => esc_html__( 'Modal (Overlay Box)', 'jetpack' ),
84 - );
85 -
86 47 $this->badges = array(
87 48 'shield_badge' => esc_html__( 'Shield Badge', 'jetpack' ),
88 49 'super_badge' => esc_html__( 'Super Badge', 'jetpack' ),
89 50 'side_bar_badge' => esc_html__( 'Red Cat Badge', 'jetpack' ),
@@ -88,16 +49,10 @@
88 49 'super_badge' => esc_html__( 'Super Badge', 'jetpack' ),
89 50 'side_bar_badge' => esc_html__( 'Red Cat Badge', 'jetpack' ),
90 51 );
91 52
92 - if ( false === $this->no_current ) {
93 - $this->badges['none'] = esc_html__( 'Don\'t display a badge (just the campaign)', 'jetpack' );
94 - }
95 -
96 53 $this->defaults = array(
97 - 'campaign' => key( $this->campaigns ),
98 - 'variant' => key( $this->variants ),
99 - 'badge' => key( $this->badges ),
54 + 'badge' => key( $this->badges ),
100 55 );
101 56
102 57 add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) );
103 58 }
@@ -127,22 +82,22 @@
127 82 if ( 'none' !== $instance['badge'] ) {
128 83 if ( ! isset( $this->badges[ $instance['badge'] ] ) ) {
129 84 $instance['badge'] = $this->defaults['badge'];
130 85 }
131 - $badge_url = esc_url( 'https://www.internetdefenseleague.org/images/badges/final/' . $instance['badge'] . '.png' );
132 - $photon_badge_url = jetpack_photon_url( $badge_url );
133 - $alt_text = esc_html__( 'Member of The Internet Defense League', 'jetpack' );
86 + $badge_url = 'internet-defense-league/' . $instance['badge'] . '.png';
87 +
134 88 echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
135 - echo '<p><a href="https://www.internetdefenseleague.org/"><img src="' . esc_url( $photon_badge_url ) . '" alt="' . esc_attr( $alt_text ) . '" style="max-width: 100%; height: auto;" /></a></p>';
89 +
90 + printf(
91 + '<p><a href="%1$s" target="_blank" rel="noopener noreferrer"><img src="%2$s" alt="%3$s" style="max-width: 100%%; height: auto;" /></a></p>',
92 + esc_url( 'https://www.fightforthefuture.org/' ),
93 + esc_url( plugins_url( $badge_url, __FILE__ ) ),
94 + esc_attr__( 'Member of The Internet Defense League', 'jetpack' )
95 + );
96 +
136 97 echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
137 98 }
138 99
139 - if ( 'none' !== $instance['campaign'] ) {
140 - $this->campaign = $instance['campaign'];
141 - $this->variant = $instance['variant'];
142 - add_action( 'wp_footer', array( $this, 'footer_script' ) );
143 - }
144 -
145 100 /** This action is already documented in modules/widgets/gravatar-profile.php */
146 101 do_action( 'jetpack_stats_extra', 'widget_view', 'internet_defense_league' );
147 102 }
148 103
@@ -147,36 +102,13 @@
147 102 }
148 103
149 104 /**
150 105 * Inline footer script.
106 + *
107 + * @deprecated 12.5 This widget does not enqueue scripts anymore.
151 108 */
152 109 public function footer_script() {
153 - if ( ! isset( $this->campaigns[ $this->campaign ] ) ) {
154 - $this->campaign = $this->defaults['campaign'];
155 - }
156 -
157 - if ( ! isset( $this->variants[ $this->variant ] ) ) {
158 - $this->variant = $this->defaults['variant'];
159 - }
160 -
161 - // On AMP endpoints, prevent a validation error from the inline script.
162 - if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
163 - return;
164 - }
165 -
166 - ?>
167 - <script type="text/javascript">
168 - window._idl = {};
169 - _idl.campaign = "<?php echo esc_js( $this->campaign ); ?>";
170 - _idl.variant = "<?php echo esc_js( $this->variant ); ?>";
171 - (function() {
172 - var idl = document.createElement('script');
173 - idl.async = true;
174 - idl.src = 'https://members.internetdefenseleague.org/include/?url=' + (_idl.url || '') + '&campaign=' + (_idl.campaign || '') + '&variant=' + (_idl.variant || 'banner');
175 - document.getElementsByTagName('body')[0].appendChild(idl);
176 - })();
177 - </script>
178 - <?php
110 + _deprecated_function( __METHOD__, 'jetpack-12.5' );
179 111 }
180 112
181 113 /**
182 114 * Widget form in the dashboard.
@@ -183,28 +115,21 @@
183 115 *
184 116 * @see WP_Widget::form()
185 117 *
186 118 * @param array $instance Previously saved values from database.
119 + * @return string|void
187 120 */
188 121 public function form( $instance ) {
189 122 $instance = wp_parse_args( $instance, $this->defaults );
190 123
191 - // Hide first two form fields if no current campaigns.
192 - if ( false === $this->no_current ) {
193 - echo '<p><label>';
194 - echo esc_html__( 'Which Internet Defense League campaign do you want to participate in?', 'jetpack' ) . '<br />';
195 - $this->select( 'campaign', $this->campaigns, $instance['campaign'] );
196 - echo '</label></p>';
124 + echo '<p><label>';
125 + echo esc_html__( 'Which badge would you like to display?', 'jetpack' ) . '<br />';
197 126
198 - echo '<p><label>';
199 - echo esc_html__( 'How do you want to promote the campaign?', 'jetpack' ) . '<br />';
200 - $this->select( 'variant', $this->variants, $instance['variant'] );
201 - echo '</label></p>';
127 + echo '<select class="widefat" name="' . esc_attr( $this->get_field_name( 'badge' ) ) . '">';
128 + foreach ( $this->badges as $option_slug => $option_name ) {
129 + echo '<option value="' . esc_attr( $option_slug ) . '"' . selected( $option_slug, $instance['badge'], false ) . '>' . esc_html( $option_name ) . '</option>';
202 130 }
203 -
204 - echo '<p><label>';
205 - echo esc_html__( 'Which badge would you like to display?', 'jetpack' ) . '<br />';
206 - $this->select( 'badge', $this->badges, $instance['badge'] );
131 + echo '</select>';
207 132 echo '</label></p>';
208 133
209 134 echo '<p>' . wp_kses(
210 135 sprintf(
@@ -209,13 +134,15 @@
209 134 echo '<p>' . wp_kses(
210 135 sprintf(
211 136 /* translators: %s is an HTML link to the website of an internet campaign called the "Internet Defense League" */
212 137 _x( 'Learn more about the %s', 'the Internet Defense League', 'jetpack' ),
213 - '<a href="https://www.internetdefenseleague.org/">Internet Defense League</a>'
138 + '<a href="https://www.fightforthefuture.org/" target="_blank" rel="noopener noreferrer">Internet Defense League</a>'
214 139 ),
215 140 array(
216 141 'a' => array(
217 - 'href' => array(),
142 + 'href' => array(),
143 + 'rel' => array(),
144 + 'target' => array(),
218 145 ),
219 146 )
220 147 ) . '</p>';
221 148 }
@@ -222,18 +149,16 @@
222 149
223 150 /**
224 151 * Display a select form field.
225 152 *
153 + * @deprecated 12.5 This widget only has one option now, no need for an extracted method.
154 + *
226 155 * @param string $field_name Name of the field.
227 156 * @param array $options Array of options.
228 157 * @param string $default Default option.
229 158 */
230 - public function select( $field_name, $options, $default = null ) {
231 - echo '<select class="widefat" name="' . esc_attr( $this->get_field_name( $field_name ) ) . '">';
232 - foreach ( $options as $option_slug => $option_name ) {
233 - echo '<option value="' . esc_attr( $option_slug ) . '"' . selected( $option_slug, $default, false ) . '>' . esc_html( $option_name ) . '</option>';
234 - }
235 - echo '</select>';
159 + public function select( $field_name, $options, $default = null ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
160 + _deprecated_function( __METHOD__, 'jetpack-12.5' );
236 161 }
237 162
238 163 /**
239 164 * Update widget.
@@ -245,11 +170,11 @@
245 170 */
246 171 public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
247 172 $instance = array();
248 173
249 - $instance['campaign'] = ( isset( $new_instance['campaign'] ) && isset( $this->campaigns[ $new_instance['campaign'] ] ) ) ? $new_instance['campaign'] : $this->defaults['campaign'];
250 - $instance['variant'] = ( isset( $new_instance['variant'] ) && isset( $this->variants[ $new_instance['variant'] ] ) ) ? $new_instance['variant'] : $this->defaults['variant'];
251 - $instance['badge'] = ( isset( $new_instance['badge'] ) && isset( $this->badges[ $new_instance['badge'] ] ) ) ? $new_instance['badge'] : $this->defaults['badge'];
174 + $instance['badge'] = ( isset( $new_instance['badge'] ) && isset( $this->badges[ $new_instance['badge'] ] ) )
175 + ? $new_instance['badge']
176 + : $this->defaults['badge'];
252 177
253 178 return $instance;
254 179 }
255 180 }
@@ -259,6 +184,5 @@
259 184 */
260 185 function jetpack_internet_defense_league_init() {
261 186 register_widget( 'Jetpack_Internet_Defense_League_Widget' );
262 187 }
263 -
264 188 add_action( 'widgets_init', 'jetpack_internet_defense_league_init' );