forked from sawyerh/social-bartender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
social-bartender.php
executable file
·137 lines (99 loc) · 4.15 KB
/
social-bartender.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
<?php
/*
Plugin Name: Social Bartender
Plugin URI: http://wordpress.org/extend/plugins/social-bartender
Description: A simple solution for adding a list of social network links (images or text) anywhere you want, with one little function or widget.
Version: 1.2.0
Author: Sawyer Hollenshead (Shaken & Stirred Web)
Author URI: http://shakenandstirredweb.com
License: GPLv2
Copyright 2011 Sawyer Hollenshead (hello@shakenandstirredweb.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.This program is distributed in the hope
that it will be useful, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
define( 'SH_SB_DIR', plugin_dir_url(__FILE__) );
add_action('init', 'sh_sb_init');
function sh_sb_init(){
load_plugin_textdomain( 'shaken', FALSE, SH_SB_DIR.'languages' );
if( current_user_can( 'manage_options' ) ){
// Display admin pages
add_action( 'admin_menu', 'sh_sb_create_menu' );
}
}
function sh_sb_create_menu(){
global $sh_sb_settings;
$sh_sb_settings = add_submenu_page( 'options-general.php', 'Social Bartender Settings', 'Social Bartender', 'manage_options', 'sh_sb_settings_page', 'sh_sb_settings_page' );
//script actions with page detection
add_action( 'admin_print_scripts-'.$sh_sb_settings, 'sh_sb_image_admin_scripts' );
//style actions with page detection
add_action( 'admin_print_styles-'.$sh_sb_settings, 'sh_sb_image_admin_styles' );
// WP 3.3 Help section
if( version_compare( '3.3', get_bloginfo( 'version' ), '<=' ) ):
add_action("load-$sh_sb_settings", 'sh_sb_help_page');
endif;
}
//script actions with page detection
function sh_sb_image_admin_scripts() {
wp_register_script( 'social-bartender-scripts', SH_SB_DIR.'js/scripts.js',
array( 'jquery', 'media-upload', 'thickbox', 'jquery-ui-core', 'jquery-ui-sortable', 'jquery-ui-tabs' ) );
wp_enqueue_script( 'social-bartender-scripts' );
}
//style actions with page detection
function sh_sb_image_admin_styles() {
if( version_compare( '3.3', get_bloginfo( 'version' ), '>' ) ):
wp_register_style( 'social-bartender-css', SH_SB_DIR.'css/styles.css', array( 'thickbox', 'nav-menu' ) );
else:
wp_register_style( 'social-bartender-css', SH_SB_DIR.'css/styles.css', array( 'wp-admin', 'thickbox' ) );
endif;
wp_enqueue_style( 'social-bartender-css' );
}
/**
* social_bartender
*
* Outputs the links with an image or title inside
*
* @param string $link_before Sets the text or html that precedes the <a> tag.
* @param string $link_after Sets the text or html that follows the <a> tag.
* @param string $echo Echo the content if true (1) or return if false (0)
*
* @return string
*/
function social_bartender( $link_before = '', $link_after = '', $echo = 1 ){
$items = get_option( 'sh_sb_items' );
$output = '';
if( !$items ) return '';
foreach( $items as $item ):
$link = $item['link'];
$title = $item['title'];
$icon = $item['icon'];
if( $link ):
$output .= $link_before;
$output .= '<a href="'.$link.'" class="sh-sb-link">';
if( $icon && get_option( 'sh_sb_title_only' ) != 'yes' ){
$output .= '<img src="'.$icon.'" alt="'.$title.'" class="sh-sb-icon" />';
}
if( $title && get_option( 'sh_sb_title_only' ) == 'yes' ){
$output .= $title;
}
$output .= '</a>';
$output .= $link_after;
endif;
endforeach;
if( $echo == 1 )
echo $output;
else
return $output;
}
require_once(WP_PLUGIN_DIR . "/" . basename(dirname(__FILE__)) . "/settings.php");
require_once(WP_PLUGIN_DIR . "/" . basename(dirname(__FILE__)) . "/help.php");
require_once(WP_PLUGIN_DIR . "/" . basename(dirname(__FILE__)) . "/widget.php");
add_shortcode('social_bartender', 'social_bartender');
?>