bradtrivers

Sharing Buttons with Pinterest - ElegantThemes

Apr 30th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.41 KB | None | 0 0
  1. /*
  2. Plugin Name: SunriseWeb.ca Sharing Buttons
  3. Description: Add Sharing buttons to content area of ElegantThemes.com themes, includes dependency on Get The Image plugin for Pinterest functionality and looks for default image in theme options
  4. Version: 0.01
  5. Author: Brad Trivers
  6. Author URI: http://sunriseweb.ca
  7. */
  8.  
  9. /**
  10.  * @author Brad Trivers <[email protected]>
  11.  */
  12.  
  13. if(!function_exists('sharingButtons_addThis') && !function_exists('getThumbnailSunriseWeb')) {
  14.   add_filter( 'the_content', 'sharingButtons_addThis', 100 );
  15.   // Put AddThis buttons at the bottom of every post page.
  16.   function sharingButtons_addThis( $content ) {
  17.     global $post;
  18.     $thisImage = getThumbnailSunriseWeb( $post->ID );
  19.     $pinterestURL = $thisImage['url'];
  20.  
  21.     $currentURL = 'http://'.$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
  22.  
  23.     $content .= '   <!-- AddThis Button BEGIN -->';
  24.     $content .= '    <div class="addthis_toolbox addthis_default_style ">';
  25.     $content .= '    <a class="addthis_button_facebook_like" fb:like:layout="button_count"></a>';
  26.     if(!empty($pinterestURL)) {
  27.       $content .= '    <a class="addthis_button_pinterest" pi:pinit:url="'. $currentURL .'" pi:pinit:media="'. $pinterestURL .'" pi:pinit:layout="horizontal"></a>';
  28.     }
  29.     $content .= '    <a class="addthis_button_tweet"></a>';
  30.     $content .= '    <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>';
  31.     $content .= '    <a class="addthis_counter addthis_pill_style"></a> ';
  32.     $content .= '    </div>';
  33.     $content .= '    <script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=btrivers"></script>';
  34.     $content .= '    <!-- AddThis Button END -->      ';
  35.     // Returns the content.
  36.     return $content;
  37.   }
  38.  
  39.   //Function to get the post thumbnail
  40.   //relies on Get the image plugin and Default Featured Image theme option
  41.   //returns array of image parameters - always contains URL
  42.   function getThumbnailSunriseWeb( $postID ) {
  43.     global $shortname;
  44.     $defaultImage = get_option($shortname.'_defaultFeaturedImage');
  45.     if($defaultImage == "") {
  46.       $defaultImage = (get_option($shortname.'_logo') <> '') ? get_option($shortname.'_logo') : get_bloginfo('template_directory').'/images/logo.png';
  47.     }    
  48.   //   if($format != 'array') {
  49.   //     $format = 'img';
  50.   //   }
  51.     if(trim($postID) != "" && !is_home()) {
  52.       if ( function_exists( 'get_the_image' ) ) {
  53.         $getTheImageOptions = array(
  54.             'meta_key' => array( 'Thumbnail', 'thumbnail' ),
  55.             'post_id' => $postID,
  56.             'attachment' => true,
  57.             'the_post_thumbnail' => true,
  58.             'size' => 'large',
  59.             'default_image' => $defaultImage,
  60.             'order_of_image' => 1,
  61.             'link_to_post' => true,
  62.             'image_class' => false,
  63.             'image_scan' => false,
  64.             'width' => false,
  65.             'height' => false,
  66.             'format' => 'array',
  67.             'meta_key_save' => false,
  68.             'callback' => null,
  69.             'cache' => true,
  70.             'echo' => false
  71.         );
  72.         $thisImage = get_the_image($getTheImageOptions);
  73.   //       $url = $thisImage['url'];
  74.       } else {
  75.         $thisImage['url'] = wp_get_attachment_url( get_post_thumbnail_id($postID) );
  76.         if(!$thisImage['url']) {
  77.           $thisImage['url'] = $defaultImage;  
  78.         }
  79.       }
  80.     } else {
  81.       $thisImage['url'] = $defaultImage;    
  82.     }
  83.     return $thisImage;
  84.   }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment