Getting Started With WordPress Development

Last night I spoke at a meetup of the Cape Town PHP Group. I was speaking alongside the excellent Gareth McCumskey who was giving a run down of what we can expect in PHP 7 (we can expect a lot of awesomeness by the way – you should really check that out). My presentation for the evening was a primer on WordPress development and a guide on how to bend WordPress to your will (which would have made a way more awesome title for the talk).

WordPress: Check if user role exists

As part of a recent Sensei update we added some custom capabilities to the editor role, but we discovered that some people have deleted that role from the database as a way of cleaning up unused data on their sites. This meant that our add_cap() calls were causing fatal errors for these sites. Here’s how we solved this problem for ourselves.

Build user appreciation links into your plugin

The other day I posted about showing plugin developers appreciation and how it’s actually really easy to do. The problem, as was pointed out to me, is that writing reviews, donations, etc. are all only accessible from the plugin page on the repo and there’s no quick way to get there from the WordPress dashboard. All is not lost, however! It is possible to add custom links to the plugin list table alongside the default links that point to the author’s website and the plugin details page.

Easily generate a month select box in PHP

Having a drop down menu for month selection is a relatively common need, but it can be a pain to write from scratch each time. Here’s a short snippet that will generate a select input (drop down menu) for all 12 months of the year – the option values will be the month numbers with leading zeros.

WordPress: Add plugin settings link to Plugins page

When building a plugin that has its own settings page, it’s often handy to create a link to the settings page straight from the Plugins list – this saves users the time it takes to find where exactly your plugin appears in the admin menu. Here is a simple code snippet that creates the settings link for you – all you need to do is tell it where to go.

Loop through each character in a string in PHP

The other day I was working on a project that required me to extract a numeric ID from the current page’s URL. The problem was that the ID could either be at the end of the URL string or in the middle, depending if there were any parameters added on or not. Here is how I worked around the problem by looping through each character of the string.