-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgoliath-add-social-media-link.php
159 lines (123 loc) · 3.73 KB
/
goliath-add-social-media-link.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
<?php
/**
*
* Plugin Name: Goliath Add Social Media Link
* Description: Add the social media link
* Version: 1.0
* Author: Studio Goliath
* Author URI: https://www.studio-goliath.com
*
* SVG sprite from :
* https://github.com/Automattic/social-logos
*
*
*/
class GoliathAddSocialMediaLink
{
private $supported_social_media;
public function __construct()
{
$this->supported_social_media = apply_filters( 'asml_supported_social_media', array(
'amazon',
'behance',
'blogger-alt',
'blogger',
'codepen',
'dribbble',
'dropbox',
'eventbrite',
'facebook',
'facebook-alt',
'feed',
'flickr',
'foursquare',
'ghost',
'github',
'google-alt',
'google-plus-alt',
'google-plus',
'google',
'instagram',
'linkedin',
'mail',
'medium',
'path-alt',
'path',
'pinterest-alt',
'pinterest',
'pocket',
'polldaddy',
'print',
'reddit',
'share',
'skype',
'spotify',
'squarespace',
'stumbleupon',
'telegram',
'tumblr-alt',
'tumblr',
'twitch',
'twitter-alt',
'twitter',
'vimeo',
'whatsapp',
'wordpress',
'xanga',
'youtube',
) );
}
public function init(){
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
add_action( 'customize_register', array( $this, 'customize_register' ) );
}
public function enqueue_scripts() {
wp_enqueue_script( 'goliath_asml_js', plugins_url( '/js/scripts.js', __FILE__ ), array(), '1.0', true);
// localize
wp_localize_script( 'goliath_asml_js', 'scripts_l10n', array(
'svgSpriteUrl' => plugins_url( '/svg/social-logos.svg', __FILE__ ),
) );
}
public function customize_register( $wp_customize ) {
foreach ( $this->supported_social_media as $social_media ){
$wp_customize->add_setting( $social_media, array(
'type' => 'theme_mod',
'capability' => 'edit_theme_options',
'sanitize_callback' => 'esc_url_raw',
) );
$wp_customize->add_control( $social_media, array(
'type' => 'url',
'section' => 'asml_section',
'label' => $social_media,
) );
}
$wp_customize->add_section( 'asml_section', array(
'title' => __( 'Social Media Link', 'asml' ),
'capability' => 'edit_theme_options',
) );
}
/**
* @return array
*/
public function getSupportedSocialMedia()
{
return $this->supported_social_media;
}
}
add_action( 'init', function(){
$asml = new GoliathAddSocialMediaLink();
$asml->init();
});
function asml_social_media_menu( $target = '' ){
$asml = new GoliathAddSocialMediaLink();
$all_supported_social_media = $asml->getSupportedSocialMedia();
echo '<div class="social-media-link">';
foreach ( $all_supported_social_media as $social_media ){
$social_media_url = get_theme_mod( $social_media );
if( $social_media_url ){
$target_string = $target ? " target='$target'" : '';
echo "<a href='{$social_media_url}' class='social-link'" . $target_string ."><svg class='icon icon-social'><use xlink:href='#{$social_media}'></use></svg></a>";
}
}
echo '</div>';
}