Software Engineering in WordPress, PHP, and Backend Development

Author: Tom (Page 1 of 424)

Fetch Album Artwork for Apple Music Playlists

TL;DR: I often create playlists for entire albums within my Apple Music library. This means that if an artist releases an album, I’ll still add it to my library, but I like to have a playlist of just that album. Unfortunately, Apple Music doesn’t use the album’s artwork as the image for the playlist.

So I wrote a Python script to fetch album artwork for Apple Music playlists when given an artist and an album. This makes it a little bit easier to make sure album playlists have better looking artwork.


Fetch Album Artwork for Apple Music

Whenever we create playlists within the current version of Apple Music, it gives us the ability to create playlist art that seems to be inspired by the Microsoft WordArt of decades past.

It’s certainly a choice. And for whatever reason, Apple Music doesn’t default to the album artwork for the album in the playlist if it’s just a single album.

Apple Music does allow us to add custom artwork, though. So if I want to add the album artwork for a given album in a playlist, then I can search the web for a high-resolution image and drop it into the editor for the playlist.

Perhaps a better option, though, is to grab the image artwork from the iTunes API. So I wrote a Python script that makes it trivially easy.

After it’s installed, all you need to do is issue the following in your terminal:

$ python fetch-album-art.py --artist="Pink Floyd" --album="The Dark Side of the Moon"

This will grab a high-resolution image of The Dark Side of the Moon and drop it into the script’s directory after which you can add it to Apple Music.

Future State

Assuming Apple doesn’t actually address this in a future version of Apple Music (which, if history is any indication, happens with each official macOS update), then this is something that’ll prove useful [at least for me] for the next little while.

That said, I’d still like to find ways to enhance the functionality so:

  • album artwork is added to its own directory,
  • considering combing through an Apple Music playlist library to determine what albums don’t have artwork (this is subject to the limitation of the API, obviously),
  • provide better visual feedback when the script is searching and downloading the album artwork,
  • and small tweaks like that.

Given that it’s a hobby project, though, it’s one of those that’s subject to the whims of when I want to work on it.

For now, though, this is still one step better than having to find an image via a web browser, download it, then drag it into Apple Music.

Fix: Reschedule Event Error for Action Scheduler

TL;DR: If you’re using WordPress 6.1+ and aren’t able to schedule any type of job with Action Scheduler, this article explains the problem and a potential fix.

Specifically, this seeks to address the following message appearing in WordPress 6.1+:

Cron reschedule event error for hook: action_scheduler_run_queue, Error code: invalid_schedule, Error message: Event schedule does not exist., Data: {"schedule":"every_minute","args":["WP Cron"],"interval":60}

Resolve the Reschedule Event Error

Introducing More Logging

Starting in WordPress 6.1, additional logging was added to WordPress core. Specifically, the patch responsible for this includes the following description:

Rarely and randomly some of my custom cron events have disappeared. From searching around, I’m not the only one with this issue, and no one else was able to figure out why. I also was unable to debug the issue since wp-cron.php doesn’t log any errors nor have any hooks to try handling them. This patch adds those in.

trac

Once this patch was introduced, it also resulted in others experiencing issues with cron and cron-related libraries starting from this ticket and then taking place in a specific forum post.

When you’re trying to create a schedule but it keeps blowing up.

And sure, these tickets are helpful as are the comments and the rest of the discussion in the forum. But there are times when we’re working on a specific task with a specific set of dependencies and need a specific solution.

Action Scheduler and Cron Jobs

My problem was this: I was trying to to register a job using Action Scheduler and the library wasn’t able to register the schedule because of the aforementioned problem.

So the fix was to add this function in my code:

/**
 * Additional logging in WordPress 6.1+ that generates the following
 * message regarding cron schedules:
 *
 * Cron reschedule event error for hook:
 * action_scheduler_run_queue,
 * Error code: invalid_schedule,
 * Error message: Event schedule does not exist.,
 * Data: {"schedule":"every_minute","args":["WP Cron"],"interval":60}
 *
 * This function needs to fire prior to loading Action Scheduler as its a
 * pre-requisite for it to schedule our tasks.
 *
 * This filter seeks to manually add the schedule to the list of schedules to
 * address this bug.
 */
add_filter('cron_schedules', function ($schedules) {
    $schedules['every_minute'] = [
        'interval' => 60,
        'display'  => 'Every Minute',
    ];
    return $schedules;
});

A few things about this code:

  • I don’t recommend using this as a permanent fix for every case. It’s a specific solution for a generic warning.
  • If your codebase is going to be distributed to wide audience, avoid anonymous functions. If you have control over the environment in which it will return, it may be fine.

On the other hand, if you’re using Action Scheduler, WordPress 6.1+, and are trying to register your own jobs and are seeing this message, this will ensure schedules Action Scheduler uses are available.

How to Successfully Deregister Anonymous Functions in WordPress

When I first started writing about anonymous functions in WordPress back in January, I didn’t anticipate it spanning over three articles reaching into the fourth month of the year. But here we are.

That said, this final article in the series aims to help provide a short introduction to a number of technical ideas both in PHP and WordPress to explain why deregistering anonymous functions is nearly impossible.

And it provides a way for us to actually get contextual information about every single hook and callback in an instance of WordPress so we can handle the anonymous functions as we see fit all through the use of a plugin.


Recall from the first article, the reason I started writing about anonymous functions in WordPress all stemmed from a tweet (or post or whatever they are currently called) that stated:

I do wish developers would stop using WordPress hooks with (what I think are called) anonymous functions […].

They are very hard if not impossible to unhook.

And the short of it is that it’s true: Anonymous functions are easy to register against WordPress hooks and are difficult to deregister.

But it’s not impossible.

Continue reading

You Probably Don’t Need An Elaborate Task Management System

At this point in my career, I’ve been working remotely more than I have ever been in an office. I don’t ever want to have to return into an office unless it’s absolutely necessary.

Part of working like this, though, is maintaining a sense of self-discipline for the backlog of tasks required for work and doing so in such a way that makes it easy for me to focus on what I’m working on, what’s next, and what’s in the backlog. (If you’re a developer and you’re reading this, then you’re probably thinking kanban and you’re not wrong – but what I’m getting at is slightly different).

Before getting too much into the rest of the article, I do want to share that the majority of work I do right now is captured in Asana and organized by quarter. We have very little email and very little thrashing between emails, DMs, and other behavior commonly associated with the hyperactive hive mind.

[The] hyperactive hive mind as a workflow centered on ongoing conversation fueled by unstructured and unscheduled messages delivered through digital communication tools, like email and instant messenger.

Ezra Klein Interviews Cal Newport

But that doesn’t mean I don’t want to take a little further to not only help my day-to-day (especially during periods of increased business) but also to help give visibility to other people with whom I work so they know where a given task stands in my queue.

And don’t think this is me elevating my day-to-day any more important than yours. On the contrary. I’m sharing this to help give insight on what I’ve found that works so it may help you, too.

Continue reading

Soft Skills in Software Are Just as Important as Technical Skills

The last point made in 10 hard-to-swallow truths they won’t tell you about software engineer job – in the article I’ve been discussing for the past few months – the author ends on a single point that has nothing to do with development or anything related to technology.

You will profit more from good soft skills than from good technical skills.

He summarizes the statement like this:

Technical skills are the ones you can learn easily. … It’s just a matter of practice.

On the other hand, soft skills are much harder to improve. … You must do things you are not comfortable with.

This is something I think is absolutely worth talking about within our industry especially given we’re not just responsible for solving a given problem.

We should be able to articulate the solution to our team or stakeholders, field questions from them, and garner and manage feedback from them to adjust or improve our work (or, in some cases, ourselves).

Continue reading
« Older posts

© 2024 Tom McFarlin

Theme by Anders NorenUp ↑