WordUp Brighton – WordPress Gems for Devs by Milana Cap

Last Tuesday I attended the WordUp Brighton WordPress meet up in Freedom Works Brighton. They had a talk from Milana Cap, a very active WordPress developer, covering recent additions to WordPress that developers may not know about. Milana streamed the talk from her home in Serbia and a copy of the talk is up on the Silicon Brighton YouTube channel.

WP HTML Tag Processor

First we were shown an example of using WP HTML Tag Processor, which lets you easily parse HTML within WordPress.

Milana used an example of spotting and removing “nofollow” from internal links which were to versions of the domain that didn’t match the set domain of the WordPress site. This was quite useful as it allowed her to show us a way the code could help in quickly parsing and changing some of the content of blog posts, but it was also a bit distracting as it’s the sort of problem I’d personally fix via updates to the database once, rather than having to run a fix every time a page loads, and that kept tripping me up while I was trying to think of ways I’d actually use HTML Tag Processor within the projects I do.

WP HTML Tag Processor looks like it could be useful and reminds me of Simple HTML DOM, a more general PHP HTML parser that I’ve used in a few projects in the past.

Interactivity API

The bulk of the talk was showing us ways to use the WordPress Interactivity API.

As I now understand it, this allows you to write PHP code within the WordPress block system and the API then builds/accesses various Preact Javascript code to do the interactivity part that you want. So, it sets up AJAX calls, shares data around, and live updates the page, all for you from quite a small amount of PHP. Milana built a simple example of this for us, and kindly linked out to some other examples from the documentation she’d put together for the talk.

I think this is potentially going to be very, very helpful for when I’m building interactive elements within a WordPress project as it’ll save me the time of writing Javascript code to handle AJAX, and API endpoints, by having all that code created by WordPress itself. It’s going to be very interesting to explore what the Interactivity API can do to help add small things to a project, e.g. search autocomplete, something I put in quite often but can be a bit of a faff to add.

Hopefully, the Interactivity API will catch on, which will make long term maintenance of sites and plugins more straightforward as they can use this within WordPress, rather than a site having multiple versions of jQuery, Vue or whatever.

Learning from learning

For me, watching live coding after a long day working on client projects was difficult. It did show us how little code needs to be written to get useful activity on the page, but I’d honestly have been fine with being shown a pre-built version and talked through what it was doing. By the end of the talk I was a bit torpid as I tried to process what we’d seen and come up with uses for it, and couldn’t think of any questions to ask, even though this is a really interesting feature that I hadn’t heard about.

I don’t mean this as a criticism of Milana, she was giving up her evening to present the talk to us and that was fantastic of her. This is a note to myself that if I’m going to an evening talk, I need to balance out what I’m doing during the day so I’ve enough mental energy to really process what I’m watching. I’ve got notes, but being able to understand more about what was going on with the code as I was watching would have been helpful.

Thanks

Big thanks to Milana for showing us these features, both of which I knew nothing about and could have missed out on using, and thanks to Paul Bunkham and Sim Brody for organising WordUp Brighton.

My UK freelancer forum on Reddit hits 6,000 members

I run a small “sub-Reddit,” a community within the site Reddit, for UK freelancers. Today I noticed it had hit 6,000 subscribers, which is a nice big, round number.

When I agreed to help moderate the community, there were 53 subscribers. That was back in September 2013, so growth hasn’t been massive or quick, but I also haven’t put a great deal of effort into it, so I think that’s absolutely fine.

Screenshot of Reddit showing the old interface and the area freelanceuk, which is at 6,000 subscribers

History

Originally, I responded to the previous moderator who was asking for help as I didn’t want the “sub” (subsection of Reddit, basically a forum) to die off. It turned out he wanted to leave moderation of it entirely, but the tasks were not onerous so I kept it up. I thought it would be a useful place to get inspiration for help pages for the Farm’s website. I haven’t done too much of that, but writing this did prompt me to request a file of all of my Reddit contributions so I can extract the useful bits more easily than trawling through my comments on Reddit itself.

Reddit as a place to be

To be honest, I don’t like Reddit much any more. Like any very large forum-style site on the web, it has a large share of absolute bellends difficult people with offensive views, which in the past the site management did very little to control, but it also had pockets of loveliness and the sub-section for talking about written science fiction particularly filled a hole for me left when Usenet became harder to access, and has managed to stay decent for many years. But the Reddit management has been making choices I’d rather they didn’t for a long time, most recently stopping free API access for mobile apps and making that access extremely expensive to force everyone to use their own apps, and now selling everything people contribute to Google for their use training their LLM (AI) project.

Long term I’d like to move off Reddit, but I haven’t had time to set up an alternative, and I know it will get less use. FreelanceUK has added about 2,000 members in the last year and a half. That’s because Reddit is a very popular site. Moving off to my own space will not get that sort of traction without a hell of a lot of effort, I’ve got it on Reddit just by removing some junk posts and answering questions that I can answer.

Running and growing a small sub-Reddit

The running part is quite easy as this is a niche interest so there isn’t a lot of spam or heated arguments, it comes down to:

  • Have some clear rules about what can be submitted
  • Check all submissions, ban people who submit spam the first time they submit it. Warn people who post borderline stuff but are probably a bit clueless in a comment, and remove their post which takes it out of view
  • If people end up arguing with each other, step in and suggest they just leave it as they’re not convincing each other, mark your own post as a moderator so they take the advice seriously. Almost always, they’ll stop. Sometimes, they even apologise to each other (this may be a British trait.)
  • Don’t get angry when people don’t like what you post yourself

On this last point – I occasionally submit links to what I think is an interesting article or tool. Often these get downvoted. It really doesn’t matter. People’s reasons for downvoting are myriad, don’t let it get to you.

I use an RSS Reader on my phone to check for new submissions to FreelanceUK. That lets me catch and remove spam pretty early, and that helps keep the forum professional looking. Spam breeds spam, so it’s best to get rid early. I find it very difficult to use the mobile version of Reddit to ban spammers, so often it’s a case where I’ll remove their post, then ban them when I’m next on my computer. Banning only stops them posting to my little area of Reddit, they’re free to use the rest of the site as usual.

Growth is harder. I have found people respond best to posts on Reddit itself. They don’t want to follow a link to somewhere else, they want to consume right where they are, and I think social media is the same way – people would rather read a screenshot of something within the site/app they’re using rather than click through to somewhere else where it would be easier to read.

I’ve made some posts on Reddit of content I’ve written for this blog or the Farm website, but mainly what I’ve done is answer questions. If someone has a question about freelancing that I can answer, I do so. Now the forum is bigger, if I’m busy I’ll leave it for a while and often a member will give a good answer and I won’t have to, but if it’s been a long time, like a day or two, and no one has answered, I will find the time.

I will upvote people’s questions and the good answers, even if it means Reddit will boost their answer over mine. The “karma” system of points within Reddit doesn’t really mean anything, but we are all distractible chimps at heart and it doesn’t cost anything for me to give people a little boost in their day by seeing someone appreciated their comment.

That’s basically it – keep things civil and on topic, be helpful. It means growth is slow, but I can keep it going without much effort and it can be a helpful place to people. I don’t need it to be more than that. A small, low maintenance project that helps people doesn’t need to become something bigger or “better,” it can just be what it is.

Whitelisting an email or domain in Mailgun

Recently a client who uses Mailgun to send email from their website had a problem where one of the clients own email addresses had been “suppressed” in Mailgun, meaning Mailgun would no longer send email to that address. It was caused by the client’s mail server having a problem for long enough that Mailgun decided they couldn’t send email to the particular address.

Mailgun have the ability to “whitelist” individual email addresses or whole domains so they will not stop sending to them. That’s exactly what I needed to put in a long term fix for this problem. It’s not available through their website, but you can do it through their API. That was fine, we’re using the API for other things so I can adapt some code to use it for this.

Unfortunately, the docs for whitelisting an email address are currently incorrect. I had some back and forth with their support people and they gave me the following curl example for how to whitelist an email address:

curl -i -X POST  -u api:[your api key] https://api.eu.mailgun.net/v3/[your mailgun domain]/whitelists -F address=[your email address]

Where [your api key] and [your mailgun domain] and [your email address] get replaced by your details.

Remember that if you’re in Europe, you’re probably using the EU API, not the one in the docs, so you’ll need to change the API domain to https://api.eu.mailgun.net

To whitelist a whole domain, use:

curl -i -X POST  -u api:[your api key] https://api.mailgun.net/v3/[your mailgun domain]/whitelists -F domain=[your email domain]

Finally, to check the whitelist, use this:

curl -i -X GET  -u api:[your api key]  https://api.mailgun.net/v3/[your mailgun domain]/whitelists

This was a frustrating situation as it took a while for their support to understand that giving me back the incorrect examples from the docs wasn’t helping, but they did come through for us in the end and were polite and trying to be helpful throughout. Hopefully they’ll get their docs updated soon.

Using ACF Blocks by default in a new post in WordPress

One of my clients has a website using Advanced Custom Fields (ACF) Blocks to style everything in the site, including their News section.

To make a new post in News, they had to load a Pattern of the relevant Blocks. This being a multi-step process, and a bit annoying if you just want to get on with posting your article, I looked for a way to load the blocks into the new post by default.

You can do this by putting this code in your functions.php (with amends explained below)

function site_post_register_template() {
    $post_type_object = get_post_type_object( 'post' );
    $post_type_object->template = array(
        array( 'my-blocks/news-header' ),
        array( 'my-blocks/news-article' ),
        array( 'my-blocks/news-article-related' ),
    );
}
add_action( 'init', 'site_post_register_template' );

In this case, I have three Blocks loading – the specific header, the article, and a strip of related articles. I can load in as many Blocks as I want.

To make this work for you, find where you have saved your blocks and list them out in the same way, in an array for each.

You will have to change ‘my-blocks’ to the prefix of your ACF Blocks. To find that prefix, go to the directory where you store the code for the relevant Block and open the block.json file. Copy the details from the “name” line to be inside the array( '' ), above.

Now, when a new Post is started, it automatically loads in the ACF Blocks and my client can get on with posting their news, not thinking about how they load in the Pattern and where they left my instructions for doing so.

New website for G2 Legal

I am delighted to announce the launch of a new website for legal recruitment agency G2 Legal.

Screenshot of a recruitment website showing their main branding and some legal jobs

The G2 Legal website from 2017-2024

Screenshot of a new recruitment website showing their main branding including a woman and their tagline Passionate about matching talent

The new G2 Legal website (click for larger)

I have a very long relationship with G2 Legal, this is the seventh complete website I’ve helped build for them and it was very much a group effort.

The Team

Amy Walker – Head of Marketing at G2 Legal – acted as primary contact and driver of the project. She handled researching and collating all of the company needs, boiling them down to the necessities and messages that can fit on a website, writing all of the content, and a huge amount of project management. This website does a great job of representing the company, and that is down to her and the work she put in both with Nick and the whole project.

Nick CarterStudio Gallant – design and UX. Nick is a fantastic designer and I’ve collaborated with him on several websites for clients. As usual, he did a fantastic job of taking the client brief and making a design that is contemporary, professional, and will stay fresh for many years. He worked closely with Amy to make sure G2 Legal got what they needed from this project and I think he did a very, very good job.

Jim LesterZero1Zero – front end build. Jim came highly recommended by Nick and I can see why. He made a great translation of Nick’s designs into working templates with clean, understandable HTML, CSS and Javascript in short order and was more than helpful when we had some late additions to the project. He was a delight to work with and I hope I get a chance to again in the near future.

Paul SilverSilver Web Services – back end build, integration of front and back ends. More on my part below, but in brief I handled moving the website from one set of back end code to another, took Jim’s templates and turned them into a working site which can be edited by the staff at G2 Legal, and handled various search engine optimisation tasks.

The site became a much larger project than planned and I am delighted with the way it has come out. Thank you to everyone who was involved with the project, I hope you’re as proud of the outcome as I am.

My part of the project

Laravel to WordPress

Being a programmer, most of my work is hidden away. Previous versions of the website were editable by the staff at G2 Legal, but the content management features were little used and had therefore not had much in the way of updates for over ten years. Now, the company has an active marketing department headed by Amy and the website needed to change. Their main requirement from the tech was to have a site they could easily edit and preview changes so they could see the pages as they would be published, not just parts of them.

The previous site was based on Laravel and various custom code written by myself and Laura Tyler. I assessed various Laravel based Content Management Systems (CMS) to see what we could add to the existing code base to do what was required, but I found them all rather lacking from a user experience viewpoint. The people updating the website are not techies and should not need to become ones in order to get their job done. I looked further afield for better tech.

WordPress for a modern editing experience

A solution came thanks to Hazlitt Eastman, who showed me a project he was making in WordPress using their latest editor with helpful additions from Advanced Custom Fields. It gives the site owner a very good editing system and preview and allowed me to get very close to the perfect experience for the client within their budget. Hazlitt kindly gave me a training session in how to set up the “blocks and patterns” involved in making the editing system pleasant to use and extra technical support across the project. Big thanks to Hazlitt for this, he got me out of several technical holes.

A lot to port

Originally I was thinking I’d use Laravel to run an API which the WordPress site would make requests to. For most of the site, that turned out not to be the right choice when I looked at the long term maintainability of the code, and considering at some point they may want another developer to work on the project. So, most of the backend code moved from Laravel to WordPress style PHP. The site may look simple, but there are a lot of hidden depths to it, including a very advanced job search both on the backend and with a new experience on the frontend which meant writing new APIs, which WordPress easily handled, and a lot of Javascript.

The intricacies of moving all of the code was a much larger task than I expected, but I think gives us advantages over the short and long term: the speed of response of the website wouldn’t have been as fast if I had stuck with my original plan, and changes over time would have been more convoluted as we’d be working with two quite different styles of codebase rather than just one within WordPress.

Looking at the long term

The previous website was live for a little over six years and went through many changes as company needs changed. It ended up as a bit of a patchwork of the original and new looks and features. I’m confident this site is flexible enough to work with changes G2 Legal needs over the coming years and will still look good at the end of it.

Hear’s to Amy, Nick and Jim for all the help getting it there with me.