Skip to content

Commit

Permalink
Refactor into WordPress plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Berridge committed Jul 31, 2012
1 parent 1759177 commit a20f661
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 119 deletions.
32 changes: 21 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# Simple Social Sharing Buttons

An often overlooked method of implementing social sharing buttons (without counters) on your site. Super lightweight without any external loading or JavaScript, fully customisable using CSS alone. A PHP version for WordPress is also included.

**Check out the demo here: http://builtbyboon.com/posed/Simple-Social-Sharing-Buttons/**

**Read all about it: http://builtbyboon.com/blog/simple-social-sharing-buttons**

built by Boon – given away free

If you have questions or put this to use then hit me up on Twitter (@mattberridge).
# Simple Social Sharing Buttons

An often overlooked method of implementing social sharing buttons (without counters) on your site. Super lightweight without any external loading or JavaScript, fully customisable using CSS alone. WordPress plugin also included.

**Check out the demo here: http://builtbyboon.com/posed/Simple-Social-Sharing-Buttons/**

**Read all about it: http://builtbyboon.com/blog/simple-social-sharing-buttons**

built by Boon - given away free

If you have questions or put this to use then hit me up on Twitter (@mattberridge).

## Using the WordPress plugin

Download and upload `simple-social-sharing.php` into your plugins folder and activate it. To call the buttons anywhere in your theme, use the function `<?php simple_social_sharing('mattberridge'); ?>` including your Twitter username.

If you wish to show/hide any of the buttons individually, add a further attribute e.g. `<?php simple_social_sharing('mattberridge', '1,0,1'); ?>`

These are toggles for each button in the order Twitter, Facebook, Google+. `1` means show, `0` means hide.

I have also created a shortcode (to be used in the content body) which follows the same form e.g. `[simple-social-sharing twitter="mattberridge" display="1,0,1"]`
16 changes: 8 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@

<div class="strip">
<h1>Simple Social Sharing Buttons</h1>
<p>An often overlooked method of implementing social sharing buttons (<em>without counters</em>) on your site. Super lightweight without any external loading or JavaScript, fully customisable using CSS alone. A PHP version for WordPress is also included.</p>
<p>An often overlooked method of implementing social sharing buttons (<em>without counters</em>) on your site. Super lightweight without any external loading or JavaScript, fully customisable using CSS alone. WordPress plugin also included.</p>
<p><a href="http://builtbyboon.com/blog/simple-social-sharing-buttons">Read all about it</a> or <a href="https://github.com/mattberridge/Simple-Social-Sharing-Buttons">Download on Github</a></p>
<p><a href="http://builtbyboon.com">built by Boon</a> &ndash; given away free<br />
If you have any questions or put this to use then <a href="http://twitter.com/mattberridge">hit me up on Twitter</a>.<br />
</div>

<div class="container">

<ul class="share">
<li class="share-item">
<a class="share-link ico-facebook" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fbuiltbyboon.com%2Fposed%2FSimple-Social-Sharing-Buttons&amp;t=built%20by%20Boon" rel="nofollow">Share on Facebook</a>
<ul class="ss-share">
<li class="ss-share-item">
<a class="ss-share-link ico-facebook" href="http://www.facebook.com/sharer.php?u=http%3A%2F%2Fbuiltbyboon.com%2Fposed%2FSimple-Social-Sharing-Buttons&amp;t=built%20by%20Boon" rel="nofollow">Share on Facebook</a>
</li>
<li class="share-item">
<a class="share-link ico-twitter" href="http://twitter.com/share?text=Simple%20Social%20Sharing%20Buttons&amp;url=http%3A%2F%2Fbuiltbyboon.com%2Fposed%2FSimple-Social-Sharing-Buttons&amp;via=mattberridge&amp;related=mixd" rel="nofollow">Share on Twitter</a>
<li class="ss-share-item">
<a class="ss-share-link ico-twitter" href="http://twitter.com/share?text=Simple%20Social%20Sharing%20Buttons&amp;url=http%3A%2F%2Fbuiltbyboon.com%2Fposed%2FSimple-Social-Sharing-Buttons&amp;via=mattberridge" rel="nofollow">Share on Twitter</a>
</li>
<li class="share-item">
<a class="share-link ico-google" href="http://plus.google.com/share?url=http%3A%2F%2Fbuiltbyboon.com%2Fposed%2FSimple-Social-Sharing-Buttons" rel="nofollow">Share on Google+</a>
<li class="ss-share-item">
<a class="ss-share-link ico-google" href="http://plus.google.com/share?url=http%3A%2F%2Fbuiltbyboon.com%2Fposed%2FSimple-Social-Sharing-Buttons" rel="nofollow">Share on Google+</a>
</li>
</ul>
</div>
Expand Down
95 changes: 95 additions & 0 deletions simple-social-sharing.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/*
Plugin Name: Simple Social Sharing
Plugin URI: https://github.com/mattberridge/Simple-Social-Sharing-Buttons
Description: Super lightweight social sharing buttons (without counters)
Author: built by Boon
Author URI: http://builtbyboon.com
*/
function simple_social_sharing($attr_twitter = null, $attr_items = null) {

// parse variables
$twitter_account = $attr_twitter;
$item_toggles = $attr_items;

// get post content and urlencode it
global $post;
$browser_title_encoded = urlencode(trim(wp_title('', false, 'right')));
$page_title_encoded = urlencode(get_the_title());
$page_url_encoded = urlencode(get_permalink($post->ID));

// create share items
$share_items = array ();

$item_twitter = array(
"class" => "twitter",
"href" => "http://twitter.com/share?text={$page_title_encoded}&amp;url={$page_url_encoded}&amp;via={$twitter_account}",
"text" => "Share on Twitter"
);
$item_facebook = array(
"class" => "facebook",
"href" => "http://www.facebook.com/sharer.php?u={$page_url_encoded}&amp;t={$browser_title_encoded}",
"text" => "Share on Facebook"
);
$item_google = array(
"class" => "google",
"href" => "http://plus.google.com/share?url={$page_url_encoded}",
"text" => "Share on Google+"
);

// test whether to display each item
if($item_toggles) {
// explode into array
$item_toggles_array = explode(",", $item_toggles);
// set each item on or off
$show_twitter = $item_toggles_array['0'];
$show_facebook = $item_toggles_array['1'];
$show_google = $item_toggles_array['2'];
}
else {
$display_all_items = 1;
}

// form array of relevant items
if($show_twitter==1 || $display_all_items) {
array_push($share_items, $item_twitter);
}
if($show_facebook==1 || $display_all_items) {
array_push($share_items, $item_facebook);
}
if($show_google==1 || $display_all_items) {
array_push($share_items, $item_google);
}

// if one or more items
if(!empty($share_items)) {
// create output
$share_output = "<ul class=\"ss-share\">\n";
foreach($share_items as $share_item) {
$share_output .= "<li class=\"ss-share-item\">\n";
$share_output .= "<a class=\"ss-share-link ico-{$share_item['class']}\" href=\"{$share_item["href"]}\" rel=\"nofollow\" target=\"_blank\">{$share_item['text']}</a>\n";
$share_output .= "</li>\n";
}
$share_output .= "</ul>";
// echo output
echo $share_output;
}

}

// add shortcode to output buttons
function simple_social_sharing_shortcode( $atts, $content = null ) {

// parse variables / set defaults
extract( shortcode_atts( array(
'twitter' => '',
'display' => '1,1,1',
), $atts ) );

// output buttons
$output_string = simple_social_sharing($twitter, $display);
return force_balance_tags($output_string);
}
add_shortcode('simple-social-sharing', 'simple_social_sharing_shortcode');

?>
10 changes: 5 additions & 5 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ body {

/* -- Begin social sharing buttons
------------------------------------------------------------- */
.share {
.ss-share {
padding-left: 0;
list-style: none; }

.share-item {
.ss-share-item {
display: inline;
margin-right: 1em; }

.share-link {
.ss-share-link {
/* crude button styles */
text-decoration: none;
color: #444;
Expand All @@ -40,10 +40,10 @@ body {
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 2px; }
.share-link:hover, .share-link:active, .share-link:focus {
.ss-share-link:hover, .ss-share-link:active, .ss-share-link:focus {
color: #891434; }

[class*="ico"] {
[class*="ico-"] {
display: inline-block;
background-size: 16px 16px;
background-repeat: no-repeat;
Expand Down
140 changes: 70 additions & 70 deletions style.scss
Original file line number Diff line number Diff line change
@@ -1,71 +1,71 @@
/*
Author : Boon
URL : http://builtbyboon.com
Twitter : http://twitter.com/mattberridge
---------------------------------------*/
body {
margin: 0;
font: 1em/1.5 sans-serif; }

.strip {
background: #891434;
color: #fff;
padding: 1em 5%;

p {
text-align: left;
font-size: 1.2em; }

a {
color: #fff; }

}

.container {
width: 90%;
margin: 2em auto; }

/* -- Begin social sharing buttons
------------------------------------------------------------- */
.share {
padding-left: 0;
list-style: none; }

.share-item {
display: inline;
margin-right: 1em; }

.share-link {
/* crude button styles */
text-decoration: none;
color: #444;
font-weight: bold;
padding: .5em .75em .5em 35px;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 2px;

&:hover,
&:active,
&:focus {
color: #891434;
}
}

[class*="ico"] {
display: inline-block;
background-size: 16px 16px;
background-repeat: no-repeat;
background-position: 10px center; }

.ico-facebook {
background-image: url('http://www.facebook.com/favicon.ico');
}

.ico-twitter {
background-image: url('http://twitter.com/favicons/favicon.ico');
}

.ico-google {
background-image: url('https://ssl.gstatic.com/s2/oz/images/faviconr2.ico');
/*
Author : Boon
URL : http://builtbyboon.com
Twitter : http://twitter.com/mattberridge
---------------------------------------*/
body {
margin: 0;
font: 1em/1.5 sans-serif; }

.strip {
background: #891434;
color: #fff;
padding: 1em 5%;

p {
text-align: left;
font-size: 1.2em; }

a {
color: #fff; }

}

.container {
width: 90%;
margin: 2em auto; }

/* -- Begin social sharing buttons
------------------------------------------------------------- */
.ss-share {
padding-left: 0;
list-style: none; }

.ss-share-item {
display: inline;
margin-right: 1em; }

.ss-share-link {
/* crude button styles */
text-decoration: none;
color: #444;
font-weight: bold;
padding: .5em .75em .5em 35px;
background-color: #f5f5f5;
border: 1px solid #ccc;
border-radius: 2px;

&:hover,
&:active,
&:focus {
color: #891434;
}
}

[class*="ico-"] {
display: inline-block;
background-size: 16px 16px;
background-repeat: no-repeat;
background-position: 10px center; }

.ico-facebook {
background-image: url('http://www.facebook.com/favicon.ico');
}

.ico-twitter {
background-image: url('http://twitter.com/favicons/favicon.ico');
}

.ico-google {
background-image: url('https://ssl.gstatic.com/s2/oz/images/faviconr2.ico');
}
25 changes: 0 additions & 25 deletions wp-simple-share.php

This file was deleted.

0 comments on commit a20f661

Please sign in to comment.