PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 13.9.2
Jetpack – WP Security, Backup, Speed, & Growth v13.9.2
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 14.1.1 14.2.2 14.3.1 14.4.2 14.5.1 14.6.1 14.7.1 14.8.1 14.9.2 15.0.3 15.1.2 15.2.1 15.3.2 15.4.1 15.5.1 15.6.1 15.7.2 15.8.1 15.9.2 16.0.2 16.1.3 16.2-a.5 16.2-a.3 16.1.2 16.2-a.1 16.1.1 16.1 16.1-beta 16.1-beta.2 16.1-beta.3 16.1-a.5 16.1-a.3 16.0.1 16.1-a.1 16.0 16.0-beta 16.0-a.7 16.0-a.5 15.9.1 16.0-a.3 16.0-a.1 15.9 15.9-beta 15.9-a.7 15.9-a.5 15.9-a.3 15.9-a.1 15.8 15.8-beta 15.8-a.7 15.8-a.5 5.2.5 5.3.4 5.4.4 5.5.5 5.6.5 5.7.5 5.8.4 5.9.4 6.0.4 6.1 6.1.1 6.1.2 6.1.3 6.1.4 6.1.5 6.2 6.2.1 6.2.2 6.2.3 6.2.4 6.2.5 6.3 6.3.1 6.3.2 6.3.3 6.3.4 6.3.5 6.3.6 6.3.7 6.4 6.4.1 6.4.2 6.4.3 6.4.4 6.4.5 6.4.6 6.5 6.5.1 6.5.2 6.5.3 6.5.4 6.6 6.6.1 6.6.2 6.6.3 6.6.4 6.6.5 6.7 6.7.1 6.7.2 6.7.3 6.7.4 6.8 6.8.1 6.8.2 6.8.3 6.8.4 6.8.5 6.9 6.9.1 6.9.2 6.9.3 6.9.4 7.0 7.0.1 7.0.2 7.0.3 7.0.4 7.0.5 7.1 7.1.1 7.1.2 7.1.3 7.1.4 7.1.5 7.2 7.2.1 7.2.1.1 7.2.2 7.2.3 7.2.4 7.2.5 7.3 7.3.0.1 7.3.1 7.3.1.1 7.3.2 7.3.3 7.3.4 7.3.5 7.4 7.4.1 7.4.2 7.4.3 7.4.4 7.4.5 7.5 7.5.0.1 7.5.1 7.5.2 7.5.3 7.5.4 7.5.5 7.5.6 7.5.7 7.6 7.6.1 7.6.2 7.6.3 7.6.4 7.7 7.7.1 7.7.2 7.7.3 7.7.4 7.7.5 7.7.6 7.8 7.8.1 7.8.2 7.8.3 7.8.4 7.9 7.9.1 7.9.2 7.9.3 7.9.4 8.0 8.0.1 8.0.2 8.0.3 8.1 8.1.1 8.1.2 8.1.3 8.1.4 8.2 8.2.0.1 8.2.1 8.2.2 8.2.3 8.2.4 8.2.5 8.2.6 8.3 8.3.1 8.3.2 8.3.3 8.4 8.4.1 8.4.2 8.4.3 8.4.4 8.4.5 8.5 8.5.1 8.5.2 8.5.3 8.6 8.6.1 8.6.2 8.6.3 8.6.4 8.7 8.7.0.1 8.7.1 8.7.2 8.7.3 8.7.4 8.8 8.8.1 8.8.2 8.8.3 8.8.4 8.8.5 8.9 8.9.1 8.9.2 8.9.3 8.9.4 9.0 9.0.1 9.0.2 9.0.3 9.0.4 9.0.5 9.1 9.1.1 9.1.2 9.1.3 9.2 9.2.1 9.2.2 9.2.3 9.2.4 9.3 9.3.1 9.3.2 9.3.3 9.3.4 9.3.5 9.4 9.4.1 9.4.2 9.4.3 9.4.4 9.5 9.5.1 9.5.2 9.5.3 9.5.4 9.5.5 9.6 9.6.1 9.6.2 9.6.3 9.6.4 9.7 9.7.1 9.7.2 15.7-beta.2 9.7.3 15.7.1 9.8 15.8-a.1 9.8.1 15.8-a.3 9.8.2 2.0.9 9.8.3 2.1.7 9.9 2.2.10 9.9.1 2.3.10 9.9.2 2.4.7 9.9.3 2.5.5 2.6.6 2.7.5 2.8.5 2.9.6 3.0.6 3.1.5 3.2.5 3.3.6 3.4.6 3.5.6 3.6.4 3.7.5 3.8.5 3.9.10 4.0.7 4.1.4 4.2.5 4.3.5 4.4.5 4.5.3 4.6.3 4.7.4 4.8.5 4.9.3 5.0.3 5.1.4 trunk 10.0 10.0.1 10.0.2 10.1 10.1.1 10.1.2 10.2 10.2.1 10.2.2 10.2.3 10.3 10.3.1 10.3.2 10.4 10.4.1 10.4.2 10.5 10.5.1 10.5.2 10.5.3 10.6 10.6.1 10.6.2 10.7 10.7.1 10.7.2 10.8 10.8.1 10.8.2 10.9 10.9.1 10.9.2 10.9.3 11.0 11.0.1 11.0.2 11.1 11.1.1 11.1.2 11.1.3 11.1.4 11.2 11.2.1 11.2.2 11.3 11.3.1 11.3.2 11.3.3 11.3.4 11.4 11.4.1 11.4.2 11.5 11.5.1 11.5.2 11.5.3 11.6 11.6.1 11.6.2 11.7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / widgets / social-icons.php
jetpack / modules / widgets Last commit date
authors 8 years ago contact-info 5 years ago eu-cookie-law 2 years ago facebook-likebox 11 years ago flickr 2 years ago gallery 2 years ago goodreads 2 years ago google-translate 4 years ago image-widget 8 years ago instagram 6 years ago internet-defense-league 2 years ago migrate-to-core 3 years ago milestone 2 years ago my-community 8 years ago simple-payments 2 years ago social-icons 4 years ago social-media-icons 5 years ago top-posts 8 years ago wordpress-post-widget 2 years ago authors.php 3 years ago blog-stats.php 2 years ago class-jetpack-eu-cookie-law-widget.php 2 years ago class-jetpack-instagram-widget.php 2 years ago contact-info.php 2 years ago customizer-controls.css 9 years ago customizer-utils.js 6 years ago facebook-likebox.php 2 years ago flickr.php 2 years ago gallery.php 2 years ago goodreads.php 2 years ago google-translate.php 2 years ago gravatar-profile.css 10 years ago gravatar-profile.php 2 years ago image-widget.php 3 years ago internet-defense-league.php 3 years ago mailchimp.php 3 years ago milestone.php 5 years ago my-community.php 2 years ago rsslinks-widget.php 3 years ago simple-payments.php 2 years ago social-icons.php 2 years ago social-media-icons.php 2 years ago top-posts.php 2 years ago twitter-timeline-admin.js 6 years ago twitter-timeline.php 3 years ago upcoming-events.php 2 years ago wordpress-post-widget.php 4 years ago
social-icons.php
835 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
4
5 /**
6 * Social Icons Widget.
7 */
8 class Jetpack_Widget_Social_Icons extends WP_Widget {
9
10 const ID_BASE = 'jetpack_widget_social_icons';
11
12 /**
13 * Default widget options.
14 *
15 * @var array Default widget options.
16 */
17 protected $defaults;
18
19 /**
20 * Widget constructor.
21 */
22 public function __construct() {
23 global $pagenow;
24
25 $widget_ops = array(
26 'classname' => 'jetpack_widget_social_icons',
27 'description' => __( 'Add social-media icons to your site.', 'jetpack' ),
28 'show_instance_in_rest' => true,
29 'customize_selective_refresh' => true,
30 );
31
32 parent::__construct(
33 'jetpack_widget_social_icons',
34 /** This filter is documented in modules/widgets/facebook-likebox.php */
35 apply_filters( 'jetpack_widget_name', __( 'Social Icons', 'jetpack' ) ),
36 $widget_ops
37 );
38
39 $this->defaults = array(
40 'title' => __( 'Follow Us', 'jetpack' ),
41 'icon-size' => 'medium',
42 'new-tab' => false,
43 'icons' => array(
44 array(
45 'url' => '',
46 ),
47 ),
48 );
49
50 // Enqueue admin scrips and styles, only in the customizer or the old widgets page.
51 if ( is_customize_preview() || 'widgets.php' === $pagenow ) {
52 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
53 add_action( 'admin_print_footer_scripts', array( $this, 'render_admin_js' ) );
54 }
55
56 // Enqueue scripts and styles for the display of the widget, on the frontend or in the customizer.
57 if ( is_active_widget( false, $this->id, $this->id_base, true ) || is_customize_preview() ) {
58 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_icon_scripts' ) );
59 add_action( 'wp_footer', array( $this, 'include_svg_icons' ), 9999 );
60 }
61
62 add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) );
63 }
64
65 /**
66 * Remove the "Social Icons" widget from the Legacy Widget block
67 *
68 * @param array $widget_types List of widgets that are currently removed from the Legacy Widget block.
69 * @return array $widget_types New list of widgets that will be removed.
70 */
71 public function hide_widget_in_block_editor( $widget_types ) {
72 $widget_types[] = self::ID_BASE;
73 return $widget_types;
74 }
75
76 /**
77 * Script & styles for admin widget form.
78 */
79 public function enqueue_admin_scripts() {
80 wp_enqueue_script(
81 'jetpack-widget-social-icons-script',
82 plugins_url( 'social-icons/social-icons-admin.js', __FILE__ ),
83 array( 'jquery', 'jquery-ui-sortable' ),
84 '20170506',
85 true
86 );
87 wp_enqueue_style(
88 'jetpack-widget-social-icons-admin',
89 plugins_url( 'social-icons/social-icons-admin.css', __FILE__ ),
90 array(),
91 '20170506'
92 );
93 }
94
95 /**
96 * Styles for front-end widget.
97 */
98 public function enqueue_icon_scripts() {
99 wp_enqueue_style( 'jetpack-widget-social-icons-styles', plugins_url( 'social-icons/social-icons.css', __FILE__ ), array(), '20170506' );
100 }
101
102 /**
103 * JavaScript for admin widget form.
104 */
105 public function render_admin_js() {
106 ?>
107 <script type="text/html" id="tmpl-jetpack-widget-social-icons-template">
108 <?php self::render_icons_template(); ?>
109 </script>
110 <?php
111 }
112
113 /**
114 * Add SVG definitions to the footer.
115 */
116 public function include_svg_icons() {
117 // Define SVG sprite file in Jetpack.
118 $svg_icons = dirname( __DIR__ ) . '/theme-tools/social-menu/social-menu.svg';
119 $svg_icons = class_exists( 'Automattic\Jetpack\Classic_Theme_Helper\Main' ) ? JETPACK__PLUGIN_DIR . 'jetpack_vendor/automattic/jetpack-classic-theme-helper/src/social-menu/social-menu.svg' : dirname( __DIR__ ) . '/theme-tools/social-menu/social-menu.svg';
120 // Define SVG sprite file in WPCOM.
121 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
122 $svg_icons = class_exists( 'Automattic\Jetpack\Classic_Theme_Helper\Main' ) ? JETPACK__PLUGIN_DIR . 'jetpack_vendor/automattic/jetpack-classic-theme-helper/src/social-menu/social-menu.svg' : dirname( __DIR__ ) . '/social-menu/social-menu.svg';
123 }
124
125 // If it exists, include it.
126 if ( is_file( $svg_icons ) ) {
127 $svg_contents = file_get_contents( $svg_icons ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Only reading a local file.
128 }
129
130 if ( ! empty( $svg_contents ) ) {
131 $allowed_tags = array(
132 'svg' => array(
133 'style' => true,
134 'version' => true,
135 'xmlns' => true,
136 'xmlns:xlink' => true,
137 ),
138 'defs' => array(),
139 'symbol' => array(
140 'id' => true,
141 'viewbox' => true,
142 ),
143 'path' => array(
144 'd' => true,
145 'style' => true,
146 ),
147 );
148 echo wp_kses( $svg_contents, $allowed_tags );
149 }
150 }
151
152 /**
153 * Front-end display of widget.
154 *
155 * @see WP_Widget::widget()
156 *
157 * @param array $args Widget arguments.
158 * @param array $instance Saved values from database.
159 */
160 public function widget( $args, $instance ) {
161 $instance = wp_parse_args( $instance, $this->defaults );
162
163 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
164 $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
165
166 echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
167
168 if ( ! empty( $title ) ) {
169 echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
170 }
171
172 if ( ! empty( $instance['icons'] ) ) :
173
174 // Get supported social icons.
175 $social_icons = $this->get_supported_icons();
176 $default_icon = $this->get_svg_icon( array( 'icon' => 'chain' ) );
177
178 ?>
179
180 <ul class="jetpack-social-widget-list size-<?php echo esc_attr( $instance['icon-size'] ); ?>">
181
182 <?php foreach ( $instance['icons'] as $icon ) : ?>
183
184 <?php if ( ! empty( $icon['url'] ) ) : ?>
185 <li class="jetpack-social-widget-item">
186 <?php
187 printf(
188 '<a href="%1$s" %2$s>',
189 esc_url( $icon['url'], array( 'http', 'https', 'mailto', 'skype', 'sms' ) ),
190 true === $instance['new-tab'] ?
191 'target="_blank" rel="noopener noreferrer"' :
192 'target="_self"'
193 );
194
195 $found_icon = false;
196
197 foreach ( $social_icons as $social_icon ) {
198 foreach ( $social_icon['url'] as $url_fragment ) {
199 /*
200 * url_fragment can be a URL host, or a regex, starting with #.
201 * Let's check for both scenarios.
202 */
203 if (
204 // First Regex.
205 (
206 str_starts_with( $url_fragment, '#' ) && str_ends_with( $url_fragment, '#' )
207 && preg_match( $url_fragment, $icon['url'] )
208 )
209 // Then, regular host name.
210 || str_contains( $icon['url'], $url_fragment )
211 ) {
212 printf(
213 '<span class="screen-reader-text">%1$s</span>%2$s',
214 esc_attr( $social_icon['label'] ),
215 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
216 $this->get_svg_icon(
217 array(
218 'icon' => esc_attr( $social_icon['icon'] ),
219 )
220 )
221 );
222 $found_icon = true;
223 break 2;
224 }
225 }
226 }
227
228 if ( ! $found_icon ) {
229 echo $default_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
230 }
231 ?>
232 </a>
233 </li>
234 <?php endif; ?>
235
236 <?php endforeach; ?>
237
238 </ul>
239
240 <?php
241 endif;
242
243 echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
244
245 /** This action is documented in modules/widgets/gravatar-profile.php */
246 do_action( 'jetpack_stats_extra', 'widget_view', 'social_icons' );
247 }
248
249 /**
250 * Sanitize widget form values as they are saved.
251 *
252 * @see WP_Widget::update()
253 *
254 * @param array $new_instance Values just sent to be saved.
255 * @param array $old_instance Previously saved values from database.
256 *
257 * @return array Updated safe values to be saved.
258 */
259 public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
260 $instance = array();
261
262 $instance['title'] = sanitize_text_field( $new_instance['title'] );
263 $instance['icon-size'] = $this->defaults['icon-size'];
264 $instance['url-icons'] = array_key_exists( 'url-icons', $new_instance ) ? $new_instance['url-icons'] : array();
265
266 if ( in_array( $new_instance['icon-size'], array( 'small', 'medium', 'large' ), true ) ) {
267 $instance['icon-size'] = $new_instance['icon-size'];
268 }
269
270 $instance['new-tab'] = isset( $new_instance['new-tab'] ) ? (bool) $new_instance['new-tab'] : false;
271 $instance['icons'] = array();
272
273 if ( array_key_exists( 'url-icons', $new_instance ) ) {
274 foreach ( $new_instance['url-icons'] as $url ) {
275 $url = filter_var( $url, FILTER_SANITIZE_URL );
276
277 if ( ! empty( $url ) ) {
278 $instance['icons'][] = array(
279 'url' => $url,
280 );
281 }
282 }
283 }
284
285 return $instance;
286 }
287
288 /**
289 * Back-end widget form.
290 *
291 * @see WP_Widget::form()
292 *
293 * @param array $instance Previously saved values from database.
294 *
295 * @return string|void
296 */
297 public function form( $instance ) {
298 $instance = wp_parse_args( $instance, $this->defaults );
299 $title = sanitize_text_field( $instance['title'] );
300 $sizes = array(
301 'small' => __( 'Small', 'jetpack' ),
302 'medium' => __( 'Medium', 'jetpack' ),
303 'large' => __( 'Large', 'jetpack' ),
304 );
305 $new_tab = isset( $instance['new-tab'] ) ? (bool) $instance['new-tab'] : false;
306 ?>
307
308 <p>
309 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'jetpack' ); ?></label>
310 <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
311 </p>
312
313 <p>
314 <label for="<?php echo esc_attr( $this->get_field_id( 'icon-size' ) ); ?>"><?php esc_html_e( 'Size:', 'jetpack' ); ?></label>
315 <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'icon-size' ) ); ?>">
316 <?php foreach ( $sizes as $value => $label ) : ?>
317 <option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $instance['icon-size'] ); ?>><?php echo esc_attr( $label ); ?></option>
318 <?php endforeach; ?>
319 </select>
320 </p>
321
322 <div class="jetpack-social-icons-widget-list"
323 data-url-icon-id="<?php echo esc_attr( $this->get_field_id( 'url-icons' ) ); ?>"
324 data-url-icon-name="<?php echo esc_attr( $this->get_field_name( 'url-icons' ) ); ?>"
325 >
326
327 <?php
328 foreach ( $instance['icons'] as $icon ) {
329 self::render_icons_template(
330 array(
331 'url-icon-id' => $this->get_field_id( 'url-icons' ),
332 'url-icon-name' => $this->get_field_name( 'url-icons' ),
333 'url-value' => $icon['url'],
334 )
335 );
336 }
337 ?>
338
339 </div>
340
341 <p class="jetpack-social-icons-widget add-button">
342 <button type="button" class="button jetpack-social-icons-add-button">
343 <?php esc_html_e( 'Add an icon', 'jetpack' ); ?>
344 </button>
345 </p>
346
347 <?php
348 switch ( get_locale() ) {
349 case 'es':
350 $support = 'https://es.support.wordpress.com/social-media-icons-widget/#iconos-disponibles';
351 break;
352
353 case 'pt-br':
354 $support = 'https://br.support.wordpress.com/widgets/widget-de-icones-sociais/#ícones-disponíveis';
355 break;
356
357 default:
358 $support = 'https://en.support.wordpress.com/widgets/social-media-icons-widget/#available-icons';
359 }
360 ?>
361
362 <p>
363 <em><a href="<?php echo esc_url( $support ); ?>" target="_blank" rel="noopener noreferrer">
364 <?php esc_html_e( 'View available icons', 'jetpack' ); ?>
365 </a></em>
366 </p>
367
368 <p>
369 <input type="checkbox" class="checkbox" id="<?php echo esc_attr( $this->get_field_id( 'new-tab' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'new-tab' ) ); ?>" <?php checked( $new_tab ); ?> />
370 <label for="<?php echo esc_attr( $this->get_field_id( 'new-tab' ) ); ?>"><?php esc_html_e( 'Open link in a new tab', 'jetpack' ); ?></label>
371 </p>
372
373 <?php
374 }
375
376 /**
377 * Generates template to add icons.
378 *
379 * @param array $args Template arguments.
380 */
381 private static function render_icons_template( $args = array() ) {
382 $defaults = array(
383 'url-icon-id' => '',
384 'url-icon-name' => '',
385 'url-value' => '',
386 );
387
388 $args = wp_parse_args( $args, $defaults );
389 ?>
390
391 <div class="jetpack-social-icons-widget-item">
392 <div class="jetpack-social-icons-widget-item-wrapper">
393 <div class="handle"></div>
394
395 <p class="jetpack-widget-social-icons-url">
396 <?php
397 printf(
398 '<input class="widefat" id="%1$s" name="%2$s[]" type="text" placeholder="%3$s" value="%4$s"/>',
399 esc_attr( $args['url-icon-id'] ),
400 esc_attr( $args['url-icon-name'] ),
401 esc_attr__( 'Account URL', 'jetpack' ),
402 esc_url( $args['url-value'], array( 'http', 'https', 'mailto', 'skype', 'sms' ) )
403 );
404 ?>
405 </p>
406
407 <p class="jetpack-widget-social-icons-remove-item">
408 <a class="jetpack-widget-social-icons-remove-item-button" href="javascript:;">
409 <?php esc_html_e( 'Remove', 'jetpack' ); ?>
410 </a>
411 </p>
412 </div>
413 </div>
414
415 <?php
416 }
417
418 /**
419 * Return SVG markup.
420 *
421 * @param array $args {
422 * Parameters needed to display an SVG.
423 *
424 * @type string $icon Required SVG icon filename.
425 * }
426 * @return string SVG markup.
427 */
428 public function get_svg_icon( $args = array() ) {
429 // Make sure $args are an array.
430 if ( empty( $args ) ) {
431 return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' );
432 }
433
434 // Set defaults.
435 $defaults = array(
436 'icon' => '',
437 );
438
439 // Parse args.
440 $args = wp_parse_args( $args, $defaults );
441
442 // Define an icon.
443 if ( false === array_key_exists( 'icon', $args ) ) {
444 return esc_html__( 'Please define an SVG icon filename.', 'jetpack' );
445 }
446
447 // Set aria hidden.
448 $aria_hidden = ' aria-hidden="true"';
449
450 // Begin SVG markup.
451 $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . ' role="presentation">';
452
453 /*
454 * Display the icon.
455 *
456 * The whitespace around `<use>` is intentional - it is a work around to a keyboard navigation bug in Safari 10.
457 *
458 * See https://core.trac.wordpress.org/ticket/38387.
459 */
460 $svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> ';
461
462 $svg .= '</svg>';
463
464 return $svg;
465 }
466
467 /**
468 * Returns an array of supported social links (URL, icon, and label).
469 *
470 * @return array $social_links_icons
471 */
472 public function get_supported_icons() {
473 $social_links_icons = array(
474 array(
475 'url' => array( '500px.com' ),
476 'icon' => '500px',
477 'label' => '500px',
478 ),
479 array(
480 'url' => array(
481 '#https?:\/\/(www\.)?amazon\.(com|cn|in|fr|de|it|nl|es|co|ca)\/#',
482 ),
483 'icon' => 'amazon',
484 'label' => 'Amazon',
485 ),
486 array(
487 'url' => array( 'apple.com' ),
488 'icon' => 'apple',
489 'label' => 'Apple',
490 ),
491 array(
492 'url' => array( 'itunes.com' ),
493 'icon' => 'apple',
494 'label' => 'iTunes',
495 ),
496 array(
497 'url' => array( 'bandcamp.com' ),
498 'icon' => 'bandcamp',
499 'label' => 'Bandcamp',
500 ),
501 array(
502 'url' => array( 'behance.net' ),
503 'icon' => 'behance',
504 'label' => 'Behance',
505 ),
506 array(
507 'url' => array(
508 'blogger.com',
509 'blogspot.com',
510 ),
511 'icon' => 'blogger',
512 'label' => 'Blogger',
513 ),
514 array(
515 'url' => array( 'bsky.app' ),
516 'icon' => 'bluesky',
517 'label' => 'Bluesky',
518 ),
519 array(
520 'url' => array( 'codepen.io' ),
521 'icon' => 'codepen',
522 'label' => 'CodePen',
523 ),
524 array(
525 'url' => array( 'deviantart.com' ),
526 'icon' => 'deviantart',
527 'label' => 'DeviantArt',
528 ),
529 array(
530 'url' => array( 'digg.com' ),
531 'icon' => 'digg',
532 'label' => 'Digg',
533 ),
534 array(
535 'url' => array( '#discord\.gg|discordapp\.com#' ),
536 'icon' => 'discord',
537 'label' => 'Discord',
538 ),
539 array(
540 'url' => array( 'dribbble.com' ),
541 'icon' => 'dribbble',
542 'label' => 'Dribbble',
543 ),
544 array(
545 'url' => array( 'dropbox.com' ),
546 'icon' => 'dropbox',
547 'label' => 'Dropbox',
548 ),
549 array(
550 'url' => array( 'etsy.com' ),
551 'icon' => 'etsy',
552 'label' => 'Etsy',
553 ),
554 array(
555 'url' => array( 'eventbrite.com' ),
556 'icon' => 'eventbrite',
557 'label' => 'Eventbrite',
558 ),
559 array(
560 'url' => array( 'facebook.com' ),
561 'icon' => 'facebook',
562 'label' => 'Facebook',
563 ),
564 array(
565 'url' => array( 'flickr.com' ),
566 'icon' => 'flickr',
567 'label' => 'Flickr',
568 ),
569 array(
570 'url' => array( 'foursquare.com' ),
571 'icon' => 'foursquare',
572 'label' => 'Foursquare',
573 ),
574 array(
575 'url' => array( 'ghost.org' ),
576 'icon' => 'ghost',
577 'label' => 'Ghost',
578 ),
579 array(
580 'url' => array( 'goodreads.com' ),
581 'icon' => 'goodreads',
582 'label' => 'Goodreads',
583 ),
584 array(
585 'url' => array( '#google\.(com|co\.uk|ca|cn|it)#' ),
586 'icon' => 'google',
587 'label' => 'Google',
588 ),
589 array(
590 'url' => array( 'github.com' ),
591 'icon' => 'github',
592 'label' => 'GitHub',
593 ),
594 array(
595 'url' => array( 'instagram.com' ),
596 'icon' => 'instagram',
597 'label' => 'Instagram',
598 ),
599 array(
600 'url' => array( 'linkedin.com' ),
601 'icon' => 'linkedin',
602 'label' => 'LinkedIn',
603 ),
604 array(
605 'url' => array( 'mailto:' ),
606 'icon' => 'mail',
607 'label' => __( 'Email', 'jetpack' ),
608 ),
609 array(
610 'url' => jetpack_mastodon_get_instance_list(),
611 'icon' => 'mastodon',
612 'label' => 'Mastodon',
613 ),
614 array(
615 'url' => array( 'meetup.com' ),
616 'icon' => 'meetup',
617 'label' => 'Meetup',
618 ),
619 array(
620 'url' => array( 'medium.com' ),
621 'icon' => 'medium',
622 'label' => 'Medium',
623 ),
624 array(
625 'url' => array( 'nextdoor.com' ),
626 'icon' => 'nextdoor',
627 'label' => 'Nextdoor',
628 ),
629 array(
630 'url' => array( 'patreon.com' ),
631 'icon' => 'patreon',
632 'label' => 'Patreon',
633 ),
634 array(
635 'url' => array( 'pinterest.' ),
636 'icon' => 'pinterest',
637 'label' => 'Pinterest',
638 ),
639 array(
640 'url' => array( 'getpocket.com' ),
641 'icon' => 'pocket',
642 'label' => 'Pocket',
643 ),
644 array(
645 'url' => array( 'ravelry.com' ),
646 'icon' => 'ravelry',
647 'label' => 'Ravelry',
648 ),
649 array(
650 'url' => array( 'reddit.com' ),
651 'icon' => 'reddit',
652 'label' => 'Reddit',
653 ),
654 array(
655 'url' => array( 'skype.com' ),
656 'icon' => 'skype',
657 'label' => 'Skype',
658 ),
659 array(
660 'url' => array( 'skype:' ),
661 'icon' => 'skype',
662 'label' => 'Skype',
663 ),
664 array(
665 'url' => array( 'slideshare.net' ),
666 'icon' => 'slideshare',
667 'label' => 'SlideShare',
668 ),
669 array(
670 'url' => array( 'sms:' ),
671 'icon' => 'sms',
672 'label' => 'SMS',
673 ),
674 array(
675 'url' => array( 'snapchat.com' ),
676 'icon' => 'snapchat',
677 'label' => 'Snapchat',
678 ),
679 array(
680 'url' => array( 'soundcloud.com' ),
681 'icon' => 'soundcloud',
682 'label' => 'SoundCloud',
683 ),
684 array(
685 'url' => array( 'spotify.com' ),
686 'icon' => 'spotify',
687 'label' => 'Spotify',
688 ),
689 array(
690 'url' => array( 'stackoverflow.com' ),
691 'icon' => 'stackoverflow',
692 'label' => 'Stack Overflow',
693 ),
694 array(
695 'url' => array( 'strava.com' ),
696 'icon' => 'strava',
697 'label' => 'Strava',
698 ),
699 array(
700 'url' => array( 'stumbleupon.com' ),
701 'icon' => 'stumbleupon',
702 'label' => 'StumbleUpon',
703 ),
704 array(
705 'url' => array( '#https?:\/\/(www\.)?(telegram|t)\.me#' ),
706 'icon' => 'telegram',
707 'label' => 'Telegram',
708 ),
709 array(
710 'url' => array( 'threads.net' ),
711 'icon' => 'threads',
712 'label' => 'Threads',
713 ),
714 array(
715 'url' => array( 'tiktok.com' ),
716 'icon' => 'tiktok',
717 'label' => 'TikTok',
718 ),
719 array(
720 'url' => array( 'tumblr.com' ),
721 'icon' => 'tumblr',
722 'label' => 'Tumblr',
723 ),
724 array(
725 'url' => array( 'twitch.tv' ),
726 'icon' => 'twitch',
727 'label' => 'Twitch',
728 ),
729 array(
730 'url' => array( 'twitter.com' ),
731 'icon' => 'twitter',
732 'label' => 'Twitter',
733 ),
734 array(
735 'url' => array( 'vimeo.com' ),
736 'icon' => 'vimeo',
737 'label' => 'Vimeo',
738 ),
739 array(
740 'url' => array( 'vk.com' ),
741 'icon' => 'vk',
742 'label' => 'VK',
743 ),
744 array(
745 'url' => array( 'whatsapp.com' ),
746 'icon' => 'whatsapp',
747 'label' => 'WhatsApp',
748 ),
749 array(
750 'url' => array( 'woocommerce.com' ),
751 'icon' => 'woocommerce',
752 'label' => 'WooCommerce',
753 ),
754 array(
755 'url' => array( '#wordpress\.(com|org)#' ),
756 'icon' => 'wordpress',
757 'label' => 'WordPress',
758 ),
759 array(
760 'url' => array( 'yelp.com' ),
761 'icon' => 'yelp',
762 'label' => 'Yelp',
763 ),
764 array(
765 'url' => array( 'x.com' ),
766 'icon' => 'x',
767 'label' => 'X',
768 ),
769 array(
770 'url' => array( 'xanga.com' ),
771 'icon' => 'xanga',
772 'label' => 'Xanga',
773 ),
774 array(
775 'url' => array( 'youtube.com' ),
776 'icon' => 'youtube',
777 'label' => 'YouTube',
778 ),
779
780 // keep feed at the end so that more specific icons can take precedence.
781 array(
782 'url' => array(
783 '/feed/', // WordPress default feed url.
784 '/feeds/', // Blogspot and others.
785 '/blog/feed', // No trailing slash WordPress feed, could use /feed but may match unexpectedly.
786 'format=RSS', // Squarespace and others.
787 '/rss', // Tumblr.
788 '/.rss', // Reddit.
789 '/rss.xml', // Moveable Type, Typepad.
790 'http://rss.', // Old custom format.
791 'https://rss.', // Old custom format.
792 'rss=1',
793 '/feed=rss', // Catches feed=rss / feed=rss2.
794 '?feed=rss', // WordPress non-permalink - Catches feed=rss / feed=rss2.
795 '?feed=rdf', // WordPress non-permalink.
796 '?feed=atom', // WordPress non-permalink.
797 'http://feeds.', // FeedBurner.
798 'https://feeds.', // FeedBurner.
799 '/feed.xml', // Feedburner Alias, and others.
800 '/index.xml', // Moveable Type, and others.
801 '/atom.xml', // Typepad, Squarespace.
802 '.atom', // Shopify blog.
803 '/atom', // Some non-WordPress feeds.
804 'index.rdf', // Typepad.
805 ),
806 'icon' => 'feed',
807 'label' => __( 'RSS Feed', 'jetpack' ),
808 ),
809 );
810
811 /**
812 * Filter the list of services matching Social Media Icons available in the Social Icons SVG sprite.
813 *
814 * @since 12.3
815 *
816 * @param array $social_links_icons Array of social links icons.
817 */
818 return apply_filters(
819 'jetpack_social_icons_supported_icons',
820 $social_links_icons
821 );
822 }
823 } // Jetpack_Widget_Social_Icons
824
825 /**
826 * Register and load the widget.
827 *
828 * @access public
829 * @return void
830 */
831 function jetpack_widget_social_icons_load() {
832 register_widget( 'Jetpack_Widget_Social_Icons' );
833 }
834 add_action( 'widgets_init', 'jetpack_widget_social_icons_load' );
835