While working on project an interesting problem arose, needing to pass an additional parameter to a WordPress filter. Normally filters only allow for a set number of parameters, but the particular filter needed an additional parameter that could be passed when calling the filter.
The problem was being able to run a WP_Query for a set number of days passed. This is normally accomplished with a simple filter that is applied to posts_where. The problem is the number of days would be variable, since it was being set via a widget option. To get around this using OOP and create a new class that stores the variable and that will be passed when calling the filter. While the example below is a specific solution to the problem above it can be adapted for pretty well any filter that needs another parameter that can be set when calling the filter.
After setting up a new VPS with MyHosting I noticed in the logs all the IP addresses belonged to CloudFlare. This is of course because CloudFlare proxies all the requests to speed up the site with it’s CDN. This is of little use when it comes to tracking down any malicious activity. Luckily there is an Apache module that restores the correct IP address to the log file. I’ll outline the process for getting the Apache module setup on the CentOS VPS.
After being with Dreamhost for a little under 2 years I’ve decided to switch over to MyHosting. I’d had been using Dreamhost’s VPS service for the past few months as their shared hosting had lead to all of my sites being hacked twice, along with poor performance all around. Everything started out fine with their VPS, then came the downtime. I understand the company is growing and some problems might be expected, but on more than one occasion downtime was into the hours. Even this fact was really the deciding factor, it was performance even on a VPS was poor and was constantly having to reboot. The prices for VPS memory upgrades were also terrible $25 for 512MB memory this is on top of the normal monthly hosting fee.
After looking at many, many companies I had a couple in mind. I finally made the decision to switch to MyHosting. I was able to get a VPS with 5 times the memory for much less than I was currently paying. Although storage and bandwidth are limited with the new hosting the prices for upgrades are reasonable. Currently I’d nowhere near exceed the current limits anyway. If your looking for a new host MyHosting, might be the way to go. I’ll update again after breaking in the tires on the new server.
Since the retirement of version 1.0 of Twitter’s API is underway, I’ve been updating the Twitter integration code in the Techozoic Fluid theme. I don’t agree with all the changes to the API, especially the requirement that all API requests, even for public info, must be signed. Luckily someone has already done the hard work creating a library for signing the requests with the proper oAuth signatures. The tmhOAuth library can be found on Github. It will be required for the new functions.
The first step is to register a new Twitter application. After signing into Twitter visit the Applications area of Twitter, and create a new application. After creating the application make sure create the access token at the bottom of the Application screen, this will authorize the application to access your account. You will now need 4 separate keys to properly sign the API requests. You’ll need the Consumer key, Consumer secret, Access token, and Access token secret. These will be added to an array and passed to the function and in turn passed to the oAuth library to sign the request.
While a site owner usually tries to do everything imaginable to create a site without errors, the occasional 404 error will crop up from time to time. Instead of just telling the visitor the page was an error, and increasing the bounce rate of the site, give the visitor other reading options. This is better for the visitor and the site owner. The visitor will be more likely to stay around if the links are to similar topic to the one they were looking for. This is were helpful 404 pages come into play.
The code itself is fairly simple and straight forward. What it does is take the end of the url after the final slash, and strips any extensions like .html, or .php that might have been accidentally added. It then queries for a post or page or any custom post type that has a title with this string. If one or more is found it will output it in a list. If this comes up empty then it will replace any dashes or underscores with spaces and use this as a search string. This will return a list of entries that contain these words. Using these two ways some results should be found and give the visitor something else that should be closely related to what they were looking for.