-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathsimple-social-icons.php
676 lines (583 loc) · 26.9 KB
/
simple-social-icons.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
<?php
/**
* Plugin Name: Simple Social Icons
* Plugin URI: https://wordpress.org/plugins/simple-social-icons/
* Description: A simple CSS and SVG driven social icons widget.
* Author: OsomPress
* Author URI: https://www.osompress.com/
* Version: 3.2.5
* Text Domain: simple-social-icons
* Domain Path: /languages
*
* License: GNU General Public License v2.0 (or later)
* License URI: https://www.opensource.org/licenses/gpl-license.php
*
* @package simple-social-icons
*/
add_action( 'plugins_loaded', 'simple_social_icons_load_textdomain' );
/**
* Load textdomain
*/
function simple_social_icons_load_textdomain() {
load_plugin_textdomain( 'simple-social-icons', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
}
/**
* The Simple Social Icons widget.
*/
class Simple_Social_Icons_Widget extends WP_Widget {
/**
* Plugin version for enqueued static resources.
*
* @var string
*/
protected $version = '3.0.2';
/**
* Default widget values.
*
* @var array
*/
protected $defaults;
/**
* Default widget values.
*
* @var array
*/
protected $sizes;
/**
* Default widget profile values.
*
* @var array
*/
protected $profiles;
/**
* Array of widget instance IDs. Used to generate CSS.
*
* @var array
*/
protected $active_instances;
/**
* Controls custom css output.
*
* @var bool
*/
protected $disable_css_output;
/**
* Constructor method.
*
* Set some global values and create widget.
*/
public function __construct() {
/**
* Filter for default widget option values.
*
* @since 1.0.6
*
* @param array $defaults Default widget options.
*/
$this->defaults = apply_filters(
'simple_social_default_styles',
array(
'title' => '',
'new_window' => 0,
'size' => 36,
'border_radius' => 3,
'border_width' => 0,
'border_color' => '#ffffff',
'border_color_hover' => '#ffffff',
'icon_color' => '#ffffff',
'icon_color_hover' => '#ffffff',
'background_color' => '#999999',
'background_color_hover' => '#666666',
'alignment' => 'alignleft',
'amazon' => '',
'behance' => '',
'bloglovin' => '',
'bluesky' => '',
'diaspora' => '',
'dribbble' => '',
'email' => '',
'etsy' => '',
'facebook' => '',
'flickr' => '',
'github' => '',
'goodreads' => '',
'instagram' => '',
'linkedin' => '',
'mastodon' => '',
'medium' => '',
'meetup' => '',
'periscope' => '',
'phone' => '',
'pinterest' => '',
'reddit' => '',
'rss' => '',
'snapchat' => '',
'substack' => '',
'telegram' => '',
'threads' => '',
'tiktok' => '',
'tripadvisor' => '',
'tumblr' => '',
'twitter' => '',
'vimeo' => '',
'whatsapp' => '',
'xing' => '',
'youtube' => '',
)
);
/**
* Filter for social profile choices.
*
* @since 1.0.6
*
* @param array $profiles Social icons to include in widget options.
*/
$this->profiles = apply_filters(
'simple_social_default_profiles',
array(
'amazon' => array(
'label' => __( 'Amazon URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'amazon', __( 'Amazon', 'simple-social-icons' ) ),
),
'behance' => array(
'label' => __( 'Behance URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'behance', __( 'Behance', 'simple-social-icons' ) ),
),
'bloglovin' => array(
'label' => __( 'Bloglovin URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'bloglovin', __( 'Bloglovin', 'simple-social-icons' ) ),
),
'bluesky' => array(
'label' => __( 'Bluesky URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'bluesky', __( 'Bluesky', 'simple-social-icons' ) ),
),
'diaspora' => array(
'label' => __( 'Diaspora URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'diaspora', __( 'Diaspora', 'simple-social-icons' ) ),
),
'dribbble' => array(
'label' => __( 'Dribbble URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'dribbble', __( 'Dribbble', 'simple-social-icons' ) ),
),
'email' => array(
'label' => __( 'Email URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'email', __( 'Email', 'simple-social-icons' ) ),
),
'etsy' => array(
'label' => __( 'Etsy URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'etsy', __( 'Etsy', 'simple-social-icons' ) ),
),
'facebook' => array(
'label' => __( 'Facebook URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'facebook', __( 'Facebook', 'simple-social-icons' ) ),
),
'flickr' => array(
'label' => __( 'Flickr URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'flickr', __( 'Flickr', 'simple-social-icons' ) ),
),
'github' => array(
'label' => __( 'GitHub URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'github', __( 'GitHub', 'simple-social-icons' ) ),
),
'goodreads' => array(
'label' => __( 'Goodreads URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'goodreads', __( 'Goodreads', 'simple-social-icons' ) ),
),
'instagram' => array(
'label' => __( 'Instagram URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'instagram', __( 'Instagram', 'simple-social-icons' ) ),
),
'linkedin' => array(
'label' => __( 'Linkedin URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'linkedin', __( 'LinkedIn', 'simple-social-icons' ) ),
),
'mastodon' => array(
'label' => __( 'Mastodon URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'mastodon', __( 'Mastodon', 'simple-social-icons' ) ),
),
'medium' => array(
'label' => __( 'Medium URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'medium', __( 'Medium', 'simple-social-icons' ) ),
),
'meetup' => array(
'label' => __( 'Meetup URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'meetup', __( 'Meetup', 'simple-social-icons' ) ),
),
'periscope' => array(
'label' => __( 'Periscope URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'periscope', __( 'Periscope', 'simple-social-icons' ) ),
),
'phone' => array(
'label' => __( 'Phone URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'phone', __( 'Phone', 'simple-social-icons' ) ),
),
'pinterest' => array(
'label' => __( 'Pinterest URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'pinterest', __( 'Pinterest', 'simple-social-icons' ) ),
),
'reddit' => array(
'label' => __( 'Reddit URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'reddit', __( 'Reddit', 'simple-social-icons' ) ),
),
'rss' => array(
'label' => __( 'RSS URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'rss', __( 'RSS', 'simple-social-icons' ) ),
),
'snapchat' => array(
'label' => __( 'Snapchat URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'snapchat', __( 'Snapchat', 'simple-social-icons' ) ),
),
'substack' => array(
'label' => __( 'Substack URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'substack', __( 'Substack', 'simple-social-icons' ) ),
),
'telegram' => array(
'label' => __( 'Telegram URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'telegram', __( 'Telegram', 'simple-social-icons' ) ),
),
'threads' => array(
'label' => __( 'Threads URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'threads', __( 'Threads', 'simple-social-icons' ) ),
),
'tiktok' => array(
'label' => __( 'TikTok URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'tiktok', __( 'TikTok', 'simple-social-icons' ) ),
),
'tripadvisor' => array(
'label' => __( 'Tripadvisor URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'tripadvisor', __( 'Tripadvisor', 'simple-social-icons' ) ),
),
'tumblr' => array(
'label' => __( 'Tumblr URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'tumblr', __( 'Tumblr', 'simple-social-icons' ) ),
),
'twitter' => array(
'label' => __( 'X URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'twitter', __( 'Twitter', 'simple-social-icons' ) ),
),
'vimeo' => array(
'label' => __( 'Vimeo URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'vimeo', __( 'Vimeo', 'simple-social-icons' ) ),
),
'whatsapp' => array(
'label' => __( 'WhatsApp URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'whatsapp', __( 'WhatsApp', 'simple-social-icons' ) ),
),
'xing' => array(
'label' => __( 'Xing URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'xing', __( 'xing', 'simple-social-icons' ) ),
),
'youtube' => array(
'label' => __( 'YouTube URI', 'simple-social-icons' ),
'pattern' => $this->get_icon_markup( 'youtube', __( 'YouTube', 'simple-social-icons' ) ),
),
)
);
/**
* Filter to disable output of custom CSS.
*
* Setting this to true in your child theme will:
* - Stop output of inline custom icon CSS.
* - Stop styling options showing in Simple Social Icons widget settings.
*
* The intent if enabling is that your theme will provide CSS for all
* widget areas, instead of allowing people to set their own icon
* styles. You should consider mentioning in theme documentation that
* Simple Social Icons widget settings will not display styling
* options, as your theme styles icons instead.
*
* @since 3.0.0
*
* @param bool $disable_css_output True if custom CSS should be disabled.
*/
$this->disable_css_output = apply_filters( 'simple_social_disable_custom_css', false );
$widget_ops = array(
'classname' => 'simple-social-icons',
'description' => __( 'Displays select social icons.', 'simple-social-icons' ),
);
$control_ops = array(
'id_base' => 'simple-social-icons',
);
$this->active_instances = array();
parent::__construct( 'simple-social-icons', __( 'Simple Social Icons', 'simple-social-icons' ), $widget_ops, $control_ops );
/** Enqueue scripts and styles */
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_css' ) );
/** Load CSS in <head> */
add_action( 'wp_footer', array( $this, 'css' ) );
/** Load color picker */
add_action( 'admin_enqueue_scripts', array( $this, 'load_color_picker' ) );
add_action( 'admin_footer-widgets.php', array( $this, 'print_scripts' ), 9999 );
}
/**
* Color Picker.
*
* Enqueue the color picker script.
*
* @param string $hook The current admin page.
*/
public function load_color_picker( $hook ) {
if ( 'widgets.php' !== $hook ) {
return;
}
wp_enqueue_style( 'wp-color-picker' );
wp_enqueue_script( 'wp-color-picker' );
wp_enqueue_script( 'underscore' );
}
/**
* Print scripts.
*
* Reference https://core.trac.wordpress.org/attachment/ticket/25809/color-picker-widget.php
*/
public function print_scripts() {
?>
<script>
( function( $ ){
function initColorPicker( widget ) {
widget.find( '.ssiw-color-picker' ).wpColorPicker( {
change: function ( event ) {
var $picker = $( this );
_.throttle(setTimeout(function () {
$picker.trigger( 'change' );
}, 5), 250);
},
width: 235,
});
}
function onFormUpdate( event, widget ) {
initColorPicker( widget );
}
$( document ).on( 'widget-added widget-updated', onFormUpdate );
$( document ).ready( function() {
$( '#widgets-right .widget:has(.ssiw-color-picker)' ).each( function () {
initColorPicker( $( this ) );
} );
} );
}( jQuery ) );
</script>
<?php
}
/**
* Widget Form.
*
* Outputs the widget form that allows users to control the output of the widget.
*
* @param array $instance The widget settings.
*/
public function form( $instance ) {
/** Merge with defaults */
$instance = wp_parse_args( (array) $instance, $this->defaults );
?>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php esc_html_e( 'Title:', 'simple-social-icons' ); ?></label> <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( $instance['title'] ); ?>" /></p>
<p><label><input id="<?php echo esc_attr( $this->get_field_id( 'new_window' ) ); ?>" type="checkbox" name="<?php echo esc_attr( $this->get_field_name( 'new_window' ) ); ?>" value="1" <?php checked( 1, $instance['new_window'] ); ?>/> <?php esc_html_e( 'Open links in new window?', 'simple-social-icons' ); ?></label></p>
<?php if ( ! $this->disable_css_output ) { ?>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>"><?php esc_html_e( 'Icon Size', 'simple-social-icons' ); ?>:</label> <input id="<?php echo esc_attr( $this->get_field_id( 'size' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'size' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['size'] ); ?>" size="3" />px</p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'border_radius' ) ); ?>"><?php esc_html_e( 'Icon Border Radius:', 'simple-social-icons' ); ?></label> <input id="<?php echo esc_attr( $this->get_field_id( 'border_radius' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'border_radius' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['border_radius'] ); ?>" size="3" />px</p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'border_width' ) ); ?>"><?php esc_html_e( 'Border Width:', 'simple-social-icons' ); ?></label> <input id="<?php echo esc_attr( $this->get_field_id( 'border_width' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'border_width' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['border_width'] ); ?>" size="3" />px</p>
<p>
<label for="<?php echo esc_attr( $this->get_field_id( 'alignment' ) ); ?>"><?php esc_html_e( 'Alignment', 'simple-social-icons' ); ?>:</label>
<select id="<?php echo esc_attr( $this->get_field_id( 'alignment' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'alignment' ) ); ?>">
<option value="alignleft" <?php selected( 'alignright', $instance['alignment'] ); ?>><?php esc_html_e( 'Align Left', 'simple-social-icons' ); ?></option>
<option value="aligncenter" <?php selected( 'aligncenter', $instance['alignment'] ); ?>><?php esc_html_e( 'Align Center', 'simple-social-icons' ); ?></option>
<option value="alignright" <?php selected( 'alignright', $instance['alignment'] ); ?>><?php esc_html_e( 'Align Right', 'simple-social-icons' ); ?></option>
</select>
</p>
<hr style="background: #ccc; border: 0; height: 1px; margin: 20px 0;" />
<p><label for="<?php echo esc_attr( $this->get_field_id( 'background_color' ) ); ?>"><?php esc_html_e( 'Icon Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'icon_color' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'icon_color' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['icon_color'] ); ?>" value="<?php echo esc_attr( $instance['icon_color'] ); ?>" size="6" /></p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'background_color_hover' ) ); ?>"><?php esc_html_e( 'Icon Hover Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'icon_color_hover' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'icon_color_hover' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['icon_color_hover'] ); ?>" value="<?php echo esc_attr( $instance['icon_color_hover'] ); ?>" size="6" /></p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'background_color' ) ); ?>"><?php esc_html_e( 'Background Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'background_color' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'background_color' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['background_color'] ); ?>" value="<?php echo esc_attr( $instance['background_color'] ); ?>" size="6" /></p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'background_color_hover' ) ); ?>"><?php esc_html_e( 'Background Hover Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'background_color_hover' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'background_color_hover' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['background_color_hover'] ); ?>" value="<?php echo esc_attr( $instance['background_color_hover'] ); ?>" size="6" /></p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'border_color' ) ); ?>"><?php esc_html_e( 'Border Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'border_color' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'border_color' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['border_color'] ); ?>" value="<?php echo esc_attr( $instance['border_color'] ); ?>" size="6" /></p>
<p><label for="<?php echo esc_attr( $this->get_field_id( 'border_color_hover' ) ); ?>"><?php esc_html_e( 'Border Hover Color:', 'simple-social-icons' ); ?></label><br /> <input id="<?php echo esc_attr( $this->get_field_id( 'border_color_hover' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'border_color_hover' ) ); ?>" type="text" class="ssiw-color-picker" data-default-color="<?php echo esc_attr( $this->defaults['border_color_hover'] ); ?>" value="<?php echo esc_attr( $instance['border_color_hover'] ); ?>" size="6" /></p>
<hr style="background: #ccc; border: 0; height: 1px; margin: 20px 0;" />
<?php } ?>
<?php
foreach ( (array) $this->profiles as $profile => $data ) {
printf( '<p><label for="%s">%s:</label></p>', esc_attr( $this->get_field_id( $profile ) ), esc_attr( $data['label'] ) );
printf( '<p><input type="text" id="%s" name="%s" value="%s" class="widefat" />', esc_attr( $this->get_field_id( $profile ) ), esc_attr( $this->get_field_name( $profile ) ), esc_attr( $instance[ $profile ] ) );
printf( '</p>' );
}
}
/**
* Form validation and sanitization.
*
* Runs when you save the widget form. Allows you to validate or sanitize widget options before they are saved.
*
* @param array $newinstance The new settings.
* @param array $oldinstance The old settings.
* @return array The settings to save.
*/
public function update( $newinstance, $oldinstance ) {
// Fields that can be transparent if their values are unset.
$can_be_transparent = array(
'background_color',
'background_color_hover',
'border_color',
'border_color_hover',
);
foreach ( $newinstance as $key => $value ) {
/** Border radius and Icon size must not be empty, must be a digit */
if ( ( 'border_radius' === $key || 'size' === $key ) && ( '' === $value || ! ctype_digit( $value ) ) ) {
$newinstance[ $key ] = 0;
}
if ( ( 'border_width' === $key || 'size' === $key ) && ( '' === $value || ! ctype_digit( $value ) ) ) {
$newinstance[ $key ] = 0;
} elseif ( in_array( $key, $can_be_transparent, true ) && '' === trim( $value ) ) {
// Accept empty colors for permitted keys.
$newinstance[ $key ] = '';
} elseif ( strpos( $key, '_color' ) && 0 === preg_match( '/^#(([a-fA-F0-9]{3}$)|([a-fA-F0-9]{6}$))/', $value ) ) {
// Validate hex code colors.
$newinstance[ $key ] = $oldinstance[ $key ];
} elseif ( array_key_exists( $key, (array) $this->profiles ) && ! is_email( $value ) && ! 'phone' === $key ) {
// Sanitize Profile URIs.
$newinstance[ $key ] = esc_url( $newinstance[ $key ] );
}
}
return $newinstance;
}
/**
* Widget Output.
*
* Outputs the actual widget on the front-end based on the widget options the user selected.
*
* @param array $args The display args.
* @param array $instance The instance settings.
*/
public function widget( $args, $instance ) {
/** Merge with defaults */
$instance = wp_parse_args( (array) $instance, $this->defaults );
echo $args['before_widget']; // phpcs:ignore
if ( ! empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $args['after_title']; // phpcs:ignore
}
$output = '';
$profiles = (array) $this->profiles;
foreach ( $profiles as $profile => $data ) {
if ( empty( $instance[ $profile ] ) ) {
continue;
}
$new_window = $instance['new_window'] ? 'target="_blank" rel="noopener noreferrer"' : '';
if ( is_email( $instance[ $profile ] ) || false !== strpos( $instance[ $profile ], 'mailto:' ) ) {
$new_window = '';
}
if ( is_email( $instance[ $profile ] ) ) {
$output .= sprintf( $data['pattern'], 'mailto:' . esc_attr( antispambot( $instance[ $profile ] ) ), $new_window );
} elseif ( 'phone' === $profile ) {
$output .= sprintf( $data['pattern'], 'tel:' . esc_attr( antispambot( $instance[ $profile ] ) ), $new_window );
} else {
$output .= sprintf( $data['pattern'], esc_url( $instance[ $profile ] ), $new_window );
}
}
if ( $output ) {
$output = str_replace( '{WIDGET_INSTANCE_ID}', $this->number, $output );
printf( '<ul class="%s">%s</ul>', esc_attr( $instance['alignment'] ), $output ); // phpcs:ignore
}
echo $args['after_widget']; // phpcs:ignore
$this->active_instances[] = $this->number;
}
/**
* Enqueues the CSS.
*/
public function enqueue_css() {
/**
* Filter the plugin stylesheet location.
*
* @since 2.0.0
*
* @param string $cssfile The full path to the stylesheet.
*/
$cssfile = apply_filters( 'simple_social_default_stylesheet', plugin_dir_url( __FILE__ ) . 'css/style.css' );
wp_enqueue_style( 'simple-social-icons-font', esc_url( $cssfile ), array(), $this->version, 'all' );
}
/**
* Custom CSS.
*
* Outputs custom CSS to control the look of the icons.
*/
public function css() {
/** Pull widget settings, merge with defaults */
$all_instances = $this->get_settings();
$css = '';
foreach ( $this->active_instances as $instance_id ) {
// Skip if info for this instance does not exist - this should never happen.
if ( ! isset( $all_instances[ $instance_id ] ) || $this->disable_css_output ) {
continue;
}
$instance = wp_parse_args( $all_instances[ $instance_id ], $this->defaults );
$font_size = round( (int) $instance['size'] / 2 );
$icon_padding = round( (int) $font_size / 2 );
// Treat empty background and border colors as transparent.
$instance['background_color'] = $instance['background_color'] ?: 'transparent';
$instance['border_color'] = $instance['border_color'] ?: 'transparent';
$instance['background_color_hover'] = $instance['background_color_hover'] ?: 'transparent';
$instance['border_color_hover'] = $instance['border_color_hover'] ?: 'transparent';
/** The CSS to output */
$css .= '
#simple-social-icons-' . $instance_id . ' ul li a,
#simple-social-icons-' . $instance_id . ' ul li a:hover,
#simple-social-icons-' . $instance_id . ' ul li a:focus {
background-color: ' . $instance['background_color'] . ' !important;
border-radius: ' . $instance['border_radius'] . 'px;
color: ' . $instance['icon_color'] . ' !important;
border: ' . $instance['border_width'] . 'px ' . $instance['border_color'] . ' solid !important;
font-size: ' . $font_size . 'px;
padding: ' . $icon_padding . 'px;
}
#simple-social-icons-' . $instance_id . ' ul li a:hover,
#simple-social-icons-' . $instance_id . ' ul li a:focus {
background-color: ' . $instance['background_color_hover'] . ' !important;
border-color: ' . $instance['border_color_hover'] . ' !important;
color: ' . $instance['icon_color_hover'] . ' !important;
}
#simple-social-icons-' . $instance_id . ' ul li a:focus {
outline: 1px dotted ' . $instance['background_color_hover'] . ' !important;
}';
}
// Minify a bit.
$css = str_replace( "\t", '', $css );
$css = str_replace( array( "\n", "\r" ), ' ', $css );
echo '<style type="text/css" media="screen">' . wp_strip_all_tags( $css ) . '</style>'; // phpcs:ignore
}
/**
* Construct the markup for each icon
*
* @param string $icon The lowercase icon name for use in tag attributes.
* @param string $label The plain text icon label.
*
* @return string The full markup for the given icon.
*/
public function get_icon_markup( $icon, $label ) {
$markup = '<li class="ssi-' . esc_attr( $icon ) . '"><a href="%s" %s>';
$markup .= '<svg role="img" class="social-' . esc_attr( $icon ) . '" aria-labelledby="social-' . esc_attr( $icon ) . '-{WIDGET_INSTANCE_ID}">';
$markup .= '<title id="social-' . esc_attr( $icon ) . '-{WIDGET_INSTANCE_ID}">' . esc_html( $label ) . '</title>';
$markup .= '<use xlink:href="' . esc_attr( plugin_dir_url( __FILE__ ) . 'symbol-defs.svg#social-' . $icon ) . '"></use>';
$markup .= '</svg></a></li>';
/**
* Filter the icon markup HTML.
*
* @since 3.0.0
*
* @param string $markup The full HTML markup for a single icon.
* @param string $icon The lowercase icon name used in tag attributes.
* @param string $label The plain text icon label.
*/
return apply_filters( 'simple_social_icon_html', $markup, $icon, $label );
}
/**
* Remove option when uninstalling the plugin.
*
* @since 2.1.0
*/
public static function plugin_uninstall() {
delete_option( 'widget_simple-social-icons' );
}
}
register_uninstall_hook( __FILE__, array( 'Simple_Social_Icons_Widget', 'plugin_uninstall' ) );
add_action( 'widgets_init', 'ssiw_load_widget' );
/**
* Widget Registration.
*
* Register Simple Social Icons widget.
*/
function ssiw_load_widget() {
register_widget( 'Simple_Social_Icons_Widget' );
}