-1

I got an error while activating a plugin in my WordPress website

Fatal error: Uncaught Error: Call to undefined function create_function() in /home4/seosexey/gifting.icowebtech.com/wp-content/plugins/woocommerce-product-options/includes/order-option-group.php:33 Stack trace: #0 /home4/seosexey/gifting.icowebtech.com/wp-content/plugins/woocommerce-product-options/includes/order-option-group.php(364): Woocommerce_Product_Options_Order_Option_Group->__construct() #1 /home4/seosexey/gifting.icowebtech.com/wp-content/plugins/woocommerce-product-options/woocommerce-product-options.php(22): require_once('/home4/seosexey...') #2 /home4/seosexey/gifting.icowebtech.com/wp-admin/includes/plugin.php(2314): include_once('/home4/seosexey...') #3 /home4/seosexey/gifting.icowebtech.com/wp-admin/plugins.php(192): plugin_sandbox_scrape('woocommerce-pro...') #4 {main} thrown in /home4/seosexey/gifting.icowebtech.com/wp-content/plugins/woocommerce-product-options/includes/order-option-group.php on line 33

I guess I need to rewrite a code

$func = create_function( '',
                    'global $woocommerce_product_options_order_option_group; $woocommerce_product_options_order_option_group->print_order_options( "' . $location . '"); return;' );
            };
            add_action( $location, $func );

Can someone help me?

Austin Poulson
  • 685
  • 7
  • 22
  • _"I guess I need to rewrite a code"_ - if this is not your _own_ plugin, that you yourself are maintaining - then you should rather update the plugin to a more current version, than manipulating plugin code yourself. – CBroe Mar 15 '23 at 11:53
  • Could you add more context please? Like CBroe said, editing plugin content is a last last LAST resort. You don't want to have to maintain the plugin yourself in the future. – Austin Poulson Mar 15 '23 at 18:14

1 Answers1

0

create_function() has been removed from php 8. Cybercriminals found it far too easy to hack.

It's not necessary for the code you showed us. You can try using an anonymous function in your call to add_action(), like this. (Not debugged.)

add_action( $location, function () use ( $location ) {
    global $woocommerce_product_options_order_option_group;
    $woocommerce_product_options_order_option_group->print_order_options
       ( $location );
    return;
});

The use ( $location ) clause makes that variable from outside the function accessible inside the function.

O. Jones
  • 103,626
  • 17
  • 118
  • 172