Resolving Bad Code During Migrations


Every once in a while I’ll run into a WordPress site with really outdated code that breaks when migrating to a modern WordPress host provider. Here are a few common issues I see along with some tips for resolving.

PHP tags need to start as <?php not <?

While an older web server might be able to understand both, newer web servers tend to be more strict and need <?php when beginning PHP tags. By using SSH, the following command will search all PHP files for bad PHP tags. The second command matches <? next to a new line.

grep --include "*.php" --line-number --recursive "<? " wp-content/
grep --include "*.php" --line-number --recursive "<?$" wp-content/
grep --include "*.php" --line-number --recursive "<?}" wp-content/
grep --include "*.php" --line-number --recursive "<?$(printf '\t')" wp-content/

HTTP links should not be hard coded

The web has embraced HTTPS, and if you’re not running HTTPS then do that now. In addition to updating http links with the database, hard-coded links are often missed. I generally see hard-coded links within custom WordPress themes, however it could be other places too. Searching the entire wp-content directory typically finds them all. 

grep --line-number --recursive "http://my-wordpress-site.com" wp-content/
grep --line-number --recursive "http://www.my-wordpress-site.com" wp-content/

New versions of PHP can cause PHP fatal errors

PHP fatal errors will make pages load incomplete, or not at all. These often happen when moving to higher version of PHP due to outdated code. Viewing the errors often requires access to the server logs so check with your host provider. With Kinsta you can simply run tail -f logs/error_log from SSH. Resolving these errors can be time consuming however here are a few tips.

  • Update all plugins and themes. These will often include PHP fixes.
  • Use a web host which supports the latest version of PHP. Newer PHP tends to include more debug info in the error log which is helpful for pinpointing the problem.
  • Google error messages. Most errors are common to PHP updates and simply need a little reworking.
  • Get help. Consult with a PHP developer. Some bad code requires a lot more knowledge in order to fully resolve.