[cn-social-icon] in page/post, template tag for php file <?php if ( function_exists('cn_social_icon') ) echo cn_social_icon(); ?> also you can use the widget "Easy Social Icons" for sidebar.
Version: 3.0.4
Author: cybernetikz
Author URI: http://www.cybernetikz.com
License: GPL2
*/
if( !defined('ABSPATH') ) die();
$cnssUploadDir = wp_upload_dir();
$cnssBaseDir = $cnssUploadDir['basedir'].'/';
$cnssBaseURL = $cnssUploadDir['baseurl'].'';
$cnssPluginsURI = plugins_url('/easy-social-icons/');
add_action('init', 'cnss_init_script');
add_action('init', 'cn_process_post');
add_action('wp_ajax_update-social-icon-order', 'cnss_save_ajax_order' );
add_action('admin_menu', 'cnss_add_menu_pages');
add_action('wp_head', 'social_profile_links_fn');
add_action('admin_enqueue_scripts', 'cnss_admin_style');
if( isset($_GET['page']) ) {
if( $_GET['page']=='cnss_social_icon_add' ) {
add_action('admin_enqueue_scripts', 'cnss_admin_enqueue' );
}
}
register_activation_hook(__FILE__,'cnss_db_install');
add_shortcode('cn-social-icon', 'cn_social_icon');
if (isset($_GET['cnss-delete'])) {
if ($_GET['id'] != '')
{
$table_name = $wpdb->prefix . "cn_social_icon";
$image_file_path = $cnssBaseDir;
$wpdb->delete( $table_name, array( 'id' => $_GET['id'] ), array( '%d' ) );
$msg = "Delete Successful !"."
";
}
}
function cnss_admin_sidebar() {
$banners = array(
array(
'url' => 'http://www.cybernetikz.com/wordpress-magento-plugins/wordpress-plugins/?utm_source=easy-social-icons&utm_medium=banner&utm_campaign=wordpress-plugins',
'img' => 'banner-1.jpg',
'alt' => 'Banner 1',
),
array(
'url' => 'http://www.cybernetikz.com/web-development/wordpress-website/?utm_source=easy-social-icons&utm_medium=banner&utm_campaign=wordpress-plugins',
'img' => 'banner-2.jpg',
'alt' => 'Banner 2',
),
array(
'url' => 'http://www.cybernetikz.com/seo-consultancy/?utm_source=easy-social-icons&utm_medium=banner&utm_campaign=wordpress-plugins',
'img' => 'banner-3.jpg',
'alt' => 'Banner 3',
),
);
//shuffle( $banners );
?>
';
$i ++;
}
?>
prefix . "cn_social_icon";
$sql = "SELECT id, title, url, image_url, sortorder, target FROM {$table_name} WHERE url<>'' AND image_url<>'' ORDER BY sortorder;";
$social_icons = $wpdb->get_results($sql);
if (count($social_icons)>0) {
return $social_icons;
} else {
return array();
}
}
function cn_esi_get_option($key='') {
if ($key == '') {
return;
}
$cnss_esi_settings = array(
'cnss-width' => '32',
'cnss-height' => '32',
'cnss-margin' => '4',
'cnss-row-count' => '1',
'cnss-vertical-horizontal' => 'horizontal',
'cnss-text-align' => 'center',
'cnss-social-profile-links' => '0',
'cnss-social-profile-type' => 'Person',
'cnss-icon-bg-color' => '#999999',
'cnss-icon-bg-hover-color' => '#666666',
'cnss-icon-color' => '#ffffff',
'cnss-icon-hover-color' => '#ffffff',
'cnss-icon-shape' => 'square',
'cnss-original-icon-color' => '1'
);
if ( get_option($key) != '' ) {
return get_option($key);
} else {
return $cnss_esi_settings[$key];
}
}
function social_profile_links_fn() {
$social_profile_links = cn_esi_get_option('cnss-social-profile-links');
$cnss_original_icon_color = cn_esi_get_option('cnss-original-icon-color');
$icon_bg_color = cn_esi_get_option('cnss-icon-bg-color');
$icon_bg_hover_color = cn_esi_get_option('cnss-icon-bg-hover-color');
$icon_hover_color = cn_esi_get_option('cnss-icon-hover-color');
$icons = cnss_get_all_icons();
if ( !empty($icons) && $social_profile_links == 1 ) {
$sameAs = '';
$social_profile_type = get_option('cnss-social-profile-type');
$profile_type = $social_profile_type == 'Person'?'Person':'Organization';
foreach ($icons as $icon) {
$sameAs .= '"'.$icon->url.'",';
}
$sameAs = rtrim($sameAs,',');
echo '';
}
if ($cnss_original_icon_color == '1') {
echo '';
} else {
echo '';
}
}
function cnss_add_menu_pages() {
add_menu_page('Easy Social Icons', 'Easy Social Icons', 'manage_options', 'cnss_social_icon_page', 'cnss_social_icon_page_fn',plugins_url('/images/scc-sc.png', __FILE__) );
//add_menu_page('Easy Social Icons', 'Easy Social Icons', 'manage_options', 'cnss_social_icon_page', 'cnss_social_icon_page_fn', 'dashicons-share' );
add_submenu_page('cnss_social_icon_page', 'All Icons', 'All Icons', 'manage_options', 'cnss_social_icon_page', 'cnss_social_icon_page_fn');
add_submenu_page('cnss_social_icon_page', 'Add New', 'Add New', 'manage_options', 'cnss_social_icon_add', 'cnss_social_icon_add_fn');
add_submenu_page('cnss_social_icon_page', 'Sort Icons', 'Sort Icons', 'manage_options', 'cnss_social_icon_sort', 'cnss_social_icon_sort_fn');
add_submenu_page('cnss_social_icon_page', 'Settings & Instructions', 'Settings & Instructions', 'manage_options', 'cnss_social_icon_option', 'cnss_social_icon_option_fn');
add_action( 'admin_init', 'register_cnss_settings' );
}
function register_cnss_settings() {
register_setting( 'cnss-settings-group', 'cnss-width' );
register_setting( 'cnss-settings-group', 'cnss-height' );
register_setting( 'cnss-settings-group', 'cnss-margin' );
register_setting( 'cnss-settings-group', 'cnss-row-count' );
register_setting( 'cnss-settings-group', 'cnss-vertical-horizontal' );
register_setting( 'cnss-settings-group', 'cnss-text-align' );
register_setting( 'cnss-settings-group', 'cnss-social-profile-links' );
register_setting( 'cnss-settings-group', 'cnss-social-profile-type' );
register_setting( 'cnss-settings-group', 'cnss-icon-bg-color' );
register_setting( 'cnss-settings-group', 'cnss-icon-bg-hover-color' );
register_setting( 'cnss-settings-group', 'cnss-icon-color' );
register_setting( 'cnss-settings-group', 'cnss-icon-hover-color' );
register_setting( 'cnss-settings-group', 'cnss-icon-shape' );
register_setting( 'cnss-settings-group', 'cnss-original-icon-color', 'cnss_original_icon_color_fn' );
}
function cnss_original_icon_color_fn($value) {
return $value==''?'0':$value;
}
function cnss_social_icon_option_fn() {
$cnss_width = get_option('cnss-width');
$cnss_height = get_option('cnss-height');
$cnss_margin = get_option('cnss-margin');
$cnss_rows = get_option('cnss-row-count');
$vorh = get_option('cnss-vertical-horizontal');
$text_align = get_option('cnss-text-align');
$social_profile_links = get_option('cnss-social-profile-links');
$social_profile_type = get_option('cnss-social-profile-type');
$icon_bg_color = get_option('cnss-icon-bg-color');
$icon_bg_hover_color = get_option('cnss-icon-bg-hover-color');
$icon_color = get_option('cnss-icon-color');
$icon_hover_color = get_option('cnss-icon-hover-color');
$icon_shape = get_option('cnss-icon-shape');
$cnss_original_icon_color = get_option('cnss-original-icon-color');
$vertical ='';
$horizontal ='';
if($vorh=='vertical') $vertical = 'checked="checked"';
if($vorh=='horizontal') $horizontal = 'checked="checked"';
$center ='';
$left ='';
$right ='';
if($text_align=='center') $center = 'checked="checked"';
if($text_align=='left') $left = 'checked="checked"';
if($text_align=='right') $right = 'checked="checked"';
?>
Icon Settings
How to use
prefix . "cn_social_icon";
if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
$sql_create_table = "CREATE TABLE IF NOT EXISTS `$table_name` (
`id` INT NOT NULL AUTO_INCREMENT,
`title` VARCHAR(255) NULL,
`url` VARCHAR(255) NOT NULL,
`image_url` VARCHAR(255) NOT NULL,
`sortorder` INT NOT NULL DEFAULT '0',
`date_upload` VARCHAR(50) NULL,
`target` tinyint(1) NOT NULL DEFAULT '1',
PRIMARY KEY (`id`)) ENGINE = InnoDB;
INSERT INTO `wp_cn_social_icon` (`id`, `title`, `url`, `image_url`, `sortorder`, `date_upload`, `target`) VALUES
(1, 'Facebook', 'https://facebook.com/', 'fa fa-facebook', 0, '1487164658', 1),
(2, 'Twitter', 'https://twitter.com/', 'fa fa-twitter', 1, '1487164673', 1),
(3, 'LinkedIn', 'https://linkedin.com/', 'fa fa-linkedin', 2, '1487164712', 1);";
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
dbDelta($sql_create_table);
}
$cnss_esi_settings = array(
'cnss-width' => '32',
'cnss-height' => '32',
'cnss-margin' => '4',
'cnss-row-count' => '1',
'cnss-vertical-horizontal' => 'horizontal',
'cnss-text-align' => 'center',
'cnss-social-profile-links' => '0',
'cnss-social-profile-type' => 'Person',
'cnss-icon-bg-color' => '#666666',
'cnss-icon-bg-hover-color' => '#333333',
'cnss-icon-color' => '#ffffff',
'cnss-icon-hover-color' => '#ffffff',
'cnss-icon-shape' => 'square',
'cnss-original-icon-color' => '1'
);
foreach ($cnss_esi_settings as $key => $value) {
add_option( trim($key), trim($value) );
}
}
function cn_process_post() {
global $wpdb,$err,$msg,$cnssBaseDir;
if ( isset($_POST['submit_button']) && check_admin_referer('cn_insert_icon') ) {
if ($_POST['action'] == 'update')
{
$err = "";
$msg = "";
$image_file_path = $cnssBaseDir;
if ($err == '')
{
$table_name = $wpdb->prefix . "cn_social_icon";
$results = $wpdb->insert(
$table_name,
array(
'title' => sanitize_text_field($_POST['title']),
'url' => sanitize_text_field($_POST['url']),
'image_url' => sanitize_text_field($_POST['image_file']),
'sortorder' => sanitize_text_field($_POST['sortorder']),
'date_upload' => time(),
'target' => sanitize_text_field($_POST['target']),
),
array(
'%s',
'%s',
'%s',
'%d',
'%s',
'%d',
)
);
if (!$results)
$err .= "Fail to update database" . "
";
else
$msg .= "Update successful !" . "
";
}
/*
$allSocialMediaIcons = array('500px','amazon','android','angellist','apple','bandcamp','behance','behance-square','bitbucket','bluetooth','cc-amex','cc-mastercard','cc-paypal','cc-stripe','cc-visa','codepen','css3','delicious','deviantart','digg','dribbble ','dropbox','drupal','edge ','etsy','expeditedssl','facebook','facebook-f','facebook-official','facebook-square','firefox','flickr','forumbee ','foursquare','free-code-camp','get-pocket','git ','git-square ','github ','github-square ','gitlab','google ','google-plus','google-plus-circle','google-plus-official','google-plus-square','google-wallet','gratipay','hacker-news','houzz','html5','imdb','instagram','internet-explorer','joomla','lastfm','linkedin','linkedin-square','linux','maxcdn ','medium ','meetup','odnoklassniki','opera','paypal','pinterest ','pinterest-p ','pinterest-square ','product-hunt','quora ','reddit ','rss ','scribd','skype','slack','slideshare ','snapchat','soundcloud','spotify','stack-exchange','stack-overflow','steam','stumbleupon','telegram','trello','tripadvisor','tumblr','tumblr-square','twitch','twitter','twitter-square','viadeo','vimeo ','vimeo-square ','vine ','wechat','whatsapp ','wikipedia-w','windows','wordpress ','xing','xing-square','yahoo','yelp','youtube','youtube-square');
$table_name = $wpdb->prefix . "cn_social_icon";
$i = 0;
foreach ($allSocialMediaIcons as $icon) {
$results = $wpdb->insert(
$table_name,
array(
'title' => $icon,
'url' => 'https://'.$icon.'.com/',
'image_url' => 'fa fa-'.$icon,
'sortorder' => $i,
'date_upload' => time(),
'target' => '1',
),
array(
'%s',
'%s',
'%s',
'%d',
'%s',
'%d',
)
);
$i++;
}
*/
}// end if update
if ( $_POST['action'] == 'edit' and $_POST['id'] != '' )
{
$err = "";
$msg = "";
$url = $_POST['url'];
$target = $_POST['target'];
$image_file_path = $cnssBaseDir;
$update = "";
$type = 1;
if ($err == '')
{
$table_name = $wpdb->prefix . "cn_social_icon";
$result3 = $wpdb->update(
$table_name,
array(
'title' => sanitize_text_field($_POST['title']),
'url' => sanitize_text_field($_POST['url']),
'image_url' => sanitize_text_field($_POST['image_file']),
'sortorder' => sanitize_text_field($_POST['sortorder']),
'date_upload' => time(),
'target' => sanitize_text_field($_POST['target']),
),
array( 'id' => sanitize_text_field($_POST['id']) ),
array(
'%s',
'%s',
'%s',
'%d',
'%s',
'%d',
),
array( '%d' )
);
if (false === $result3){
$err .= "Update fails !". "
";
}
else
{
$msg = "Update successful !". "
";
}
}
} // end edit
}
}
function cnss_social_icon_sort_fn() {
global $wpdb,$cnssBaseURL;
$cnss_width = get_option('cnss-width');
$cnss_height = get_option('cnss-height');
$image_file_path = $cnssBaseURL;
$icons = cnss_get_all_icons();
?>
prefix . "cn_social_icon";
parse_str($_POST['order'], $data);
if (is_array($data)) {
foreach($data as $key => $values )
{
if ( $key == 'item' )
{
foreach( $values as $position => $id )
{
$wpdb->update( $table_name, array('sortorder' => $position), array('id' => $id) );
}
}
}
}
}
function cnss_get_icon_html($url = '', $title = '', $width = '', $height = '', $margin = '') {
if ($url == '') {
return 'Input source invalid.';
}
$width = ($width=='') ? get_option('cnss-width') : $width;
$height = ($height=='') ? get_option('cnss-height') : $height;
$icon_output_html = '';
if ( cnss_is_image_icon($url) ) {
$imgStyle = '';
$imgStyle .= ($margin == '') ? '' : 'margin:'.$margin.'px;';
$imgStyle .= ($width == $height) ? '' : 'height:'.$height.'px;';
$icon_output_html = '';
} else {
$icon_output_html = '';
}
return $icon_output_html;
}
function cnss_get_img_url($url)
{
global $cnssBaseURL;
if ($url == '') {
return;
}
if( strpos($url,'/') === false ) {
return $cnssBaseURL.'/'.$url;
} else {
return $url;
}
}
function cnss_is_image_icon($url) {
if ( strpos($url, 'fa fa-') === false ) {
return true;
} else {
return false;
}
}
function cnss_social_icon_add_fn() {
global $wpdb,$err,$msg,$cnssBaseURL;
$social_sites = array(
"https://500px.com/" => "500px",
"https://angellist.com/" => "AngelList",
"https://bandcamp.com/" => "Bandcamp",
"https://behance.com/" => "Behance",
"https://bitbucket.org/" => "BitBucket",
"https://bloglovin.com/" => "Blog Lovin'",
"https://codepen.com/" => "Codepen",
"mail:" => "Email",
"https://delicious.com/" => "Delicious",
"https://deviantart.com/" => "DeviantArt",
"https://digg.com/" => "Digg",
"https://dribbble.com/" => "Dribbble",
"https://dropbox.com/" => "Dropbox",
"https://facebook.com/" => "Facebook",
"https://flickr.com/" => "Flickr",
"https://foursquare.com/" => "Foursquare",
"https://github.com/" => "Github",
"https://plus.google.com/" => "Google+",
"https://houzz.com/" => "Houzz",
"https://instagram.com/" => "Instagram",
"https://itunes.com/" => "iTunes",
"https://jsfiddle.com/" => "JSFiddle",
"https://lastfm.com/" => "Last.fm",
"https://linkedin.com/" => "LinkedIn",
"https://mixcloud.com/" => "Mixcloud",
"https://paper-plane.com/" => "Newsletter",
"https://pinterest.com/" => "Pinterest",
"https://reddit.com/" => "Reddit",
"rss" => "RSS",
"skype" => "Skype",
"https://snapchat.com/" => "Snapchat",
"https://soundcloud.com/" => "Soundcloud",
"https://spotify.com/" => "Spotify",
"https://stackoverflow.com/" => "Stack Overflow",
"https://steam.com/" => "Steam",
"https://stumbleupon.com/" => "Stumbleupon",
"https://tripadvisor.com/" => "Trip Advisor",
"https://tumblr.com/" => "Tumblr",
"https://twitch.com/" => "Twitch",
"https://twitter.com/" => "Twitter",
"viber" => "Viber",
"https://vimeo.com/" => "Vimeo",
"https://vine.com/" => "Vine",
"https://vkontakte.com/" => "VK",
"https://wordpress.com/" => "WordPress",
"https://xing.com/" => "Xing",
"https://yelp.com/" => "Yelp",
"https://youtube.com/" => "YouTube",
"https://yahoo.com/" => "Yahoo"
);
$cnss_width = get_option('cnss-width');
$cnss_height = get_option('cnss-height');
$blank_img = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7";
if (isset($_GET['mode'])) {
if ( $_GET['mode'] == 'edit' and $_GET['id'] != '' ) {
if( ! is_numeric($_GET['id']) )
wp_die('Sequrity Issue.');
$page_title = 'Edit Icon';
$uptxt = 'Icon';
$table_name = $wpdb->prefix . "cn_social_icon";
$image_file_path = $cnssBaseURL;
$sql = sprintf("SELECT * FROM %s WHERE id=%d", $table_name, $_GET['id']);
$icon_info = $wpdb->get_row($sql);
if (!empty($icon_info))
{
$id = $icon_info->id;
$title = $icon_info->title;
$url = $icon_info->url;
$image_url = $icon_info->image_url;
$sortorder = $icon_info->sortorder;
$target = $icon_info->target;
}
}
}
else
{
$page_title = 'Add New Icon';
$title = "";
$url = "";
$image_url = "";
$sortorder = count(cnss_get_all_icons());
$target = "";
$uptxt = 'Icon';
}
?>
'.$msg.'
';
if($err!='') echo ''.$err.'
';
?>
←Back to';
}
function cnss_manage_icon_table_header() {
return '
ID |
Title |
URL |
Open In |
Icons |
Order |
Action |
Action |
';
}
function cnss_esi_review_text()
{
return '';
}
function cnss_social_icon_page_fn() {
global $wpdb,$cnssBaseURL;
$cnss_width = get_option('cnss-width');
$cnss_height = get_option('cnss-height');
$image_file_path = $cnssBaseURL;
$icons = cnss_get_all_icons();
?>
Social Icons
Add New
id;?>
|
title;?>
|
url;?>
|
target==1?'New Window':'Same Window' ?>
|
image_url, $icon->title); ?>
|
sortorder;?>
|
|
|
No icon found, please Add New icon | ';
}
?>
prefix . "cn_social_icon";
$image_file_path = $cnssBaseURL;
$sql = "SELECT * FROM ".$table_name." WHERE image_url<>'' AND url<>'' ORDER BY sortorder";
$icons = $wpdb->get_results($sql);
$icon_count = count($icons);
$_collectionSize = count($icons);
$_rowCount = $cnss_rows ? $cnss_rows : 1;
$_columnCount = ceil($_collectionSize/$_rowCount);
if($vorh=='vertical')
$table_width = $cnss_width;
else
$table_width = $_columnCount*($cnss_width+$cnss_margin);
$td_width = $cnss_width+$cnss_margin;
ob_start();
echo '';
$out = ob_get_contents();
ob_end_clean();
return $out;
}
function cnss_format_title($str) {
$pattern = '/[^a-zA-Z0-9]/';
return strtolower(preg_replace($pattern,'-',$str));
}
function cnss_format_class($str) {
return str_replace(array('fa ','fa-'), array('','cnss-'), $str);
}
function cn_social_icon($attr = array(), $call_from_widget = NULL) {
global $wpdb, $cnssBaseURL;
$image_file_path = $cnssBaseURL;
$attr_id = isset($attr['attr_id'])?$attr['attr_id']:'';
$attr_class = isset($attr['attr_class'])?$attr['attr_class']:'';
$where_sql = "";
if(isset($attr['selected_icons']))
{
if(is_string($attr['selected_icons'])) {
$attr['selected_icons'] = preg_replace('/[^0-9,]/','',$attr['selected_icons']);
$attr['selected_icons'] = explode(',', $attr['selected_icons']);
}
if(is_array($attr['selected_icons'])) {
$where_sql .= ' AND `id` IN(';
foreach($attr['selected_icons'] as $iid)
{
$where_sql .= $iid.',';
}
$where_sql = rtrim($where_sql,',');
$where_sql .= ') ';
}
}
$cnss_width = isset($attr['width'])?$attr['width']:get_option('cnss-width');
$cnss_height = isset($attr['height'])?$attr['height']:get_option('cnss-height');
$cnss_margin = isset($attr['margin'])?$attr['margin']:get_option('cnss-margin');
$cnss_rows = get_option('cnss-row-count');
$vorh = isset($attr['display'])?$attr['display']:get_option('cnss-vertical-horizontal');
$text_align = isset($attr['alignment'])?$attr['alignment']:get_option('cnss-text-align');
// settings for font-awesome icons
$icon_bg_color = cn_esi_get_option('cnss-icon-bg-color');
$icon_color = cn_esi_get_option('cnss-icon-color');
$icon_hover_color = cn_esi_get_option('cnss-icon-hover-color');
$icon_shape = cn_esi_get_option('cnss-icon-shape');
$cnss_original_icon_color = cn_esi_get_option('cnss-original-icon-color');
$table_name = $wpdb->prefix . "cn_social_icon";
$sql = "SELECT * FROM ".$table_name." WHERE image_url<>'' AND url<>'' $where_sql ORDER BY sortorder";
$icons = $wpdb->get_results($sql);
$icon_count = count($icons);
$li_margin = round($cnss_margin/2);
ob_start();
echo '';
$i=0;
foreach($icons as $icon)
{
$aStyle = '';
$liClass = 'cn-fa-'.cnss_format_title($icon->title);
$aClass = '';
$liStyle = ($vorh == 'horizontal') ? 'display:inline-block;' : '';
$aTarget = ($icon->target ==1 ) ? 'target="_blank"' : '';
if ( !cnss_is_image_icon($icon->image_url) ) {
$liClass .= " cn-fa-icon ";
$aPadding = round($cnss_width/4);
$aWidth = $cnss_width + $aPadding*2;
$aHeight = $aWidth;
$aStyle .= "width:{$aWidth}px;";
$aStyle .= "height:{$aHeight}px;";
$aStyle .= "padding:{$aPadding}px;";
$aStyle .= "margin:{$li_margin}px;";
$aStyle .= "color: {$icon_color};";
if ($cnss_original_icon_color == '1') {
$aClass = cnss_format_class($icon->image_url);
} else {
//$aStyle .= "background-color:{$icon_bg_color};";
}
if ($icon_shape == 'circle') {
$borderRadius = '50%';
} elseif ($icon_shape == 'round-corner') {
$borderRadius = '10%';
} else {
$borderRadius = '0%';
}
$aStyle .= "border-radius: {$borderRadius};";
}
?>- href="url ?>" title="title ?>" style="">image_url, $icon->title, $cnss_width, $cnss_height, $li_margin); ?>
';
$out = ob_get_contents();
ob_end_clean();
return $out;
}
function _cn_social_icon_sc( $selected_icons_array = array() ) {
global $wpdb,$cnssBaseURL;
$cnss_width = get_option('cnss-width');
$cnss_height = get_option('cnss-height');
$image_file_path = $cnssBaseURL;
$icons = cnss_get_all_icons();
$icon_count = count($icons);
ob_start();
echo ''."\r\n";
$i=0;
foreach($icons as $icon)
{
?>-
id, $selected_icons_array ) ) echo 'checked="checked"'; ?> style="margin:0;" type="checkbox" name="_selected_icons[]" id="iconid; ?>" value="id; ?>" />
'."\r\n";
$out = ob_get_contents();
ob_end_clean();
return $out;
}
class Cnss_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'cnss_widget', // Base ID
'Easy Social Icons', // Name
array( 'description' => __( 'Add social media icons to your Sidebar.' ) ) // Args
);
}
public function widget( $args, $instance ) {
extract( $args );
$title = apply_filters( 'widget_title', $instance['title'] );
echo $before_widget;
if ( ! empty( $title ) )
echo $before_title . $title . $after_title;
echo cn_social_icon($instance, 1);
echo $after_widget;
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['attr_id'] = strip_tags( $new_instance['attr_id'] );
$instance['attr_class'] = strip_tags( $new_instance['attr_class'] );
$instance['width'] = strip_tags( $new_instance['width'] );
$instance['height'] = strip_tags( $new_instance['height'] );
$instance['margin'] = strip_tags( $new_instance['margin'] );
$instance['display'] = strip_tags( $new_instance['display'] );
$instance['alignment'] = strip_tags( $new_instance['alignment'] );
$instance['selected_icons'] = $new_instance['selected_icons'];
return $instance;
}
public function form( $instance ) {
$cnss_width = get_option('cnss-width');
$cnss_height = get_option('cnss-height');
$cnss_margin = get_option('cnss-margin');
$cnss_rows = get_option('cnss-row-count');
$vorh = get_option('cnss-vertical-horizontal');
$text_align = get_option('cnss-text-align');
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
else {
$title = __( 'Follow Us' );
}
$instance[ 'alignment' ] = isset($instance[ 'alignment' ])?$instance[ 'alignment' ]:$text_align;
$instance[ 'display' ] = isset($instance[ 'display' ])?$instance[ 'display' ]:$vorh;
?>
Following settings will override the default Icon Settings
(If select none all icons will be displayed)
_cn_social_icon_widget( isset($instance['selected_icons'])?$instance['selected_icons']:array() ); ?>
'."\r\n";
$i=0;
foreach($icons as $icon)
{
?>-
id, $selected_icons_array ) ) echo 'checked="checked"'; ?> style="margin:0;" type="checkbox" name="get_field_name( 'selected_icons' ); ?>[]" id="get_field_id( 'selected_icons'.$icon->id ); ?>" value="id; ?>" />
'."\r\n";
} else {
echo 'No icon found, please Add New icon.';
}
$out = ob_get_contents();
ob_end_clean();
return $out;
}
} // class Cnss_Widget
add_action( 'widgets_init', create_function( '', 'register_widget( "Cnss_Widget" );' ) );