5

I upgraded from PHP 5.3 to 7.2 and am getting the following error on 2 lines of code:

PHP Deprecated: Function create_function() is deprecated

I searched the forum and tried various forms of code, but none of them worked.

Code 1:

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

Code 2:

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

Thanks for your assistance!

Anurag Srivastava
  • 14,077
  • 4
  • 33
  • 43
Ctichicago
  • 51
  • 1
  • 1
  • 2

1 Answers1

12

create_function was used to create anonymous function. So you can simply change it to function() {}

In example:

instead

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

use

add_action( 'widgets_init', function() {
    register_widget("layerslider_widget");
} );
Harven
  • 608
  • 6
  • 15