SPLOTs just won’t go away [from this blog]. I recently celebrated some success in building a new part of the machine, then realizing it’s use case might be narrow.

So while no one needs say a third arm, the process of designing it often has unexpected payoffs later.

It Came About Because I Messed Up My Development Space

This all happened because of my ineptness at managing command line jujitsu somehow I had pretty badly mangled my laptop set up of Varying Vagrant Vagrants the weirdly named system that lets my run WordPress as a local system on my laptop.

The fix ended up being just starting a new directory with a fresh install, but I faced some issue in moving over a fleet of test sites. I’d known this for a while, and thought about maybe once while walking the dog, but I had no means of saving and restoring all of the SPLOT options in one site. The only recourse was old school manually checking a source site and making the same settings in another.

In general the copying of one WordPress site from one place to another is never trivial. Oh there are plugins that offer a copy capability, but there’s always a catch or an upsell that ever makes it clean.

If you are working with a Reclaim Hosting WordPress then you are in luck, as their Installatron tool offers a means to clone one site from say a domain of your own to maybe another subdomains of your own. It deftly does it well, but that’s only if you are within sites you own (I did find out there is an advanced metod if you have FTP access to a source site).

So making a copy of a WordPress site is more than just exporting the content:

  • You have to install the same theme and plugins
  • The media can be transferred only if the source site is publically still available
  • You resort to extra plugins to say import/export Customizer settings and Widget settings.

Someone will reply with some plugin that does it all in one swoop (yes for a while I had success with All in One or Duplicator) and render my arguments useless.

But this is all to day that the SPLOT Theme settings in my stuff are not part of any WordPress export I know of.

I was fairly sure there was someway to save these settings as a JSON file that could then be imported to another site.

All of this to say I got it working and it’s available now in the current version of TRU Writer.

Coding it Up

I looked at a number of posts and Stack Exchange responses, but the one that got me there was Building a settings import and export feature from Pippins Plugins. I’ll save the usual long code blathering, to show that the layout of the SPLOT Options for TRU Writer has a new look and function.

TRU Options interface has been updated with a new TAB for Import/Export

Previously there was a tab for documentation, and I would go through a tedious process to convert the markdown from Github to HTML so to offer a version of the documents right there.

But it seems easier just to link to the documentation, which one day might make use of Paul Hibbitts’s amazingly elegant docsify publishing kit. So now there is a tav for the import/export options for the site’s SPLOT settings.

Nothing terribly impressive visually, but the Export button initiates creation of and download of a JSON file with all the settings, which in all their glory look like:

Thrilling, ain’t it data? The trickier part was the import … well maybe not. It is just something that parses the json, and changes the values of the settings as displayed. Then it’s on the user to accept and change them.

After the excitement of getting most of it working, I found the shortcomings. One was that things like categories and images are saved as just a database ID. So an mage with an ID of 12 means nothing on another site.

I did figure out a way on the settings save to change that value from an ID to a URL for the image. Then, on the importing end, it downloads a copy of the image, adds to the media library, and now it has a database ID (I ended up learning how to use media_sideload_image()!)

Shrug

I do not know if anyone really will have a need for this appendix-like appendage, but the real gain was some code banging to figure out saving and importing og settings as JSON data.

I almost feel like I know what I am talking about.

This will find its way to other SPLOT themes in time, so look soon for a feature you may never use.

But I did get my victory dance in when it actually worked.


Featured Image: Lufkin 7R flickr photo by cogdogblog shared under a Creative Commons (BY) license modified by me to feature the SPLOT EXPORT text.

If this kind of stuff has value, please support me by tossing a one time PayPal kibble or monthly on Patreon
Become a patron at Patreon!
Profile Picture for CogDog The Blog
An early 90s builder of the web and blogging Alan Levine barks at CogDogBlog.com on web storytelling (#ds106 #4life), photography, bending WordPress, and serendipity in the infinite internet river. He thinks it's weird to write about himself in the third person. And he is 100% into the Fediverse (or tells himself so)

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *