One of the eventual issues you have to deal with when developing a plugin for WordPress, is finding out what went wrong when someone reports a bug. You need to know what the plugin did — what decisions it took as it executed and why. There are a number of PHP / WordPress debugging tools available to developers, but you can’t really ask customers to debug your plugin with these. At most, you can ask them to click a “debug” option so you can get more info about it’s operation. And this is where my WordPress debug / logging PHP class comes in. At first, it was just a way to include a few hidden HTML comments in the webpage, so I could have some clues as to what might have went wrong and where. But the more I used it, the more useful it became. Here are a few examples…
I updated PHP from v5.3 to v5.4 this morning to get the pecl-memcache package (which wasn’t available in the repo for v5.3). I was hoping to switch from APC to memcache for my WordPress object cache (APC gets too fragmented), but the memcached plugin for WordPress wouldn’t add objects to memcache. So in the end, I’m back to using APC for now — at leats until I have more time to debug that plugin…
I’ve found a few snippets of PHP code to read XMP / XML meta data from an image file, but none that I would call very robust or efficient. I ended up writing my own for Underwater Focus, and I’m quite pleased with the result. In fact, after adding support for a shortcode, I packaged it as an Adobe XMP plugin for WordPress.
The first part of using XMP meta data is reading the XMP information from the image. I’ve seen a few solutions that read the whole file into memory, and others that read-in just a small part. If the XMP / XML contains a lot of information, that small part may be incomplete. And each time the XMP meta data is required, the original (and sometimes quite large) image file must be re-read. Since the XMP doesn’t change unless the original image is updated, there’s no reason to keep re-reading the same large file time and time again.
$url = $cache->get( $url );
This morning I had a bit of a challenge parsing Adobe XMP information for images on Underwater Focus. The Adobe XMP is too complex for SimpleXML, and anyway, I only needed a few values — one of them, the LightRoom hierarchicalSubject keywords, is the reason I’m sharing some of the code I wrote.
Using regular expressions to get at single values is quick and easy, but I wanted to create arrays for
rdf:li values, and split each
lr:hierarchicalSubject keyword into an additional second-dimension array.
I wanted filepaths and filenames in WordPress post and page content to be displayed with a monospace font, so I wrote the following PHP plugin to wrap filepaths with a <span> HTML and CSS style tag. The code could be added to a theme’s functions.php file, or used as a stand-alone plugin.
The span-filepaths.php script wraps filepaths and filenames with a CSS ID of “span-fp”, and variables / perl module names with a CSS ID of “span-ftp-var”. Here’s an example of a CSS stylesheet:
font-family:'Vollkorn', Geneva, sans-serif;