Adding dates to custom post permalinks in WordPress

Making date-based permalinks for custom posts in WordPress

If you didn’t know already, this blog is not the only thing that we work on — we also take on clients to work on website and web-related projects for them. Recently, we worked on a website project where we had to code a custom WordPress post type into the custom theme we made for the client (yes we make those).

This custom post type (which shall henceforth be called Articles — what we named the post type) was supposed to serve a purpose similar to the default WordPress Post — it was meant to go into a blog section for the website, and the client wanted to be able to assign categories to individual articles. All of this is pretty standard fare when it comes to WordPress customisation, as you can easily figure out how to do it reading official guides and documentation from WordPress:

We needed something a bit more though, as we wanted to customise the permalinks (i.e. auto-generated URL) of our Articles such that they are:

  1. Preceeded by the article slug, e.g. example.com/article/my-article-title
  2. Display the year and month before the post title, e.g. example.com/article/2021/03/my-article-title
  3. Display a list of articles posted on the specified year and month if it was specified in the URL, e.g. example.com/article/2021/03 would show all the articles posted in March 2021.

Want to find out how we did it? Then continue reading.

Continue reading
Setting up Infusionsoft's PHP SDK

Using Keap’s (aka Infusionsoft) PHP SDK (2021)

If you are creating applications that work with Keap CRM — formerly known as Infusionsoft — you might be unsure where to start. After all, many of the guides available online for working with Infusionsoft’s API are outdated. Additionally, although the official documentation is an option, it’s a little too vague, especially if you are new to the whole web API business.

I recently worked on a project where I had to integrate a set of fields in a web form with Keap’s CRM system — that is, users will fill up a web form, and the information will automatically be sent to Keap’s CRM database for storage. After a lot of trial and error, as well as source code reading, I’ve managed to get my form working.

I’ve put together this guide in the hopes that you can have a smoother journey of integrating Keap’s / Infusionsoft’s CRM into your web services.

In Keap’s / Infusionsoft’s defense, their documentation is much better in their GitHub repository, as they have more concrete instructions and examples. Once the API is set up on your web application, the information in the repository is actually very helpful.

Continue reading
Adding virtual hosts on Bitnami Apache

Adding virtual hosts on Bitnami Apache

Over the weekend, I’ve spent a substantial chunk of time figuring out how to add a virtual host onto a client’s subdomain. In laymen’s terms, this means that:

  1. My client has a website hosted on a domain (which we shall call example.com, for confidentiality reasons)
  2. We want to build a web application on app.example.com, which will be entirely separate from example.com.
  3. To save on cost, we want to host app.example.com on the same server that example.com is using (i.e. create a virtual host on the web server).

This means that we have to configure our web server so that it will serve a different webroot depending on the domain it is being accessed from.

Continue reading
Security for your Ubuntu Droplet

Setting up basic security for your Ubuntu Droplet

Have you recently spun up a new Ubuntu Droplet on DigitalOcean? The other day, when I checked my authentication logs in /var/log/auth.log, I came across several login attempts with random usernames.

Malicious login attempts in Ubuntu
Login attempts by malicious users.

We often take security for granted, but it becomes something of great concern once you start to manage servers of your own. If you were to leave your Droplet as it is, it is only a matter of time before hackers guess your login credentials and gain access to your system. Hence, here are some basic security measures you should set up to prevent others from breaking in:

Continue reading
PayPal Conversion
Original photo by Lukas from Pexels: https://www.pexels.com/photo/analytics-blur-business-close-up-590045/

Save money by being smart with PayPal conversion

In today’s digital era, where everything is becoming smarter and faster, and everyone is about doing things that make them look smart, PayPal is absolutely invaluable. It’s a payment platform that stores all of our payment information across different cards and banks, so we don’t have to remember and re-enter pesky things like credit card numbers everytime we purchase something. Just click on PayPal’s big yellow checkout button! It’s the smart thing to do, right?

Continue reading
Troubleshooting PHP gettext

Debugging PHP gettext

Over the last couple of weeks, I’ve been tinkering with PHP’s gettext to set up internationalisation for one of my web apps (i.e. getting it ready for translation into different languages). Even though there were many step-by-step guides and Stack Overflow topics on the web, all detailing a similar set of instructions, following them did not work things out for me.

After some frustration and a lot of time tinkering, it turns out that these guides were missing some pieces of information. If you are tearing your hair out troubleshooting PHP gettext, this article might be just what you’re looking for.

Continue reading
reCAPTCHA Meerkats
Image by Mike Birdy, from https://stocksnap.io/photo/animals-mammals-VJ91Z8LULN

Verifying Google reCAPTCHA v2 checkbox on PHP

17 July 2020: Updated the class provided in this article to make it easier to use.

For those of you using Google reCAPTCHA to weed out spam on your websites, here’s a code snippet for verifying the reCAPTCHA v2 tickbox response on the server-side using PHP.

Continue reading
Debugging with Beverage

Fixing an Apache cron log rotation error

If you manage a Unix-like server, every now and then, you might get an email from the server notifying you of important errors that occur in your server. Here’s one that I got earlier today from an Ubuntu 18.04 server of mine:

Cron <root@terresquall> test -x /usr/sbin/anacron || ( cd / && run-parts –report /etc/cron.daily )

/etc/cron.daily/logrotate:
error: error running shared postrotate script for ‘/var/log/apache2/*.log ‘
run-parts: /etc/cron.daily/logrotate exited with return code 1

Mail sent at 06:39

It’s never fun to receive server admin emails like this, because it means that your server has issues, but the message tends to be really ambiguous, so it’s really hard to figure out what the issue is. Obviously, I didn’t know what the issues were, so I had to do some research.

Continue reading
Image by Martin Vorel from https://stocksnap.io/photo/KLIK5Q5KX2
Image by Martin Vorel from https://stocksnap.io/photo/KLIK5Q5KX2

A primer on images for game developers

If your work involves sitting in front of a computer, chances are — at some point or another — you’ll have to work with digital images. For most people, it’s more than enough to know how to save images into the right formats. If you’re a game developer though, it’ll help to have a bit more in-depth knowledge, since you’ll be working with game engines that like to throw around obscure terms like true color, bit-depth or ARGB-16.

I struggled a lot with images during my early days in game development precisely because of these terms — Google searches and Wikipedia articles only led me to pages with big words that confused me even more. With time, I eventually figured things out — hence this primer. Hopefully, reading this means you won’t take as long as I did to figure things out.

Continue reading