WordPress is a long running machine, and in most of my 11 year experience using it, have found it rather forgiving with old code and themes.

With the 4.7 WordPress update, I have been seeing a problem with the Feed WordPress plugin, and despite a fix I found that cleared the error, tonight I found the fix broke other related plugins.

Sadly the developer of this plugin much of my syndicated blogging work has revolved around is a bit absent on issues with his code.

That has to wait for another day.

I ran into another problem with a plugin, it’s one that presents code I put into my blog post into a more readable format. Syntax Highlighter Plus has worked without problem on my site for several years, but tonight, it’s borking. The problem has to do with some new way WordPress has coded global filters. I could not untangle the code enough to find a remedy.

The first recourse is disabling the plugin. The problem this presents is that the way it worked is I wrapped all my code with a pair of shortcodes like:

Nearly all my stuff has an attribute for lang= of php or javascript. This is the hitch of using shortcodes; when I disable the plugin, my posts are going to be littered with bits of [sourcecode lang="php"] ... mumbo jumbo .... [/sourcecode].

My strategy was to find another syntax formatting plugin (there are quite a few), and Crayon looked like a good pick. It’s recent, has a fair number of installs and reviews.

I installed the plugin and tested it. Yup, it formats code. The thing is that uses a different (and better IMHO) construct than shortcodes; it wraps code in [crayon-59e8bb0a001ec032733147/] tags with a class attribute that defines the display language, e.g.[crayon-59e8bb0a001ef008435440/]

I started thinking about a function I could add to hook into the_content to do a search and replace on the shortcodes. I even got as far as getting a grep search to work.

The I thought of an easier plan. I just need to do a one time search and replace on all posts that used these tags. And I remembered you can do this on the database in phpMyAdmin. I fired up mine via my lovely Reclaim Hosting cpanel.

I fund the wp_posts table in my blog, that’s where all the content for blog posts live and breathe. Actually I first duplicated the table in case I messed up.

I clicked the SQL tab so I could run direct queries (not for the feint of heart), and ran this one to replace all the closing [/sourcecode] shortcodes with </pre>ones:

Bam! I got like an update to 38 posts. I checked one. Sure enough the search and replace worked. I then ran a few more like:

or in phpMyAdmin:

Note: I spent way too much time getting [crayon-59e8bb0a001f1558397112/] tags, so I set it’s default to use the Plain White theme and to never show the toolbar for those boxes where I did not want code formatting.

THEN I ran my mySQL updates to modify the ones where code was used, to replace with tags that include a darker Crayon theme and to show the toolbar.

I better stop now….


Top / Featured Image: flickr photo by waferboard https://flickr.com/photos/waferboard/30182796173 shared under a Creative Commons (BY) license

Profile Picture for Alan Levine aka CogDog
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.

Comments

  1. bitrot like change is a constant :-) good luck on the bitrot in the Feed Press WordPress plugin; i feel your pain and like you I have felt the pain of plugin-in/add-on breakage on many pieces of software over the 3 decades I’ve been in the software industry.

    This is why I try to avoid using plugins and add-ons in any software (emacs, firefox thunderbird, heck even jekyll where I am using the default theme); eventually they all stop working without some sort of change usually non-trivial

Leave a Reply

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