This post is about
This post is about fixing errors of "Exec-PHP" plugin running in the latest WordPress with PHP 7.2.
What happened
I upgraded PHP version from 5.6 to 7.2 in the server hosting WordPress sites for my customer the other day.
One of the sites used Exec-PHP which enabled us to execute PHP code directly in posts or pages.
Unfortunately, it was out of date.
The last update was 9 years ago and it was based on PHP under 7.
The plugin is officially deprecated for security issue and has vanished from WordPress Plugins pages since the end of the last year.
Anyway, my customer had used it and the service was still on.
I needed to find the way to carry out both server migration and service continuation.
Why it errors
It's because of one of the PHP 7.0's backward incompatible changes, that:
"New objects cannot be assigned by reference".
This is forbidden:
class C {}
$c =& new C;
How to fix it
Use alternative plugin
It would have been an almost ideal way if something had been found.
Modify plugin code directly
Remove '&' from '=&' like this:
- $c =& new C;
+ $c = new C;
All of the targets are in wordpress/wp-content/plugins/exec-php
:
-
exec-php.php
- line 22
-
include/admin.php
- line 53, 56, 57, 63, 64, 79
-
includes/ajax.php
- line 64
-
includes/cache.php
- line 22, 39
-
includes/manager.php
- line 36, 37, 38, 39
For example, modify exec-php.php
line 22 like this:
- $GLOBALS['g_execphp_manager'] =& new ExecPhp_Manager();
+ $GLOBALS['g_execphp_manager'] = new ExecPhp_Manager();
After all modification and testing
The WordPress site worked well with modified Exec-PHP as it had.
My customer is satisfied with the new server so far : )