Leaving Behind The Last Vestiges Of Gutenberg

It’s no secret that I do not especially enjoy the WordPress block editor, otherwise known by the last name of the originator of printing with movable type, and for awhile now I’ve had it completely disabled. My themes of late, then, have been non-block ones, and using the Jetpack plugin I write my posts in Markdown right in the old-fashioned Classic Editor.

There’s been one last thing nagging at my OCD, however: the posts I’d previously written using the Markdown Block.

I’ve spent several weeks trying the WordPress forums and even, briefly, Reddit trying to see if anyone already had a way to convert posts written using the Markdown Block into posts written using Markdown in the Classic Editor. Thanks to the forums, I’d already learned how Markdown in the Classic Editor stores its posts.

If you open a Markdown Block post using the Classic Editor, what you get is first the Markdown but in a wrapper of wp:jetpack/markdown {"source":""}, followed by the HTML generated by that Markdown in a wrapper of <div class="wp-block-jetpack-markdown"></div>. (Technically the Markdown wrapper is inside HTML comment tags but when I try to put that in a code block, this post breaks. I’m not going to spend any time on figuring out why.) All of this is stored as-is in the normal spot in the database: post_content.

However, a Markdown in the Classic Editor post stores the Markdown as written in post_content_filtered and the HTML generated from it in the usual post_content. This way, if you ever turn off Markdown in the Classic Editor, WordPress is still able to display the generated HTML.

So, it’s superficially straightforward enough: I needed a way to pull the Markdown out of a Markdown Block post and save it in post_content_filtered and leave the bare HTML, minus wrapper, in post_content. All of which nontheless was beyond me.

In the end, this week I sat down with ChatGPT to figure this out, and the solution eventually required learning one more thing about how these posts are stored in WordPress that the forums didn’t let me in on: Markdown in the Classic Editor posts have an extra bit of post_meta: a key of _wpcom_is_markdown with a value of 1. It took about an hour of tearing my hair out in a local install under MAMP to figure out why the conversion answers ChatGPT was giving me weren’t working, and it was this metadata.

At any rate, when all was said and done, the process required a couple of different steps.

  1. First, this PHP script to decode the Unicode characters within the Markdown in posts written using the Markdown Block, so that the Markdown would present as nicely human-readable the way it is in Markdown in the Classic Editor posts).

  2. Second, this series of database queries, to apply the Markdown in the Classic Editor metadata to Markdown Block posts, and then to split the Markdown and the HTML into their respective Markdown in the Classic Editor database locations.

Not until late yesterday did I discover that I did have one post that tripped up this entire process: I’d written a post about Raphael Devers’ batting struggles using the Markdown Block but I’d made the table using the block editor process for tables. This resulted in two different segments of what was stored in post_content having the Markdown-wrapping string the ChatGPT solution uses to make changes.

To wit: only what appeared below the table actually made it through the conversion, and I only discovered it entirely by accident—followed by maybe half an hour of a sort of panicked scrambling to make sure nothing else had been lost. The missing parts of the post I restored using the Wayback Machine.

With all posts now stored as Markdown in the Classic Editor posts, I believe that I’ve finally and fully transitioned away from having anything to do with WordPress’ block editor. It’s not needed for what I do, and arguably gets in the way of what I do, and now there won’t even be that voice in the back of my mind nagging me about its last traces under the hood.