Tag: Share This

Hacking “Share This” to Configure Sharing Options

by Matt Danger on Nov.24, 2008, under PHP

Thomas likes to use Alex King’s Share This plugin on his Wordpress install but wanted a little more configurability from it. I wrote a little hack to allow him to select which sharing tab appears by default. This was written for version 1.3 and I’m not sure if it could be successfully implemented into the 2.3 version.

To select the default tab set “DEFAULT_TAB” to either ’social’ or ‘email’ for which tab you’d like to be displayed when Share This is activated. Set “FIRST_TAB” to either ’social’ or ‘email’ for which tab you’d like to appear first in the tab order when Share This is activated.

To begin, add this code at line 26:

@define('DEFAULT_TAB', 'email'); // 'social' or 'email' 
@define('FIRST_TAB', 'email'); // 'social' or 'email' as the first tab.

Then add this code at line 123:

function get_default_tab() {
  switch (DEFAULT_TAB) {
    case 'email':
      $tab_number = 2;
      break;
    case 'social':
      $tab_number = 1;
      break;
    default: die("Error with the Share This plugin: Please define DEFAULT_TAB as either 'social' or 'email'.");  
  }
  echo $tab_number;
}

Then add this code at line 174:

akst_share_tab('<?php get_default_tab(); ?>');

Finally, at line 442 replace:

<li id="akst_tab1" onclick="akst_share_tab('1');"><?php _e('Social Web', 'alexking.org'); ?></li>
<li id="akst_tab2" class="selected" onclick="akst_share_tab('2');"><?php _e('E-mail', 'alexking.org'); ?></li>

with:

<?php 
switch (FIRST_TAB) {
  case 'social':
?>
    <li id="akst_tab1" onclick="akst_share_tab('1');"><?php _e('Social Web', 'alexking.org'); ?></li>
    <li id="akst_tab2" class="selected" onclick="akst_share_tab('2');"><?php _e('E-mail', 'alexking.org'); ?></li>
<?php
    break;
  case 'email':
?>
    <li id="akst_tab2" class="selected" onclick="akst_share_tab('2');"><?php _e('E-mail', 'alexking.org'); ?></li>
    <li id="akst_tab1" onclick="akst_share_tab('1');"><?php _e('Social Web', 'alexking.org'); ?></li>
<?php
    break;
  default: die("Error with the Share This plugin: Please define FIRST_TAB as either 'social' or 'email'.");
}
?>
Leave a Comment :, , more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Send me a message on AIM!

Friends

Read what I read...