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).
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.
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.
At WordCamp Cape Town 2014 I presented a workshop on building your first WordPress plugin. It was a pleasure to share my experience with everyone who attended the workshop and, as I promised at the end of the workshop, here are a few links regarding what we learnt.
There are many use cases for allowing users to upload files from the frontend, but the trick is making sure the file is uploaded and saved in the WordPress media…
Building an options page for a plugin can be a daunting prospect, so here’s a single class that will help you to create a versatile and user-friendly options page for your plugin that fits neatly into the WordPress dashboard.
With WooCommerce 2.1 having just been released, you’ll find that a number of functions that you have been using in your plugins and themes have now been deprecated in favour of better and more aptly named functions. Here is a simple function that checks if a site is running the specified version of WooCommerce or higher.
If you have ever wanted to display your posts (or a post type archive) in a random order, but keep the pagination consistent then here’s your solution.
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.
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.
In order to minimise the amount of plugins your site uses, here’s a simple function I use to show a post’s featured image in the RSS feed (something WordPress does not do by default).
When creating web apps, there’s often a need to generate a random password for your users. There are a number of ways to do this, but in needing to do this recently I came up with this very simple function that will generate a password (or other random string) of whatever length you wish.
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.