I’m having trouble rewriting this line of code that contains create_function() in preparation for updating to PHP 8+.
The line of code to replace is:
add_action('widgets_init', create_function('', 'return register_widget("Ctxt_Menu_Widget");'));
I am trying to replace it with:
$callback = function(){
('', 'return register_widget("Ctxt_Menu_Widget");');
}
add_action('widgets_init', $callback);
But obviously, this isn’t right, the replacement code won’t allow the array withing that function.
Can someone help me rewrite this? Thanks so much!
2
Answers
What turns out to be a good solution was:
to replace:
Source: https://sarah-moyer.com/fix-create_function-deprecated-in-wordpress/
The function should be a real (anonimous) function, sintactically valid in php, so it should be something like that
Then you can call this function
Now wehn called, it is executed as a normal php functions