Wordpress hack for bit.ly

Wordpress hack for bit.ly

Wow, just spent 30min hacking the 'Sociable' plugin for Wordpress to use bit.ly instead of awe.sm. Harder than you might have thought! If anybody's interested then give me a shout and I'll take you through it. However, if you're content with just hacking the code and hard coding your bit.ly login name and API key into your sociable.php file then you can do the following...

Replace everything between line 735 and the } else { in sociable.php with the following...

$bitlyapikey      = '{api_key}';
$bitlylogin          = '{api_login'};

$login = '&login;='.$bitlylogin;
$key = '&apiKey;='.$bitlyapikey;

$bitlyurl = 'http://api.bit.ly/shorten?version=2.0.1&longUrl;='.$permalink.$login.$key;

$bitlyurl = file_get_contents($bitlyurl);
$bitlyurl = (string) $bitlyurl;

$find = '!"shortUrl": "(.+?)"!';
$matches = array();
preg_match($find, $bitlyurl , $matches);

if(isset($matches['1'])) {
    $url = str_replace('PERMALINK', $matches['1'], $url);
} else {
    $url = str_replace('PERMALINK', $permalink, $url);
}

October 22, 2009 |
Tags : exciting php Plugins Wordpress

Comments Section

Feel free to comment on the post but keep it clean and on topic.

comments powered by Disqus

About Me

Garry Welding Tried my hand at the start-up scene with 650hours and I'm a maintainer of a few of my own open-source projects. For now I'm now taking it easy working a cushy employee lifestyle with Mamas & Papas, one of the largest children's retailers in the UK.

gkwelding.github.com