Monday, November 11, 2019

Fixing an old Wordpress plugin to run on PHP 7

You should always update your CMS engine and individual plugins. Unfortunately this is not always possible especially when you have a non actively maintained website and you've used commercial theme or plugins.

In my case, I had to deal with an old Wordpress site which was updated but was still running on an older PHP version 5.6.40. Changing the PHP version  on the server to 7.3, the site broke with a sneaky Call to undefined function mysql_error() on the frontend and [] operator not supported for strings on the admin area. Both errors were caused from a plugin installed by the theme which doesn't support auto updates. More specifically Revslider 4.6.0 which looks like it was used by various themes in the past.
I had no other option but to try and fix them manually since I couldn't downgrade to older PHP version anymore nor invest more resource to change/update the theme and plugins.

First I had to locate the files and lines causing the exceptions and then look suitable solutions. I was lucky and in my case both errors were easy to fix.

The admin error, [] operator not supported for strings in /wp-content/plugins/revslider/inc_php/framework/base_admin.class.php:72, was a syntax error using the short array push syntax when the variable was initialised as a string. Changing the initialisation fixed it.

For the site error, Call to undefined function mysql_error() in /wp-content/plugins/revslider/inc_php/framework/db.class.php:29, I've changed to the msqli alternative of the function which requires the mysqli link argument. Thankfully it's available via the global wpdb class of Wordpress, already utilized on this file.

You can see my changes on the following two diffs.


No comments: