PluginProbe ʕ •ᴥ•ʔ
Jetpack – WP Security, Backup, Speed, & Growth / 15.2.1
Jetpack – WP Security, Backup, Speed, & Growth v15.2.1
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 1 year ago contact-info 1 year ago eu-cookie-law 1 year ago facebook-likebox 11 years ago flickr 1 year ago gallery 1 year ago goodreads 1 year ago google-translate 1 year ago image-widget 1 year ago instagram 1 year ago internet-defense-league 2 years ago milestone 1 year ago my-community 1 year ago social-icons 1 year ago social-media-icons 1 year ago top-posts 1 year ago wordpress-post-widget 11 months ago authors.php 1 year ago blog-stats.php 1 year ago class-jetpack-eu-cookie-law-widget.php 10 months ago class-jetpack-instagram-widget.php 1 year ago contact-info.php 1 year ago customizer-controls.css 1 year ago customizer-utils.js 1 year ago facebook-likebox.php 1 year ago flickr.php 1 year ago gallery.php 1 year ago goodreads.php 11 months ago google-translate.php 10 months ago gravatar-profile.css 1 year ago gravatar-profile.php 1 year ago image-widget.php 1 year ago internet-defense-league.php 1 year ago mailchimp.php 1 year ago milestone.php 1 year ago my-community.php 1 year ago rsslinks-widget.php 1 year ago simple-payments.php 1 year ago social-icons.php 1 year ago social-media-icons.php 1 year ago top-posts.php 10 months ago twitter-timeline-admin.js 1 year ago twitter-timeline.php 1 year ago upcoming-events.php 1 year ago wordpress-post-widget.php 1 year ago
social-icons.php
822 lines
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit( 0 );
5 }
6
7 // phpcs:disable Universal.Files.SeparateFunctionsFromOO.Mixed -- TODO: Move classes to appropriately-named class files.
8
9 /**
10 * Social Icons Widget.
11 */
12 class Jetpack_Widget_Social_Icons extends WP_Widget {
13
14 const ID_BASE = 'jetpack_widget_social_icons';
15
16 /**
17 * Default widget options.
18 *
19 * @var array Default widget options.
20 */
21 protected $defaults;
22
23 /**
24 * Widget constructor.
25 */
26 public function __construct() {
27 global $pagenow;
28
29 $widget_ops = array(
30 'classname' => 'jetpack_widget_social_icons',
31 'description' => __( 'Add social-media icons to your site.', 'jetpack' ),
32 'show_instance_in_rest' => true,
33 'customize_selective_refresh' => true,
34 );
35
36 parent::__construct(
37 'jetpack_widget_social_icons',
38 /** This filter is documented in modules/widgets/facebook-likebox.php */
39 apply_filters( 'jetpack_widget_name', __( 'Social Icons', 'jetpack' ) ),
40 $widget_ops
41 );
42
43 $this->defaults = array(
44 'title' => __( 'Follow Us', 'jetpack' ),
45 'icon-size' => 'medium',
46 'new-tab' => false,
47 'icons' => array(
48 array(
49 'url' => '',
50 ),
51 ),
52 );
53
54 // Enqueue admin scrips and styles, only in the customizer or the old widgets page.
55 if ( is_customize_preview() || 'widgets.php' === $pagenow ) {
56 add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_admin_scripts' ) );
57 add_action( 'admin_print_footer_scripts', array( $this, 'render_admin_js' ) );
58 }
59
60 add_filter( 'widget_types_to_hide_from_legacy_widget_block', array( $this, 'hide_widget_in_block_editor' ) );
61 }
62
63 /**
64 * Remove the "Social Icons" widget from the Legacy Widget block
65 *
66 * @param array $widget_types List of widgets that are currently removed from the Legacy Widget block.
67 * @return array $widget_types New list of widgets that will be removed.
68 */
69 public function hide_widget_in_block_editor( $widget_types ) {
70 $widget_types[] = self::ID_BASE;
71 return $widget_types;
72 }
73
74 /**
75 * Script & styles for admin widget form.
76 */
77 public function enqueue_admin_scripts() {
78 wp_enqueue_script(
79 'jetpack-widget-social-icons-script',
80 plugins_url( 'social-icons/social-icons-admin.js', __FILE__ ),
81 array( 'jquery', 'jquery-ui-sortable' ),
82 '20170506',
83 true
84 );
85 wp_enqueue_style(
86 'jetpack-widget-social-icons-admin',
87 plugins_url( 'social-icons/social-icons-admin.css', __FILE__ ),
88 array(),
89 '20170506'
90 );
91 }
92
93 /**
94 * Styles for front-end widget.
95 */
96 public function enqueue_icon_scripts() {
97 wp_enqueue_style( 'jetpack-widget-social-icons-styles', plugins_url( 'social-icons/social-icons.css', __FILE__ ), array(), '20170506' );
98 }
99
100 /**
101 * JavaScript for admin widget form.
102 */
103 public function render_admin_js() {
104 ?>
105 <script type="text/html" id="tmpl-jetpack-widget-social-icons-template">
106 <?php self::render_icons_template(); ?>
107 </script>
108 <?php
109 }
110
111 /**
112 * Add SVG definitions to the footer.
113 */
114 public function include_svg_icons() {
115 // Define SVG sprite file in Jetpack.
116 $svg_icons = dirname( __DIR__ ) . '/theme-tools/social-menu/social-menu.svg';
117 $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';
118 // Define SVG sprite file in WPCOM.
119 if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
120 $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';
121 }
122
123 // If it exists, include it.
124 if ( is_file( $svg_icons ) ) {
125 $svg_contents = file_get_contents( $svg_icons ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Only reading a local file.
126 }
127
128 if ( ! empty( $svg_contents ) ) {
129 $allowed_tags = array(
130 'svg' => array(
131 'style' => true,
132 'version' => true,
133 'xmlns' => true,
134 'xmlns:xlink' => true,
135 ),
136 'defs' => array(),
137 'symbol' => array(
138 'id' => true,
139 'viewbox' => true,
140 ),
141 'path' => array(
142 'd' => true,
143 'style' => true,
144 ),
145 );
146 echo wp_kses( $svg_contents, $allowed_tags );
147 }
148 }
149
150 /**
151 * Front-end display of widget.
152 *
153 * @see WP_Widget::widget()
154 *
155 * @param array $args Widget arguments.
156 * @param array $instance Saved values from database.
157 */
158 public function widget( $args, $instance ) {
159 $instance = wp_parse_args( $instance, $this->defaults );
160
161 // Enqueue front end assets.
162 $this->enqueue_icon_scripts();
163 add_action( 'wp_footer', array( $this, 'include_svg_icons' ), 9999 );
164
165 /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
166 $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
167
168 echo $args['before_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
169
170 if ( ! empty( $title ) ) {
171 echo $args['before_title'] . $title . $args['after_title']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
172 }
173
174 if ( ! empty( $instance['icons'] ) ) :
175
176 // Get supported social icons.
177 $social_icons = $this->get_supported_icons();
178 $default_icon = $this->get_svg_icon( array( 'icon' => 'chain' ) );
179
180 ?>
181
182 <ul class="jetpack-social-widget-list size-<?php echo esc_attr( $instance['icon-size'] ); ?>">
183
184 <?php foreach ( $instance['icons'] as $icon ) : ?>
185
186 <?php if ( ! empty( $icon['url'] ) ) : ?>
187 <li class="jetpack-social-widget-item">
188 <?php
189 printf(
190 '<a href="%1$s" %2$s>',
191 esc_url( $icon['url'], array( 'http', 'https', 'mailto', 'sms' ) ),
192 true === $instance['new-tab'] ?
193 'target="_blank" rel="noopener noreferrer"' :
194 'target="_self"'
195 );
196
197 $found_icon = false;
198
199 foreach ( $social_icons as $social_icon ) {
200 foreach ( $social_icon['url'] as $url_fragment ) {
201 /*
202 * url_fragment can be a URL host, or a regex, starting with #.
203 * Let's check for both scenarios.
204 */
205 if (
206 // First Regex.
207 (
208 str_starts_with( $url_fragment, '#' ) && str_ends_with( $url_fragment, '#' )
209 && preg_match( $url_fragment, $icon['url'] )
210 )
211 // Then, regular host name.
212 || str_contains( $icon['url'], $url_fragment )
213 ) {
214 printf(
215 '<span class="screen-reader-text">%1$s</span>%2$s',
216 esc_attr( $social_icon['label'] ),
217 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
218 $this->get_svg_icon(
219 array(
220 'icon' => esc_attr( $social_icon['icon'] ),
221 )
222 )
223 );
224 $found_icon = true;
225 break 2;
226 }
227 }
228 }
229
230 if ( ! $found_icon ) {
231 echo $default_icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
232 }
233 ?>
234 </a>
235 </li>
236 <?php endif; ?>
237
238 <?php endforeach; ?>
239
240 </ul>
241
242 <?php
243 endif;
244
245 echo $args['after_widget']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
246
247 /** This action is documented in modules/widgets/gravatar-profile.php */
248 do_action( 'jetpack_stats_extra', 'widget_view', 'social_icons' );
249 }
250
251 /**
252 * Sanitize widget form values as they are saved.
253 *
254 * @see WP_Widget::update()
255 *
256 * @param array $new_instance Values just sent to be saved.
257 * @param array $old_instance Previously saved values from database.
258 *
259 * @return array Updated safe values to be saved.
260 */
261 public function update( $new_instance, $old_instance ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
262 $instance = array();
263
264 $instance['title'] = sanitize_text_field( $new_instance['title'] );
265 $instance['icon-size'] = $this->defaults['icon-size'];
266 $instance['url-icons'] = array_key_exists( 'url-icons', $new_instance ) ? $new_instance['url-icons'] : array();
267
268 if ( in_array( $new_instance['icon-size'], array( 'small', 'medium', 'large' ), true ) ) {
269 $instance['icon-size'] = $new_instance['icon-size'];
270 }
271
272 $instance['new-tab'] = isset( $new_instance['new-tab'] ) ? (bool) $new_instance['new-tab'] : false;
273 $instance['icons'] = array();
274
275 if ( array_key_exists( 'url-icons', $new_instance ) ) {
276 foreach ( $new_instance['url-icons'] as $url ) {
277 $url = filter_var( $url, FILTER_SANITIZE_URL );
278
279 if ( ! empty( $url ) ) {
280 $instance['icons'][] = array(
281 'url' => $url,
282 );
283 }
284 }
285 }
286
287 return $instance;
288 }
289
290 /**
291 * Back-end widget form.
292 *
293 * @see WP_Widget::form()
294 *
295 * @param array $instance Previously saved values from database.
296 *
297 * @return string|void
298 */
299 public function form( $instance ) {
300 $instance = wp_parse_args( $instance, $this->defaults );
301 $title = sanitize_text_field( $instance['title'] );
302 $sizes = array(
303 'small' => __( 'Small', 'jetpack' ),
304 'medium' => __( 'Medium', 'jetpack' ),
305 'large' => __( 'Large', 'jetpack' ),
306 );
307 $new_tab = isset( $instance['new-tab'] ) ? (bool) $instance['new-tab'] : false;
308 ?>
309
310 <p>
311 <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'jetpack' ); ?></label>
312 <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 ); ?>" />
313 </p>
314
315 <p>
316 <label for="<?php echo esc_attr( $this->get_field_id( 'icon-size' ) ); ?>"><?php esc_html_e( 'Size:', 'jetpack' ); ?></label>
317 <select class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'icon-size' ) ); ?>">
318 <?php foreach ( $sizes as $value => $label ) : ?>
319 <option value="<?php echo esc_attr( $value ); ?>" <?php selected( $value, $instance['icon-size'] ); ?>><?php echo esc_attr( $label ); ?></option>
320 <?php endforeach; ?>
321 </select>
322 </p>
323
324 <div class="jetpack-social-icons-widget-list"
325 data-url-icon-id="<?php echo esc_attr( $this->get_field_id( 'url-icons' ) ); ?>"
326 data-url-icon-name="<?php echo esc_attr( $this->get_field_name( 'url-icons' ) ); ?>"
327 >
328
329 <?php
330 foreach ( $instance['icons'] as $icon ) {
331 self::render_icons_template(
332 array(
333 'url-icon-id' => $this->get_field_id( 'url-icons' ),
334 'url-icon-name' => $this->get_field_name( 'url-icons' ),
335 'url-value' => $icon['url'],
336 )
337 );
338 }
339 ?>
340
341 </div>
342
343 <p class="jetpack-social-icons-widget add-button">
344 <button type="button" class="button jetpack-social-icons-add-button">
345 <?php esc_html_e( 'Add an icon', 'jetpack' ); ?>
346 </button>
347 </p>
348
349 <?php
350 switch ( get_locale() ) {
351 case 'es':
352 $support = 'https://es.support.wordpress.com/social-media-icons-widget/#iconos-disponibles';
353 break;
354
355 case 'pt-br':
356 $support = 'https://br.support.wordpress.com/widgets/widget-de-icones-sociais/#ícones-disponíveis';
357 break;
358
359 default:
360 $support = 'https://en.support.wordpress.com/widgets/social-media-icons-widget/#available-icons';
361 }
362 ?>
363
364 <p>
365 <em><a href="<?php echo esc_url( $support ); ?>" target="_blank" rel="noopener noreferrer">
366 <?php esc_html_e( 'View available icons', 'jetpack' ); ?>
367 </a></em>
368 </p>
369
370 <p>
371 <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 ); ?> />
372 <label for="<?php echo esc_attr( $this->get_field_id( 'new-tab' ) ); ?>"><?php esc_html_e( 'Open link in a new tab', 'jetpack' ); ?></label>
373 </p>
374
375 <?php
376 }
377
378 /**
379 * Generates template to add icons.
380 *
381 * @param array $args Template arguments.
382 */
383 private static function render_icons_template( $args = array() ) {
384 $defaults = array(
385 'url-icon-id' => '',
386 'url-icon-name' => '',
387 'url-value' => '',
388 );
389
390 $args = wp_parse_args( $args, $defaults );
391 ?>
392
393 <div class="jetpack-social-icons-widget-item">
394 <div class="jetpack-social-icons-widget-item-wrapper">
395 <div class="handle"></div>
396
397 <p class="jetpack-widget-social-icons-url">
398 <?php
399 printf(
400 '<input class="widefat" id="%1$s" name="%2$s[]" type="text" placeholder="%3$s" value="%4$s"/>',
401 esc_attr( $args['url-icon-id'] ),
402 esc_attr( $args['url-icon-name'] ),
403 esc_attr__( 'Account URL', 'jetpack' ),
404 esc_url( $args['url-value'], array( 'http', 'https', 'mailto', 'sms' ) )
405 );
406 ?>
407 </p>
408
409 <p class="jetpack-widget-social-icons-remove-item">
410 <a class="jetpack-widget-social-icons-remove-item-button" href="javascript:;">
411 <?php esc_html_e( 'Remove', 'jetpack' ); ?>
412 </a>
413 </p>
414 </div>
415 </div>
416
417 <?php
418 }
419
420 /**
421 * Return SVG markup.
422 *
423 * @param array $args {
424 * Parameters needed to display an SVG.
425 *
426 * @type string $icon Required SVG icon filename.
427 * }
428 * @return string SVG markup.
429 */
430 public function get_svg_icon( $args = array() ) {
431 // Make sure $args are an array.
432 if ( empty( $args ) ) {
433 return esc_html__( 'Please define default parameters in the form of an array.', 'jetpack' );
434 }
435
436 // Set defaults.
437 $defaults = array(
438 'icon' => '',
439 );
440
441 // Parse args.
442 $args = wp_parse_args( $args, $defaults );
443
444 // Define an icon.
445 if ( false === array_key_exists( 'icon', $args ) ) {
446 return esc_html__( 'Please define an SVG icon filename.', 'jetpack' );
447 }
448
449 // Set aria hidden.
450 $aria_hidden = ' aria-hidden="true"';
451
452 // Begin SVG markup.
453 $svg = '<svg class="icon icon-' . esc_attr( $args['icon'] ) . '"' . $aria_hidden . ' role="presentation">';
454
455 /*
456 * Display the icon.
457 *
458 * The whitespace around `<use>` is intentional - it is a work around to a keyboard navigation bug in Safari 10.
459 *
460 * See https://core.trac.wordpress.org/ticket/38387.
461 */
462 $svg .= ' <use href="#icon-' . esc_html( $args['icon'] ) . '" xlink:href="#icon-' . esc_html( $args['icon'] ) . '"></use> ';
463
464 $svg .= '</svg>';
465
466 return $svg;
467 }
468
469 /**
470 * Returns an array of supported social links (URL, icon, and label).
471 *
472 * @return array $social_links_icons
473 */
474 public function get_supported_icons() {
475 $social_links_icons = array(
476 array(
477 'url' => array( '500px.com' ),
478 'icon' => '500px',
479 'label' => '500px',
480 ),
481 array(
482 'url' => array(
483 '#https?:\/\/(www\.)?amazon\.(com|cn|in|fr|de|it|nl|es|co|ca)\/#',
484 ),
485 'icon' => 'amazon',
486 'label' => 'Amazon',
487 ),
488 array(
489 'url' => array( 'apple.com' ),
490 'icon' => 'apple',
491 'label' => 'Apple',
492 ),
493 array(
494 'url' => array( 'itunes.com' ),
495 'icon' => 'apple',
496 'label' => 'iTunes',
497 ),
498 array(
499 'url' => array( 'bandcamp.com' ),
500 'icon' => 'bandcamp',
501 'label' => 'Bandcamp',
502 ),
503 array(
504 'url' => array( 'behance.net' ),
505 'icon' => 'behance',
506 'label' => 'Behance',
507 ),
508 array(
509 'url' => array(
510 'blogger.com',
511 'blogspot.com',
512 ),
513 'icon' => 'blogger',
514 'label' => 'Blogger',
515 ),
516 array(
517 'url' => array( 'bsky.app' ),
518 'icon' => 'bluesky',
519 'label' => 'Bluesky',
520 ),
521 array(
522 'url' => array( 'codepen.io' ),
523 'icon' => 'codepen',
524 'label' => 'CodePen',
525 ),
526 array(
527 'url' => array( 'deviantart.com' ),
528 'icon' => 'deviantart',
529 'label' => 'DeviantArt',
530 ),
531 array(
532 'url' => array( 'digg.com' ),
533 'icon' => 'digg',
534 'label' => 'Digg',
535 ),
536 array(
537 'url' => array( '#discord\.gg|discordapp\.com#' ),
538 'icon' => 'discord',
539 'label' => 'Discord',
540 ),
541 array(
542 'url' => array( 'dribbble.com' ),
543 'icon' => 'dribbble',
544 'label' => 'Dribbble',
545 ),
546 array(
547 'url' => array( 'dropbox.com' ),
548 'icon' => 'dropbox',
549 'label' => 'Dropbox',
550 ),
551 array(
552 'url' => array( 'etsy.com' ),
553 'icon' => 'etsy',
554 'label' => 'Etsy',
555 ),
556 array(
557 'url' => array( 'eventbrite.com' ),
558 'icon' => 'eventbrite',
559 'label' => 'Eventbrite',
560 ),
561 array(
562 'url' => array( 'facebook.com' ),
563 'icon' => 'facebook',
564 'label' => 'Facebook',
565 ),
566 array(
567 'url' => array( 'flickr.com' ),
568 'icon' => 'flickr',
569 'label' => 'Flickr',
570 ),
571 array(
572 'url' => array( 'foursquare.com' ),
573 'icon' => 'foursquare',
574 'label' => 'Foursquare',
575 ),
576 array(
577 'url' => array( 'ghost.org' ),
578 'icon' => 'ghost',
579 'label' => 'Ghost',
580 ),
581 array(
582 'url' => array( 'goodreads.com' ),
583 'icon' => 'goodreads',
584 'label' => 'Goodreads',
585 ),
586 array(
587 'url' => array( '#google\.(com|co\.uk|ca|cn|it)#' ),
588 'icon' => 'google',
589 'label' => 'Google',
590 ),
591 array(
592 'url' => array( 'github.com' ),
593 'icon' => 'github',
594 'label' => 'GitHub',
595 ),
596 array(
597 'url' => array( 'instagram.com' ),
598 'icon' => 'instagram',
599 'label' => 'Instagram',
600 ),
601 array(
602 'url' => array( 'linkedin.com' ),
603 'icon' => 'linkedin',
604 'label' => 'LinkedIn',
605 ),
606 array(
607 'url' => array( 'mailto:' ),
608 'icon' => 'mail',
609 'label' => __( 'Email', 'jetpack' ),
610 ),
611 array(
612 'url' => jetpack_mastodon_get_instance_list(),
613 'icon' => 'mastodon',
614 'label' => 'Mastodon',
615 ),
616 array(
617 'url' => array( 'meetup.com' ),
618 'icon' => 'meetup',
619 'label' => 'Meetup',
620 ),
621 array(
622 'url' => array( 'medium.com' ),
623 'icon' => 'medium',
624 'label' => 'Medium',
625 ),
626 array(
627 'url' => array( 'nextdoor.com' ),
628 'icon' => 'nextdoor',
629 'label' => 'Nextdoor',
630 ),
631 array(
632 'url' => array( 'patreon.com' ),
633 'icon' => 'patreon',
634 'label' => 'Patreon',
635 ),
636 array(
637 'url' => array( 'pinterest.' ),
638 'icon' => 'pinterest',
639 'label' => 'Pinterest',
640 ),
641 array(
642 'url' => array( 'getpocket.com' ),
643 'icon' => 'pocket',
644 'label' => 'Pocket',
645 ),
646 array(
647 'url' => array( 'ravelry.com' ),
648 'icon' => 'ravelry',
649 'label' => 'Ravelry',
650 ),
651 array(
652 'url' => array( 'reddit.com' ),
653 'icon' => 'reddit',
654 'label' => 'Reddit',
655 ),
656 array(
657 'url' => array( 'slideshare.net' ),
658 'icon' => 'slideshare',
659 'label' => 'SlideShare',
660 ),
661 array(
662 'url' => array( 'sms:' ),
663 'icon' => 'sms',
664 'label' => 'SMS',
665 ),
666 array(
667 'url' => array( 'snapchat.com' ),
668 'icon' => 'snapchat',
669 'label' => 'Snapchat',
670 ),
671 array(
672 'url' => array( 'soundcloud.com' ),
673 'icon' => 'soundcloud',
674 'label' => 'SoundCloud',
675 ),
676 array(
677 'url' => array( 'spotify.com' ),
678 'icon' => 'spotify',
679 'label' => 'Spotify',
680 ),
681 array(
682 'url' => array( 'stackoverflow.com' ),
683 'icon' => 'stackoverflow',
684 'label' => 'Stack Overflow',
685 ),
686 array(
687 'url' => array( 'strava.com' ),
688 'icon' => 'strava',
689 'label' => 'Strava',
690 ),
691 array(
692 'url' => array( 'stumbleupon.com' ),
693 'icon' => 'stumbleupon',
694 'label' => 'StumbleUpon',
695 ),
696 array(
697 'url' => array( '#https?:\/\/(www\.)?(telegram|t)\.me#' ),
698 'icon' => 'telegram',
699 'label' => 'Telegram',
700 ),
701 array(
702 'url' => array( 'threads.net' ),
703 'icon' => 'threads',
704 'label' => 'Threads',
705 ),
706 array(
707 'url' => array( 'tiktok.com' ),
708 'icon' => 'tiktok',
709 'label' => 'TikTok',
710 ),
711 array(
712 'url' => array( 'tumblr.com' ),
713 'icon' => 'tumblr',
714 'label' => 'Tumblr',
715 ),
716 array(
717 'url' => array( 'twitch.tv' ),
718 'icon' => 'twitch',
719 'label' => 'Twitch',
720 ),
721 array(
722 'url' => array( 'vimeo.com' ),
723 'icon' => 'vimeo',
724 'label' => 'Vimeo',
725 ),
726 array(
727 'url' => array( 'vk.com' ),
728 'icon' => 'vk',
729 'label' => 'VK',
730 ),
731 array(
732 'url' => array( 'whatsapp.com' ),
733 'icon' => 'whatsapp',
734 'label' => 'WhatsApp',
735 ),
736 array(
737 'url' => array( 'woocommerce.com' ),
738 'icon' => 'woocommerce',
739 'label' => 'WooCommerce',
740 ),
741 array(
742 'url' => array( '#wordpress\.(com|org)#' ),
743 'icon' => 'wordpress',
744 'label' => 'WordPress',
745 ),
746 array(
747 'url' => array( 'yelp.com' ),
748 'icon' => 'yelp',
749 'label' => 'Yelp',
750 ),
751 array(
752 'url' => array( '#^https?:\/\/(www\.)?(twitter|x)\.com#' ),
753 'icon' => 'x',
754 'label' => 'X',
755 ),
756 array(
757 'url' => array( 'xanga.com' ),
758 'icon' => 'xanga',
759 'label' => 'Xanga',
760 ),
761 array(
762 'url' => array( 'youtube.com' ),
763 'icon' => 'youtube',
764 'label' => 'YouTube',
765 ),
766
767 // keep feed at the end so that more specific icons can take precedence.
768 array(
769 'url' => array(
770 '/feed/', // WordPress default feed url.
771 '/feeds/', // Blogspot and others.
772 '/blog/feed', // No trailing slash WordPress feed, could use /feed but may match unexpectedly.
773 'format=RSS', // Squarespace and others.
774 '/rss', // Tumblr.
775 '/.rss', // Reddit.
776 '/rss.xml', // Moveable Type, Typepad.
777 'http://rss.', // Old custom format.
778 'https://rss.', // Old custom format.
779 'rss=1',
780 '/feed=rss', // Catches feed=rss / feed=rss2.
781 '?feed=rss', // WordPress non-permalink - Catches feed=rss / feed=rss2.
782 '?feed=rdf', // WordPress non-permalink.
783 '?feed=atom', // WordPress non-permalink.
784 'http://feeds.', // FeedBurner.
785 'https://feeds.', // FeedBurner.
786 '/feed.xml', // Feedburner Alias, and others.
787 '/index.xml', // Moveable Type, and others.
788 '/atom.xml', // Typepad, Squarespace.
789 '.atom', // Shopify blog.
790 '/atom', // Some non-WordPress feeds.
791 'index.rdf', // Typepad.
792 ),
793 'icon' => 'feed',
794 'label' => __( 'RSS Feed', 'jetpack' ),
795 ),
796 );
797
798 /**
799 * Filter the list of services matching Social Media Icons available in the Social Icons SVG sprite.
800 *
801 * @since 12.3
802 *
803 * @param array $social_links_icons Array of social links icons.
804 */
805 return apply_filters(
806 'jetpack_social_icons_supported_icons',
807 $social_links_icons
808 );
809 }
810 } // Jetpack_Widget_Social_Icons
811
812 /**
813 * Register and load the widget.
814 *
815 * @access public
816 * @return void
817 */
818 function jetpack_widget_social_icons_load() {
819 register_widget( 'Jetpack_Widget_Social_Icons' );
820 }
821 add_action( 'widgets_init', 'jetpack_widget_social_icons_load' );
822