Ordering WordPress taxonomies

I came across an issue the other day when I was working on The Band Company website that required me to order a taxonomy numerically.  The issue was, that even though the items that I was ordering were numbers, they were being ordered alphabetically.  This is what I did to solve the issue.

Continue reading “Ordering WordPress taxonomies”

Using Drupal’s hook_views_default_views_alter

I came across an issue recently with a Drupal installation that I am working on that required me to use hook_views_default_views_alter, and found that the help out there was minimal.  I finally got what I was after working, but with much debugging using the Devel module and dpm.  I thought that I would put down what I found out to help others in a similar position. Continue reading “Using Drupal’s hook_views_default_views_alter”

Coding album of the month

As with most developers, I like to listen to music whilst I code.  The one that I have been listening to the most at the moment is Don’t Look Now by Way Out West.  Check it out on Spotify below.

Its basically a chilled out techno, dance music style album, not too dis-similar to Chicane. Good for getting in the zone and coding too – nothing too distracting going on.

Best way to test email

One thing that can be difficult to test is email, get it wrong and at worst you can end up sending confusing and misleading emails to your clients.  Its easy to get a webserver and a local copy of the database set up, but what about a local email server.

One approach is to create your own mail function, which looks at a system environment to see if it should actually send the mail or not.  For instance, if it is a dev machine, ignore the mail function and write the contents of the email to log.  This is OK, but it doesn’t actually test the email function until it is on live, which is arguably too late.

I have just come across a package called Dumbster.  It is a java application that will sit and respond to SMTP requests, but instead of sending the email on to the recipient it holds on to it in an internal store.  Bingo, we are actually testing the mail function, but the email is being contained.

To get up and running you will need Java, and Ant, and a copy of the source code.  Extract the files and open up a terminal in the folder you placed the source.  Run ant and you should see something like this.

$ ant
Buildfile: /home/ubuntu/rjo1970-dumbster-d20b4e6/build.xml

[delete] Deleting directory /home/ubuntu/rjo1970-dumbster-d20b4e6/build

[mkdir] Created dir: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/classes
[mkdir] Created dir: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test
[mkdir] Created dir: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test/report

[javac] Compiling 29 source files to /home/ubuntu/rjo1970-dumbster-d20b4e6/build/classes

[jar] Building jar: /home/ubuntu/rjo1970-dumbster-d20b4e6/build/dumbster.jar

[javac] Compiling 6 source files to /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test

[cobertura-instrument] Cobertura - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-instrument] Instrumenting 29 files to /home/ubuntu/rjo1970-dumbster-d20b4e6/build/instrumented
[cobertura-instrument] Cobertura: Saved information on 29 classes.
[cobertura-instrument] Instrument time: 174ms
[junit] Running com.dumbster.smtp.MailMessageTest
[junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 0.181 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 29 classes.
[junit] Cobertura: Saved information on 29 classes.
[junit] Running com.dumbster.smtp.RequestTest
[junit] Tests run: 38, Failures: 0, Errors: 0, Time elapsed: 0.079 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 29 classes.
[junit] Cobertura: Saved information on 29 classes.
[junit] Running com.dumbster.smtp.RollingMailStoreTest
[junit] Tests run: 7, Failures: 0, Errors: 0, Time elapsed: 0.049 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 29 classes.
[junit] Cobertura: Saved information on 29 classes.
[junit] Running com.dumbster.smtp.SmtpServerTest
[junit] Tests run: 10, Failures: 0, Errors: 0, Time elapsed: 1.113 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 29 classes.
[junit] Cobertura: Saved information on 29 classes.
[junit] Running com.dumbster.smtp.SmtpStateTest
[junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.038 sec
[junit] Flushing results...
[junit] Flushing results done
[junit] Cobertura: Loaded information on 29 classes.
[junit] Cobertura: Saved information on 29 classes.
[junitreport] Processing /home/ubuntu/rjo1970-dumbster-d20b4e6/build/test/report/TESTS-TestSuites.xml to /tmp/null279172976
[junitreport] Loading stylesheet jar:file:/usr/share/ant/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 701ms
[junitreport] Deleting: /tmp/null279172976
[cobertura-report] Cobertura - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-report] Cobertura: Loaded information on 29 classes.
[cobertura-report] Report time: 237ms

Total time: 10 seconds

You have now compiled the Java, and to run it use the following

java -jar build/dumbster.jar [PORT]

and substitute [PORT] for the port you want to run it on, or leave it empty to run it on port 25, the default for SMTP.

Next make sure that your development setup is configured to use Dumbster as its SMTP server and you are good to go.

Once you have run your tests, or done what you need to do, you can have a look at what Dumbster has collected.  They easiest way is to telnet into it.  Once you have connected you need to be polite and say HELO.  You’re then free to inspect your email.

To see how many emails Dumbster has collected simply type LIST into the terminal.  You should see something like this.

$ telnet localhost 25
Connected to localhost.
Escape character is '^]'.
220 localhost Dumbster SMTP service ready
250 OK
250 There are 2 message(s).

To see an individual message you need to specify the index of the message, with the numbering starting at 0.  You should see something like this.

Subject: This is a subject
Date: Tue, 14 Feb 2012 09:10:57 +0000
To: blog@ghosty.co.uk
From: blog@ghosty

This is an interesting test message.
There are 2 message(s).

Once you are done, type the QUIT command so that you free the server up to run more tests.  The server will only allow a single connection at a time, and so if you leave your connection open, other applications will hang on the connection.


Debugging PHP, with breakpoints!

One thing that I have always disliked about PHP development was the seemingly difficult debugging process that came along with it.  The fact that you would save a file, and then have to open it in the browser to see what’s going on – sometimes to random results.  There was none of the usual ability to step through the code and create checkpoints – something that Java, .Net, and even JavaScript (since the web inspector came about) have had for a while.

Well it turns out that I was wrong. The ability to do this stuff exists, I was just unaware of it, and because of my willingness to accept the status quo, I never bothered to look for a way.

The missing piece of the puzzle is actually something that I have been using for a while. Xdebug. I have been using it to generate grind files, which allow you to profile your script using tools like WebGrind.

Add the following in your php.ini.


Then, in NetBeans, go to your options window and select the PHP tab.  Make sure that the Debugger Port corresponds to the one that you have set in your ini file.

Finally, restart your web server and have fun using breakpoints.

There is also a really useful guide from NetBeans on how to debug PHP using the inbuilt tools available to you.

Theming WordPress using Thematic and Compass

Recently I have started to play with making my own themes for WordPress. Rather than start from the ground and reinvent the wheel, I decided to use a base theme which I can then extend. I also opted to use the brilliant Compass css framework to speed up development. Im going to talk about how I set my project up to get the most out of these tools.

Continue reading “Theming WordPress using Thematic and Compass”

WordPress network on Dreamhost

Recently I have started deploying more and more versions of the WordPress code base for different projects that I have been working on, and a couple of them have been network (multisite) installs.  For those who dont know what a multisite install is, well it allows you to run several instances of wordpress off a single codebase.

There are two ways [out of the box] that a network can run:

  1. Sub directories
  2. Sub domains
If you choose option 1 then when you create a new site it will appear at example.com/newsite, this is very simple to set up, as it uses mod_rewrite to make them appear in the sub folders.  The sub domain option makes sites appear at newsite.example.com.  This, in my opinion is a nicer way of doing things, but it requires that you have the ability to have wildcard DNS for your domain.  Unfortunately this is something that Dreamhost do not provide yet.

But all is not lost

If you log into the excellent Dreamhost panel to administer your account then you can set up your domains, you can follow these steps to get the new site hosted.

  1. Log into Dreamhosts Panel
  2. Click Manage Domainsmanage domains
  3. Click Add New Domainadd domain
  4. Scroll down and fill out the Mirror Domain form. Enter the new wordpress site into the “Create the mirror at” field, and choose the main wordpress network address from the dropdown for the mirror this site field. Finally click mirror this domain.Mirror domain
  5. You should see the success notification.Success

Sit back and relax

Thats it, all done, your new WordPress network site is up and running on a sub domain. Its obviously not as nice as the domain magically appearing out of thin air, but on small-medium sites where you control the setting up of network sites manually you can do this at point of creation.

Thats not all folks

If you also take the time to install the WordPress Domain Mapping plugin, then you can use the process above to host completely different domains off of a single wordpress codebase. How cool is that.