public static function registerWidget($widgetName){
add_action('widgets_init', create_function('', 'return register_widget("'.$widgetName.'");'));
This is my code and the warning is:
"Deprecated: Function create_function() is deprecated in xxx.php" on 258 line
How can I fix this?
You need to replace it with an anonymous function and the problem with the solution above is that the anonymous function doesn't have $widgetName in its scope.
Try:
public static function registerWidget($widgetName){
add_action('widgets_init', function () use ($widgetName) {
return register_widget($widgetName);
});
}
source: https://www.php.net/manual/en/functions.anonymous.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With