Digg This! for WordPress

I have created this simple wordpress plugin because I wanted to include the “Digg.com button” on my self-hosted version, which worked like the one that featured here, which is available to blogs hosted on “wordpress.com”.

To install simply get the code below, and create a new file called digg-this.php in your wordpress plugin dir (ie: /home/user/public_html/wordpress/wp-content/plugins/). Once it exists, log into the wp-admin area, and activate it under the plugins section.

<?php
/*
Plugin Name: Digg This
Plugin URI: http://hm2k.com/projects/wp-digg-this
Description: A simple plugin for <a href=”http://digg.com/tools/integrate”>digg.com integration</a> using an iframe, mimicing the “digg this” as seen on wordpress.com blogs. Also see: <a href=”http://wordpress.org/support/topic/139124″>digg this</a>.
Author: HM2K
Version: 0.1
Author URI: http://hm2k.com/
*/

//core function
function digg_this($input) {
//these variables are editable
$style=’float: right; margin-left: 5px; margin-bottom: 5px; padding: 2px 0 2px 2px; background: #fff;’;
$pattern=’/\[digg=(http:\/\/(.*|www\.)digg.com\/.+?)\]/’;
$url=’http://digg.com/api/diggthis.php?u=’;
$replace=’<iframe src=”" height=”82″ width=”55″ frameborder=”0″ scrolling=”no” style=”"></iframe>’;

//do not edit the below
if (preg_match($pattern,$input,$matches)) {
$src=$url.urlencode(trim($matches[1]));
$replace=str_replace(’src=”"‘,’src=”‘.$src.’”‘,$replace);
$replace=str_replace(’style=”"‘,’style=”‘.$style.’”‘,$replace);
$input=preg_replace($pattern,$replace,$input);
}
return $input;
}

//passes the_content through the above function
add_action(‘the_content’, ‘digg_this’);

?>

You can download this script here: digg-this.phps

1 Comment »

  1. Michael T. Smith - Diffusion ยป Digg Integration for WordPress said,

    November 12, 2008 @ 2:16 am

    [...] feel that it’s appropriate. Not all of my posts are Digg worthy. HM2K.com has a plugin called Digg This which emulates the WordPress.com functionality so that you can use a Digg tag for integration on [...]

RSS feed for comments on this post · TrackBack URL

Leave a Comment