Page Builder data lost after migration Last updated:18 August 2016

I’ve spent a lot of time this morning looking into an issue with a client site migration where Page Builder data was lost after the migration.

I have migrated many many WordPress sites by exporting the database, replacing the old URL with the new URL in the exported SQL and re-importing. Never had an issue. But in this case I did, and it’s related to how Page Builder stores data. This data is serialized, and the serialization stores both the data and its length. So a snippet of stored data looks like this:

s:160:"<p><img class="alignleft size-full wp-image-2348" src="" alt="Tulips" width="200" height="150" /></p>"

Super…so if you run a global replace on the domain name you end up with this:

s:160:"<p><img class="alignleft size-full wp-image-2348" src="" alt="Tulips" width="200" height="150" /></p>"

Which looks fine, but it isn’t because the serialization is now incorrect as the length of the serialized string has changed from 160 characters to 166 characters. Result: lost Page Builder data.

The correct update should be:

s:166:"<p><img class="alignleft size-full wp-image-2348" src="" alt="Tulips" width="200" height="150" /></p>"

Clearly doing this is impracticable and fortunately there’s a plugin that handles this which is WP Migrate DB.

imagejpeg issues with PHP 5.4 Last updated:27 November 2014

Came across an interesting little issue this afternoon while debugging an issue with a very old osCommerce installation. This particular site uses an on the fly product thumb generator (product_thumb.php) which worked fine with PHP 5.3 but failed with PHP 5.4.

After a bit of digging I tracked the issue to this line in the original code:

imagejpeg($src, '', 100);

In PHP 5.4 this fails, and needs to be replaced with:

imagejpeg($src, NULL, 100);

Perhaps this will save someone a bit of time. I didn’t find this problem noted elsewhere.

Ordnance Survey maps in WordPress Last updated:16 June 2014

We’ve just finished another site which embeds OS Openspace maps into WordPress pages: Dartefacts. This uses a custom post type to record the grid reference of an object, which is then displayed on a home page map showing all the items, custom taxonomy pages and search results. This works really well with several hundred items (so far) displaying on the home page, and is fully responsive as well.

OS map showing multiple points and a pop up balloon linking to a page

We’re really pleased with this site (and so is the client!). This builds on our earlier site Rombalds Riding which displays gpx routes as well as points.

Getting the lowest level category (or custom taxonomy) for a WordPress post Last updated:6 June 2014

Working on a client project which applies a hierarchical custom taxonomy to a custom post type I needed to find the lowest level set for the post. Assuming that there is only one hierarchy applied to the post the following does the trick, for categories (running on the single post page):

$categories = get_categories();
$parents = array();
	foreach ($categories as $category){
		$ids[] = $category->term_id;//read the category ids into an array
		if ($category->parent) $parents[] = $category->parent;//read the parent ids into an array
$low_categories =  array_diff ($ids,$parents);//get the ids which are not parents
$lowest_category = array_shift($low_categories);//read the first id (just in case there's more than one)

If you’re working with a custom taxonomy called, say, ‘classification’ then this becomes:

$post_classifications = get_the_terms($get_the_ID,'classification');
	foreach ($post_classifications as $post_classification){
		$ids[] = $post_classification->term_id;
		if ($post_classification->parent) $parents[] = $post_classification->parent;
$low_class =  array_diff ($ids,$parents);
$classification = array_shift($low_class);

Hope this helps someone else…

Making this site responsive Last updated:21 June 2014

I’ve been thinking about making this site responsive for some time, but never quite got round to it, in part because only about 1% of the traffic is from mobile devices, but I have finally got around to it. Now this site has grown up over the last, errr, five or six years, and I was expecting it be a bit of a nightmare.

Not so! The css file is pretty large anyway, but to date I have added only 94 css statements to media queries for small screens, and I think I’m nearly there, the only major challenge left is the photography slideshows. I have done this backwards according to conventional wisdom, in that I’ve started with a desktop site and reverse-engineered a mobile site. I can’t quite get my mind around why that piece of wisdom anyway… Just for comparison, bootstrap.css has more than 5000 entries.