loading...

Fixing Exec-PHP (WordPress Plugin) With PHP 7.2

nabbisen profile image Heddi Nabbisen ・2 min read

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 : )

Posted on by:

nabbisen profile

Heddi Nabbisen

@nabbisen

An ICT designer/developer and a security monk. "With a cool brain and a warm heart", I am challenging unsolved problems in our society. I use OpenBSD/Rust/etc.

Discussion

pic
Editor guide
 

You are a genius, Heddi!

I know that this plugin is deprecated, but other plugins use shortcodes or blocks of php code or so. But with this plugin the php code can be inserted in any way in the text of the post or page.

Thank you very much!!!

 

Hi, Amarse a uno mismo,

You are welcome.
I'm glad if my post helped you.

Yes, it's deprecated because of security issue.
Therefore, take care.

Your comment taught me that each plugin had a reason to be chosen 🙂

 

Many, many thanks for posting this solution to my headache!!
This was a simple fix for me because you shared it.
I am deeply grateful.

 

Hi kspreier,
Thank you for your comments.
I'm happy to know my post helped for the relief of your headache.
"Happiness is real when shared" 😊

 

This was very helpful. Thank you!

 

Glad you found an answer, @mickmel . Welcome to DEV!

 

Hi, Mickey,
I'm happy to know this post helped you 🙂
Thank you for your comment.