Any computer program can be designed to run from a single file if you architect it wrong enough! I wanted to create the simplest possible Fediverse server which can be used as an educational tool to show how ActivityPub / Mastodon works. The design goals were: Upload a single PHP file to the server. No databases or separate config files. Single Actor (i.e. not multi-user). Allow the Actor to be followed. Post plain-text messages to followers. Be roughly standards compliant. And those…
Continue reading →
I've written an ActivityPub server which only allows you to post messages to your followers. That's all it does. It won't record favourites or reposts. There's no support for following other accounts or receiving replies. It cannot delete or update posts nor can it verify signatures. It doesn't have a database or any storage beyond flat files. But it will happily send messages and allow itself to be followed. This shows that it is totally possible to broadcast fully-featured ActivityPub…
Continue reading →
I'm a little bit obsessed with building eInk displays. They're pretty cheap second hand. They're low energy, passive displays, with good-enough performance for occasional updates. Here's a new one which shows me what the current cost of my electricity is: Background After installing solar panels, a smart electricity meter, and a solar battery - the next obvious step was a smart energy tariff. Octopus (join and we both get £50) have an "Agile" tariff. Unlike a normal tariff - with a set …
Continue reading →
Here's a quick scrap of code that works. There are lots of outdated tutorials out there for old versions of WordPress. This one is tested to be working in WordPress 6.3.2. This will pop up a confirmation dialogue when you try to publish, update, or schedule a post or page. The Code Add this to your theme's functions.php file: add_action( "admin_footer", "confirm_publish" ); function confirm_publish() { echo <<< EOT <script> var publishButton =…
Continue reading →
WordPress allows you to set a featured image - called a "thumbnail" in the API. This gives a single image which can be used on a listing page, or shown when a post is shared on social media. The WordPress Media Library lets you set the alt text of an image. But, crucially, this alt text can be different when the image is used as a featured image. Here's how to find all your featured images which don't have alt text. One Liner Paste this into wp shell to get a list. foreach (get_posts(…
Continue reading →
PHP has some pretty good error handling and logging, but I do sometimes find it confusing. For example, look at this warning message: [18-Oct-2023 12:34:56 UTC] PHP Warning: Something bad happened in /wp-content/something.php on line 123 OK, so we can go to something.php and scroll to line 123 and try to figure out what's gone wrong. But we don't know which page, post, or URl caused the error. If the error only occurs on /page/test?input=6 and not /page/test?output=7 that would be handy…
Continue reading →
I have written a lot of blog posts. In some of those posts I link to other posts on my site. What's the easiest way of displaying those internal incoming links? Here's what it looks like: Code All we need to do is search WordPress for the URl of the current page. Loop through the results. Then display those links. $the_query = new WP_Query( array( 's' => get_the_permalink(), // This post 'post_type' => 'post', // Only posts, not pages "posts_per_page" =>…
Continue reading →
I like the JetPack related post functionality. But I wanted to customise it far beyond what the default code allows for. So here's how I went from this: To this: Documentation The complete documentation for related posts is pretty easy to follow. This is an adaptation of "Use Jetpack_RelatedPosts_Raw to build your own list of Related Posts". Remove the automatic placement You can turn off the original "related posts" by adding this to your theme's functions.php: function…
Continue reading →
If you use WordPress's HTML5 comments, there's an annoying little gotcha. There's a four year old bug which prevents client-side form validation. HTML allows <input> elements to have a required attribute. In theory, that means the form shouldn't submit until the input is filled in. Sadly, WordPress uses novalidate on the form - as the name suggests it stops any validation. But! WordPress is very hackable. Here's how to make a comment form which does client-side validation and as a bonus…
Continue reading →
There's a new HTML element in town! You can now use <search> to semantically mark up a search box. It's great for letting screen-readers and other assistive tech know what a form does. It's only supported in WebKit for now - other browsers will get it eventually. The WordPress default search widget hasn't yet updated, but I'm going to show you how you can start using it today! In your theme, create a new file called searchform.php - WordPress will automatically load it for the search widget. …
Continue reading →
There's a brilliant post by WordPress about how they've optimised some of the backend code to make it more efficient. So here's a suggestion for something else which can be optimised. If you want to schedule a blog post to be published later, you have to use this WordPress control: I find it mildly annoying. I don't get why part of it is a dropdown. And the number fields don't pop up my phone's number keypad. And I have to look at a different calendar if I want to schedule something for a…
Continue reading →
I blog. A lot. Too much really. One of the things I like to do is see what I was rambling on about this time last year. And the year before that. And so on. So, here's my On This Day page and here's how I built it. WARNING Extremely quick and dirty code ahead! This allows you to add a shortcode like [ edent_on_this_day ] to a page and have it auto generate a list of posts you published on this day in previous years. You may need to exclude that page from your cache. Add these functions to…
Continue reading →