A common technique for building an email list is to offer something free to customers in exchange for their contact info. It’s simple and effective. People like reciprocity and don’t mind providing something that is cheap to them in exchange for something they want.
As simple and effective as this strategy is, setting up such a system in WordPress can be a bit difficult. There isn’t an obvious path to a solution.
We find that Gravity Forms is the perfect solution for capturing leads in exchange for free downloads. We recently set up such a system for a client and we found the solution to be elegant and easy to manage.
Ever since I heard about the incredible performance gains possible by using HHVM instead of PHP’s native interpreter, I’ve dreamed of getting this working for some of my larger e-commerce client sites that struggle with performance.
This past labor day, I moved to using ServerPilot.io (again, it’s awesome, get it. now) to manage my servers. It installs a LAMP + LEMP stack by default, but being as awesome as they are, ServerPilot includes a doc that shows you how to setup a LEMP only configuration on their stack.
After using this for a few months, I decided to look into running HHVM on this server, but only for wp-admin requests. My logic is that it is easy to cache frontend pages, but it’s hard to optimize WP admin. And for e-commerce sites, WP admin becomes a regular web application for people who process orders and deal with customers.
It turns out that there are a ton of guides available for setting up HHVM, but not many for setting it up for only certain urls (ie., wp-admin). Accomplishing this took a lot of trial and error. Nginx location directives operate on a best match scheme, so it was difficult to find a configuration that functioned with IF / ELSE logic, especially since Nginx does not allow fastcgi directives within an actual if / else block.
I eventually discovered that you can nest location directives, and that nested rules actually run isntead of the outer directive if they match. This solved my dilemma well, and the rest was easy to setup.
Here is the configuration I ended up with:
If you need help installing HHVM, I highly recommend this guide, especially if you are operating within a ServerPilot managed environment. It is a very lean install plan that reduces greatly the chance of breaking something important:
Feel free to ask questions. I’ll do my best help.
I’m working on migrating a user from a WordPress managed host to a self-managed server that uses ServerPilot.io (which is totally freaking awesome and you should get it asap).
This forced me to do some research on how to properly setup my redirects since I would not have either
.htaccess or a managed list of redirects a la WP Engine.
I found this document in ServerPilot’s docs which shows how to handle domain based redirects and made some simple changes to handle URL based redirects instead. (I think this technique will work with any Nginx configuration, but I’m not positive)
In case anyone else needs it, here is what I came up with:
The example above will redirect http://any_site.com/bags to http://any_site.com/shop. And since it uses RegEx, there’s a ton you can do here.
The ~* tells Nginx to use case insensitive comparison.
Doesn’t get much simpler than that.
I typically use MAMP Pro for local development, finding it to be a happy medium between the commitment and overhead of VVV and running my own LAMP stack.
However, a friend recently pointed me to the comparative leanness of XAMPP, and the ability to use a wild card Virtual Host to simplify adding new sites.
Compare these workflows:
XAMPP w/ wildcard Virtual Host
Both give you a new localhost called http://whatever.dev, which is now ripe for local development magic.
The good news is, it’s pretty easy.
The first thing you need to do is install XAMPP. If you have MAMP or the like installed, be sure to shut off services when you have XAMPP running lest you run into conflicts.
That shouldn’t take more than a few minutes.
Now let’s configure XAMPP’s virtual hosts.
First, open up /Applications/XAMPP/xamppfiles/etc/httpd.conf in your favorite text editor. Locate this line:
And uncomment it by removing the # at the beginning of the line, if it exists.
Now, open up /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
Add this bit of magic at the end of the file:
Note: You’ll need to make sure a sites folder exists in /Applications/XAMPP/xamppfiles/htdocs/. It won’t by default.
Now you’re ready to setup dnsmasq.
dnsmasq is required because Mac OS X doesn’t allow wildcards in /etc/hosts.
This is lame, but it is what it is.
Because of this, we’ll need to setup a local DNS server to handle requests to *.dev. Fortunately, someone has written an awesome, very easy to follow guide on setting dnsmasq up, using the exact configuration we need. So at this point, pop open this guide and run with it:
I recommend using the resolver technique of routing requests to *.dev.
Note: If you haven’t used homebrew before, you’ll need to install that first. It’s also really easy to setup. Go here for more information: http://brew.sh/
Once you’re done setting up XAMPP and dnsmasq, go ahead and create a new directory in your sites directory, add a file, and then restart XAMPP.
Then try to access that file by entering the following in your address bar:
It should work if you’ve followed all of the above instructions.
Enjoy the magic.
Post type archives are ordered by date, descending by default. This isn’t always desirable, especially for content whose chronology isn’t important.
There are a few recommended methods for changing the order of custom post type archives, but the best technique I’ve found is this one:
This example specifically changes the custom post type archive order to order by post_title ascending, but it should be pretty easy for you to figure out how to order by another property and direction.
I have found that this technique is more robust and reliable than using the pre_get_posts hook.
Recently I took on a project where a client needed to generate an image on the fly, with a particular quote and they wanted to scale the text to fit the image on the fly. Which sounded perfectly daunting.
But, I decided to try to tackle the problem anyway.
It turns out there are plenty of tutorials on how to add text to an image with PHP using
annotateImage. But none of them deal with the specific problem of scaling your text to fit in a particular space on the image. Nor do they adequately handle fonts and sizing and text wrapping.
In my searches, I came upon a few pieces that helped me get there, and ultimately resulted in a magic function I’m calling:
Posted a small plugin to GitHub for setting up a global subsite menu in WordPress multisite.
Basically, if you have a multisite WordPress install and you want to create a global menu with some or all of your subsites and show which subsite you’re on, this will help you build that menu.
It doesn’t have many features, and it has a lot of limitations. But I put quite a few filters in it so you can in theory make it do exactly what you need it to.
I’m calling it Network Subsite Menu and I uploaded it to GitHub on the off chance someone else finds it useful.
I’ve been sitting on the fence with WP Migrate DB Pro for awhile. I kept up the same routine of loading phpMyAdmin, exporting, importing, running searchreplacedb2, etc. Painful.
If you are still in the fence, I’d like to firmly shove you off. This plugin is pure gold.
Last week I decided to actually review the plugin to see if it could help me keep my various MAMP, dev, and production sites synced up. After watching the introduction video, I was sold. I decided to take the plunge and by the dev license.
And good gosh am I ever glad I did. This plugin is freaking amazing. It actually makes migrating databases fun. And yes, I know how lame that sounds.
The interface is the best I’ve seen of late. It’s smooth and responsive. I love the instant, subtle AJAX updates. Linking up two sites and saving the profile is lightning fast.
In fact, I’d say even starting fresh and having to install the plugin on both sites + doing the first migration can be done faster than the time required for one manual migration. In other words, it will save you time the first time you use it. Which is saying something.
In addition to database migration, it has a few more subtle features that show the Brad and company know exactly what devs need:
Anyway, I highly recommend it. I’ve even joined their affiliate program. It’s my new favorite WordPress tool.
Click this nice affiliate link to check it out. You can use code SUPER20 to save 20%.
Freelancing has many upsides, and in my case, thus far I can honestly say it has been mostly upsides. I’ve increased my income. I’ve been freed to allocate my time and energy in accordance with my actual priorities (in theory).
I no longer feel the daily stress of wondering whether anyone noticed I was 10 minutes late, or got back late from lunch, left early (maybe even on the same day cough). Nor do I feel the pressure to kiss someone’s butt as a career advancement skill rather than do my best work.
But, with all of these upsides comes some downsides too:
This last one is perhaps the most challenging. I’ve learned to balance the responsibilities of owning a business (mostly, don’t tell my accountant my 1040ES is late). Likewise, cash flow is generally about self-control and keeping up with your invoicing.
But, in the fog, there are moments of confusion, panic, and questions I am supposed to know the answer to: am I as good at this as I thought I was? am I stretching myself too thin? are my clients happy? what kinds of projects do I enjoy working on? where should I focus my time?
It’s when these questions echo around, deprived their answers that I find the most stress. I start to sweat and worry. What if I’m steering the ship into an iceberg and I have no idea? What if the formula that got me here has been lost in the rush of daily operations? What if I will just be another freelancing statistic about people who give it a go, only to rejoin corporate ranks in defeat soon after?
And even more strangely, it doesn’t seem to matter how much success I have. My business could have its highest check book balance ever, and these thoughts can still invade. And, worse, sometimes these thoughts creep up on you during your vacations. When you’re supposed to be disconnected. By design.
I don’t have the answer to this dilemma exactly. Except that, when these moments hit, I generally take a step back and remind myself that I didn’t quit my job to be more stressed. I quit it to be less. I remind myself that more freedom was the goal, and that I was willing to accept that even if I didn’t succeed in more fiduciary ways.
I also remind myself that, at the end of the day, I have to bill about 3 hours a workday to pay my bills. And less than that if I were willing to change my lifestyle. Keeping that perspective, it becomes easy for me to find my way back.
Ideally, I’ll stop having these mini-panic attacks one day and just enjoy the blessing of working lance free without the worry.
How do you deal with freelance stress?
It is for freedom that Christ has set us free. Stand firm, then, and do not let yourselves be burdened again by a yoke of slavery. — Galatians 5:1
P.S. There is possibly some connection between the timing of this post and my viewing Puccini’s Madame Butterfly, which has a determinedly pessimistic bent.