WordPress – fixing wp_options array

You may have noticed that when transferring between your development and production environments, your finely-crafted WordPress site will completely break.

The fact that the url for the site has changed forces you to run a good old find-and-replace on the MySQL backup to swap all instances of the url ro fix all the links – however in certain themes the whole look of the site has broken.

This is to do with discrepancies in the length of the url, and the way in which serialised php arrays are stored.

The culprit is the array held in the themename.wp_options table. My example is below.

Before:
a:4:{i:0;b:0;s:19:"citizensadvice_logo";s:72:"http://localhost/cabwhabac/wp-content/uploads/2016/05/mainlogo_100px.png";s:26:"citizensadvice_homefeature";s:64:"http://localhost/cabwhabac/wp-content/uploads/2016/02/WHABAC.png";s:18:"nav_menu_locations";a:2:{s:12:"primary_menu";i:2;s:14:"header_top-nav";i:0;}}

After:
a:4:{i:0;b:0;s:19:"citizensadvice_logo";s:80:"http://benkent.servehttp.com/cabwhabac/wp-content/uploads/2016/05/mainlogo_100px.png";s:26:"citizensadvice_homefeature";s:76:"http://benkent.servehttp.com/cabwhabac/wp-content/uploads/2016/02/WHABAC.png";s:18:"nav_menu_locations";a:2:{s:12:"primary_menu";i:2;s:14:"header_top-nav";i:0;}}

Posted in PHP Tagged with: ,

Leave a Reply

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

*