WordPress command line PHP

This is a quick overview on running a PHP file via the command line, bootstrapped within the WordPress ecosystem. This sounds like a mouthful, but it’s a fairly straight forward concept. Let’s suppose you have a requirement, where you need to run a PHP script as a one off, or even regularly as a cron job (let’s forgot about WP cron for a moment). The specifc use-case I find arising again and again, is where I need to import data from another source into WordPress. Perhaps the data I’m getting is in a really weird format, from a legacy system, needs to go into a custom system, or a host of other reasons why imports may not already exist for your use-case.… Read the rest

Contact Form 7 – Editing email output of tags

Have you ever needed to make small changes to the output that Contact Form 7 creates for emails? Change a certain word, replace certain characters, etc.? Well here’s the solution:

add_filter('wpcf7_mail_tag_replaced', tag_replace_function(), 10, 3);

Now, this is not a perfect solution, it’s fairly brutish in fact. CF7 did not see it fit to provide you with many avenues for editing the mail output. This filter only provides you with the following information:

  • The replaced text ($replaced)
  • The original values ($submitted)
  • Whether or not is it HTML ($html)

Using this information you can’t do a whole lot, unless you want some really broad changes.… Read the rest

Installing Laravel on an AWS AMI

Today I decided to install Laravel on my AWS instance to have a bit of a play and see if I can’t create something fun. The Laravel website provides incredibly good guides which contain most of the required details:

  • http://laravel.com/docs/4.2
  • http://laravel.com/docs/5.1

Upgrading packages

I am using an Amazon Linux AMI for my instance, which uses PHP 5.3 as it’s standard PHP version. Laravel requires PHP version 5.5.9 or above, so first things first, install PHP 5.6:

sudo yum remove php* httpd*
sudo yum install httpd24 php56
sudo yum install php56-mysqlnd php56-gd php56-mbstring
service httpd start

This removes the old versions of PHP and Apache that are installed, installs updated versions of both, and then will install some extra PHP packages that are required, and finally starts Apache back up.… Read the rest

Using Apache environment variables in .htaccess

In a previous post I talked about using environment variables to make your life easier when developing on multiple servers. In this post I will talk about how to use these variables in your .htaccess file.

Why .htaccess?

You may want some rules specific to different servers, maybe you want to hide certain paths on your live server, or perhaps you want to use a different robots.txt file. Below is a rule I’ve used to server a different robots file on a live server.

RewriteCond %{ENV:TESTSERVER} !yes
RewriteCond %{REQUEST_URI} robots.txt
RewriteRule (.*) robots.txt.block
  • Is the environment variable ‘TESTSERVER’ NOT equal to ‘yes’?
Read the rest

Development Processes – Making WP Config Generic

My Process

When developing a site it’s good to have levels of separation between your development environment and a live production server. I normally have three levels when creating a site:

  1. Development
    • This server is mine, I can do what I want on it and destroy what I please. Clients and users will have absolutely no visibility of it. There will be frequent changes of varying size and complexity.
  2. QA
    • This is where clients start to come in. Using this server they can view major versions that I release from Development when they are ready. This should be a stable server but will have well controlled occasional changes.
Read the rest

Renaming a theme and its folder


Sometimes you are going to want to rename a Theme. Maybe you’re utilising a free theme to base your development work on. Perhaps you’ve just done a huge rewrite on an existing theme. Or even you just think your theme needs a new name. If you want to modify your theme you may as well do a thorough job, as there are some annoyances that’ll show if you don’t. Below I’ve included the considerations you’ll need to account for:

  • WordPress Admin – Appearance -> Themes
    • The theme selector – all of the theme information will be displayed here. You’ll also receive update notifications for themes here.
Read the rest

Test Data

Making a brand new site is great! You get to start from scratch and completely re-imagine and refresh the design. However this can at times leave you with a problem. The new site looks bare! There’s nothing to look at, you have no idea how it’ll look once editors start using it and populating it with data. This is unbelievably important! You can often be surprised at how many bugs and issues spring up when you can’t thoroughly test your new site with data, text, images, and strange editorial practices.

Some of these you can account for, unfortunately it’s not the editorial practices.… Read the rest

Character Encoding Woes

Recently I’ve been plagued with character encoding issues everywhere I go. Inevitably people just do not plan for special characters on their website. English does not generally use them, so it can often slip the mind of developers. Unfortunately special characters are extremely important and if you do not cater for them your website can look unprofessional or just plain bad. This is especially true if you have a team of editors working on your site to provide content – content copied from word processors/publishing software can unintentionally contain special characters such as curly quotes ( ‘ ’ “ ” ) and long dashes ( — ).… Read the rest