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