Zahed Alfak
Zahed Alfak

Reputation: 11

PHP 7.3 Function create_function() is deprecated

I have used create_function in my theme below.

add_action( 'widgets_init', create_function( '', 'register_widget( "Woocommerce_Header_Cart" );' ) );

But for PHP 7.3.0, the create_function() is deprecated.

Any idea, how to fix my codes above on PHP 7.3.0.

Thanks for your help,

Upvotes: 0

Views: 2092

Answers (2)

mivk
mivk

Reputation: 15009

Replace

add_action( 'widgets_init', create_function( '', 'register_widget( "Woocommerce_Header_Cart" );' ) );

with this, using an anonymous function instead :

add_action( 'widgets_init', function() { return register_widget("Woocommerce_Header_Cart"); } );

Upvotes: 1

Vel
Vel

Reputation: 9342

Try this code

add_action( 'widgets_init', 'custom_widget_func');

funcation custom_widget_func(){
    register_widget( "Woocommerce_Header_Cart" );
}

Upvotes: 2

Related Questions