If you use a caching plugin, you may have an option to include custom PHP code when flushing the cache manually — for example, Comet Cache has an “Evaluate Custom PHP Code when Clearing the Cache?” option where you can enter additional PHP code to execute when clearing the cache manually. Adding the following code will also clear the WPSSO object cache when clearing the webpage cache:
| || |
if ( function_exists( 'wpsso_clear_all_cache' ) )
echo 'Cleared '.wpsso_clear_all_cache().
' files and objects from the WPSSO cache.<br/>';
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.
I often want to output an array for debugging purposes, but using var_dump() or print_r() on an array that includes true / false values and class objects can be problematic — false values appear empty, and class objects can include too much information. I wrote the following recursive static method (presented here as a function) to pre-filter an array for readability when using print_r() or var_dump().
There is a huge variety of available plugins for WordPress — 30,326 plugins as of today — and if you’ve tried more than a few, you’ll have noticed a marked difference in their quality as well (functionality, user interface, stability, etc.). If you know your way around PHP, you should take a moment to browse the source code of a plugin before installing it. You’ll notice quite a difference there as well. ;-) You can view WPSSO’s source code directly from WordPress.org’s SVN repository. If you do, please excuse the lack of comments — it’s on my To-Do list. ;-)
I’ve always kept an eye on performance, and used WordPress’s object and transient caches when possible, along with disk based caching when appropriate. NGFB and WPSSO are fast, but until recently, I’d never compared their performance to other plugins. As I prepare WPSSO v2.4.4 for release later this week, I took some time to double-check its performance and that of a few other plugins as well.
If you manage a DNS master, and push zones to several slaves / secondaries, you may have found that over time — as configuration files and firewall rules change — one or more slaves may have lost its ability to update its zone files. Perhaps the slave is no longer being notified, or it may have lost the necessary zone transfer permissions from the master. In a large distributed environment where DNS changes are frequent, checking the SOA serial number for all the NS servers in a zone can be quite helpful — a quick way to eliminate the DNS as a possible source of a problem. Here is a perl script I wrote a few years back to retrieve the SOA serial number for a given domain.
If you are concerned about the quality of your NextGEN Gallery v2.x resized images, this should be of particular interest to you.
Some months ago I contacted Photocrati to ask them how, in version 2.x, developers could retrieve the “actual” dimensions of a resized image. In the past, after resizing an image we could use PHP’s getimagesize() function on the resulting file, but in v2.x image resizing is dynamic and those resized images may not be available on disk. I had some concerns between the expected / calculated image dimensions, those returned by NGG v2.x’s methods / functions, and the actual image retrieved by the URL. All 3 dimensions were different! A resized uncropped image which should have been 300x200px, was reported as being 300x199px by the NGG methods / functions, and the image retrieved by URL was 298x199px!
This may not sound like much, but a few pixels here and there can lead to image distortion when rendered by browsers, alignment issues in page layouts, and failures when working with minimum image dimensions (for example, Facebook ignores images smaller than 200x200px).
I recently added multisite support for NGFB and faced a few challenges — the documentation is a little slim, especially when it comes to uninstalling / deleting plugins. The basic premise is that network-wide plugin activation must take care of the essentials for all sites (like creating default settings in the options table), and when removing the plugin, it should cleanup all its settings from all the sites. I prefer working within classes, so opted to keep the uninstall method in the class, instead of breaking it out into an uninstall.php file.
Recently a client asked me to setup multiple instances of MongoDB on a Linux Ubuntu server. Ubuntu does not use standard /etc/init.d/ scripts, instead it uses upstart, an event-based replacement for the /sbin/init daemon, that handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running. Upstart uses it’s own limited syntax to describe a service or task. I tried launching several processes from a single upstart config, but upstart could not track the service properly. Instead, I broke-up the upstart script into two — one master to define the instances, and another to start each one independently.
If you have a server with multiple interfaces – either public and/or private – your routing table might look something like this:
| || |
sh# ip route list
default via 184.108.40.206 dev eth1 metric 100
192.168.0.0/24 dev eth0 proto kernel scope link src 192.168.0.51
220.127.116.11/23 dev eth1 proto kernel scope link src 18.104.22.168
22.214.171.124/28 dev eth2 proto kernel scope link src 126.96.36.199
This example shows one private interface with IP 192.168.0.51, two public interfaces with IPs 188.8.131.52 and 184.108.40.206, and a default route to 220.127.116.11. This means that any traffic to/from an IP outside the interface’s subnets is sent to 18.104.22.168 — and this is where problems occur (and probably why you’re reading this article). ;-)
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…