If you need to create an array of store hours (for example), the following function can generate an associative array of values quickly, with the hours formatted and stepped (every hour, 30 mins, etc.) as you wish.
I’ve seen similar functions using DateTime(), but we’re already working with timestamps, so there’s really no need.
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’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.