-3

I have the following code on my php website from a theme i made a long time ago but it gives warnings on 7.4 and errors on 8.0

add_action('widgets_init', create_function('', 'return register_widget("Banners125");'));

Any suggestion on how i can fix this code in my wordpress theme for php 8.0?

I would like it to work on php 8.0

  • 2
    what is the error you're getting? – Amjad Dec 03 '22 at 03:49
  • see how create_function(''",..) has to be modify: I just figured out why it crashes on 8.0. Open the file dcwp_jquery_accordion.php in the plugin folder. Go to line 63 and comment out or remove, https://wordpress.org/support/topic/crash-with-php-8-0/ – MZM Dec 03 '22 at 04:05
  • Does this answer your question? [PHP 7.2 Function create\_function() is deprecated](https://stackoverflow.com/questions/48161526/php-7-2-function-create-function-is-deprecated) – Kirk Beard Dec 03 '22 at 05:26

1 Answers1

0

The function create_function was deprecated in 7.2 and removed in 8.0. Your code can be rewritten in several ways, one of which is:

add_action(
    'widgets_init',
    function() {
        return register_widget("Banners125");
    }
);
Chris Haas
  • 53,986
  • 12
  • 141
  • 274
  • If this code has been working for a “long time”, I wouldn’t be surprised if you have old-style constructors, too, which was common with widgets. – Chris Haas Dec 03 '22 at 04:45