Subtitle Migration: From a Theme to a Plugin Subtitle Migration migrates old theme subtitles to compatibility with the Subtitles plugin.

Recently, some theme shops have been acquired by larger hosting companies. Thus, getting a copy of a theme that you want is now more difficult unless you use said host.

For those who typically read this site via RSS (or some other means), then it’s worth noting that I’ve changed this site back to a stock theme (Twentyseventeen, actually).

Subtitles Migration: A Change to Twentyseventeen

The short reason being that this is a theme that is likely to be long supported since it’s built by the WordPress.org team and it’s going to play well with all of the new and upstream features.

But when changing themes, I lost one of my favorite features: Subtitles. That is, each post that I wrote had its subtitle to help explain and give context to what the rest of the article was about.

I’ve been familiar with Philip Arthur Moore’s Subtitles plugin for some time.

Subtitle Migration: Moving to Subtitles

And the way the previous theme was built along with the way this plugin is built made it possible for me to write a small plugin to migrate all of the previous theme subtitles to the plugin subtitles.

Here’s how where it is, how to use it, and how it works.

Subtitle Migration

Subtitle Migration

Here’s the short of it:

Migrates old theme subtitles to compatibility with the Subtitles plugin. This is for developers. Review the readme.

That was the short description of the plugin states in its repository.

For the developer-types, I’m going to get more into how it works later in the post, but the gist of the plugin is this:

  1. Install it,
  2. Activate it,
  3. Run it (given the prompt it provides),
  4. Deactivate it,
  5. Delete it.

And that’s it. Simple, by design, and does one thing and one thing only for a very, very specific niché case.

Where It Is

You can find a copy of the plugin on GitHub. This is the only place I’m hosting it.

You don’t need a GitHub account to grab a copy of it, though.

Instead, you can download it directly from the repository (though I recommend renaming it subtitles-migration.zip rather than subtitles-migration-master.zip) to make following along with the instructions a bit easier.

How To Use It

Note that this plugin has a hard-coded value that will need to be changed depending on your installation. This is why it’s a developer-oriented plugin.

Specifically, if you take a look at this line, you’ll notice that it’s looking for a specific key in the post meta data table. This value will need to be changed:

  • if the theme you were using uses a different key,
  • if and only if the value is stored in the post meta data table.

That is to say that if your previous theme does not use the post meta data table, this plugin will not work.

Assuming all of the above looks good, then you should be fine to run the plugin. So upon activation, you can assume the following the course of action:

  1. Assuming you have the proper permissions to run the plugin, it will ask if you want to migrate the old subtitle to that which is compatible with the Subtitles plugin.
  2. When you run the plugin, it will attempt to make a change. If it’s successful, you will see a message that says as much, says you can deactivate the plugin, and then delete it.
  3. If the plugin encounters an error, it will write an error to the Debug log which can be used to provide diagnostic information for improving the plugin (so don’t hesitate to report an issue or anything like that).

And that’s it.

Subtitle Migration: Easy

But for the developer-curious, how does it do what it does?

How It Works

Since this plugin is aimed at developers (since you may have to modify the code for it to work on your installation), I want to make sure to breakdown how it works.

  1. Once the plugin is activated, it makes sure the user has permission to run the plugin. If so, it proceeds; otherwise, it stops.
  2. If you have permission to run the plugin, it will present a message to you after activation. Once you click on the anchor, it will redirect to the same page with a specific query string.
  3. The plugin, if it has permission and has been started, will attempt to update all meta values in the post meta data table by changing them from the previous subtitle key to the Subtitles plugin key.
  4. If it succeeds, it will display a success message; otherwise, it will display an error and write an error to the debug log that I can use to help improve the plugin.

Though the code is namespaced, it’s written in a procedural manner (again, this was a very quick write for a migration I needed), and it lacks some practices around DRY code, internationalization, and so on.

But that’s where the future of the plugin may or may not happen.

Future Development

This is the plight of every plugin developer, isn’t it? That is, will this continue to be updated, developed, and generally improved?

I don’t know.

I’m going to be keeping an eye on the repository, it’s stars, forks, pull requests, and any feedback I receive via email or Twitter.

There are certainly a few things that I’d like to introduce, but for spending a little bit of time on an afternoon to put this together for my purposes, it works well enough. It’s just a 0.1.0, as well.

For example:

  • I need to document and rename one of the functions,
  • I could easily improve the functionality around displaying messages,
  • Adding support for internationalization might be a good idea (but, again, this is a super niché plugin),
  • And so on.

I don’t know if anyone else needs us, so I’m not sure it’s worth my time to continue building it out when there’s so much else to do. So I’ll let those who might need it decide.

We’ll see. So let me know one way or another (all of which I’ve already listed above 🙂).