/
pl2x-social-icons.php
129 lines (111 loc) · 3.09 KB
/
pl2x-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
<?php
/**
* Plugin Name: PL2X Social Icons
* Description: Add Simple Social icons
* Author: Evan Mattson (@aaemnnosttv)
* Author URI: https://aaemnnost.tv
* Version: 2.0
*
* GitHub Plugin URI: PL2X/pl2x-social-icons
*/
namespace PL2X;
class SocialIcons
{
const version = '2.0';
public function __construct()
{
$this->uri = plugins_url('', __FILE__);
$this->dir = plugin_dir_path( __FILE__ );
}
public function hooks()
{
add_action('init', array($this, 'init'));
add_action('wp_enqueue_scripts', array($this, 'enqueue'));
add_action('pagelines_setup', array($this, 'add_social_options'));
}
public function init()
{
wp_register_style('social-icons', "{$this->uri}/social-icons.css" , array(), self::version);
add_shortcode('social_icons', array($this, 'shortcode'));
}
public function add_social_options()
{
$options = array(
'social_profiles' => array(
'title' => 'Social Profiles',
'type' => 'multi_option',
'selectvalues' => $this->get_options()
),
);
pl_add_options_page( array(
'name' => 'Social_Icons/Profiles',
'array' => $options,
) );
}
public function enqueue()
{
wp_enqueue_style('social-icons');
}
public function shortcode( $atts, $content, $tag )
{
$data = array();
foreach ( $this->get_options() as $key => $o )
{
$value = ploption( $key );
if ( $value )
$data[ $key ] = sprintf( $o['format'], $value );
}
$data = array_filter( $data );
if ( empty( $data ) )
return '';
else
{
$icons = implode("\n", $data);
return "<div class='social-icons'>$icons</div>";
}
}
public function get_options()
{
return array(
'facebook_id' => array(
'inputlabel' => 'Facebook ID',
'type' => 'text',
'format' => '<a class="social-facebook" target="_blank" href="http://www.facebook.com/%s"></a>',
),
'twitter_handle' => array(
'inputlabel' => 'Twitter Handle (@_____)',
'type' => 'text',
'format' => '<a class="social-twitter" target="_blank" href="http://www.twitter.com/%s"></a>',
),
'google_id' => array(
'inputlabel' => 'Google + ID',
'type' => 'text',
'format' => '<a class="social-google" target="_blank" href="http://plus.google.com/+%s"></a>',
),
'linkedin_url' => array(
'inputlabel' => 'Linkedin Profile URL',
'type' => 'text',
'format' => '<a class="social-linkedin" target="_blank" href="%s"></a>',
),
'pinterest_handle' => array(
'inputlabel' => 'Pinterest Handle',
'type' => 'text',
'format' => '<a class="social-pinterest" target="_blank" href="http://www.pinterest.com/%s"></a>',
),
'yelp_id' => array(
'inputlabel' => 'Yelp biz ID',
'type' => 'text',
'format' => '<a class="social-yelp" target="_blank" href="http://www.yelp.com/biz/%s"></a>',
),
);
}
} // SocialIcons
function pl2x_plugin_social_icons()
{
static $instance;
if ( ! $instance) {
$instance = new SocialIcons();
}
return $instance;
}
add_action('plugins_loaded', 'pl2x_plugin_social_icons');