Archive Latest Entries

Automatically Escape HTML Entities of Code Fragments in Comments

Update: Ryan has made this into a plugin — Code Comments.

Add this to your theme’s functions.php to allow readers post fragments of code in their comments (wrapped in <code>...</code>) which are automatically encoded (think of < and &lt;)

add_filter('pre_comment_content', 'encode_code_in_comment');

function encode_code_in_comment($source) {
  $encoded = preg_replace_callback('/<code>(.*?)<\/code>/ims',
  create_function(
    '$matches',
    '$matches[1] = preg_replace(
        array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "",
        $matches[1]);
      return "<code>" . htmlentities($matches[1]) . "</code>";'
  ),
  $source);

  if ($encoded)
    return $encoded;
  else
    return $source;
}

Worth noting:

  • Everything wrapped in <code>...</code> is encoded.
  • Line breaks after opening <code> and before closing </code> are removed in order to avoid unnecessary <br /> tags.

Semantics of Article Headline and Byline

Can you think of any reason why placing article credits before the headline, like this:

<p>August 18, 2009 by Author Name</p>
<h1>Title of the Post</h1>
<p>Post body goes here.</p>

is semantically worse than moving credits after the title:

<h1>Title of the Post</h1>
<p>August 18, 2009 by Author Name</p>
<p>Post body goes here.</p>

Multiple Galleries per Post/Page

Ever wanted to have multiple galleries on the same post or page? Currently most of the solutions require you to manually edit gallery shortcode and add something like include="img_id_1 img_id2". Luckily, WordPress 2.9 will have this include/exclude feature built in core, but you still don’t have an easy way to select images which to include or to insert multiple galleries.

Therefore, I created a plugin called Multiple Galleries which adds checkboxes next to images in the Insert Gallery window which makes selecting images to be included in galleries fast and easy. If no checkbox is selected, all images are included.

Select images which to include in gallery

I created this plugin because I am designing a new WordPress theme for designers, artists, architects and all of the creative types where the ability to have multiple galleries per portfolio entry is very important.

The Pricey GPL Thought Experiment

Let’s create the most expensive GPL licensed WordPress plugin and call it the Pricey GPL. It is offered as a free download from WordPress.org and by default it displays a random paragraph from the most downloaded book at Project Gutenberg in the WordPress dashboard. Of course, there is a widget available, too.

However, to enjoy the real value of the Pricey GPL, you have to purchase a monthly subscription to the PriceyGPL.com service (an API key) which displays a random paragraph from one of the GPL licenses. Read more »