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

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