Mostly about my amusement

Tag: plugin (page 1 of 1)

Remove shortlink URLs from comments

Or remove them from anywhere, though I’m not sure why you’d remove shortlinks from your own author’s posts.

I’ve written a small plugin that will filter your comments using preprocess_comment which is a useful filter comment data before it’s committed to your database. The other toys I used are wp_extract_urls and wp_remote_head to make http head requests to web sites.

The plugin works like this: you feed a function a URL and it gives you back a URL but with shortlinks you get the real destination. It uses wp_remote_head() to make an http HEAD request and looks for the location header.

If it finds that header then it recursively calls itself to get real destination up to 5 requests. After 5 requests the URL is replaced with the # sign. If it doesn’t find that header then the original URL is returned.

Depending on your site that can be a lot of URLs and to cache those results I create transients for those URLs. The next time in a 12 hour window that URL is tested then WordPress will pull the data from the transient.

I’ve never used transients and I’m not sure this is a good idea or not. But if you need to eliminate shortlinks then this plugin might do it. Also this parses all URLs in the post or the comment and that’s probably not necessary. A simple check can be put in to see if the URL is on a list of shortlink providers and ignore all the rest.

You can download the plugin from this Gist page.

Once you’ve downloaded it save it to your wp-content/plugins directory as short-links-begone.php and activate the plugin in your WordPress dashboard. This plugin will not change any post data or old comments. It will modify new comments when they are submitted.

Old content! Now in 3D!

The guys over at Wired re-published their old review of The Phantom Menace but with a difference. Using CSS and duplicating the content they were able to apply a 3D effect.

It’s readable if you have the glasses. And of course, I do have 3D glasses.

Naturally, I tried to do the same just for giggles. I was able to duplicate the content in both red and blue, but the entire container div uses “position: relative” so the height needed to be set manually.

That can be read as: I haven’t figured out the CSS to dynamically overlay text content on top of each other without the comment box sitting on top of the text. I can’t do it the same way as they do at Wired.

Google to the rescue! To get the effect I wanted, I’m using CSS to color the paragraph fonts a shade of blue while making the offset text-shadow red. For links I reverse that so they look different. It’s not a lot of CSS and if you apply it you better have your glasses ready. It’s easy to do but probably doesn’t work right with old browsers.

Forget old browsers. I opted for this simpler method and put the solution into a plugin.

The plugin inserts the necessary CSS into the head and when a post is tagged “Phantom 3D” the_content gets wrapped in a div  with the CSS class “redblue-text”.

Here’s the “Now in 3D!” part

  1. Download, install, and activate a copy of my plugin. It’s a zip archive with one file in it.
  2. Find an old post on your blog and edit it just by adding the tag “Phantom 3D” to the post. The spelling and case are important, the P and D have to be capitalized in the tag or this wont work.
  3. Poof! You’ve just brought new life to an old subject.

For purposes of readability I have not put that tag on this post. Not everyone has 3D classes by their PC.

But I do have an old post titled Adding Slimstats to WordPress from 2007 and that’s a good candidate.

The info in that post is horribly outdated (I mean come on, I recommended editing wp-config.php) and totally unnecessary these days. As indicated today in the comments, there are just better ways to implement Slimstat in WordPress that are supportable.

But we all know that by adding 3D everything is improved. I’ve made that post new and exciting not by updating the content but by simply applying a special effect.

If that’s good enough for George Lucas, then it’s good enough for me. 😀