If you turn on WP_DEBUG, you may find an error like this:
Deprecated: Function create_function() is deprecated in /wp-content/themes/your-theme/functions/widgets/widget-categories.php on line 106
To fix, change this:
add_action( 'widgets_init', create_function( '', 'return register_widget("Woo_Widget_AdSpace");' ), 1 );
to this:
add_action ( 'widgets_init', 'Woo_Widget_init_AdSpace' ); function Woo_Widget_init_AdSpace() { return register_widget('Woo_Widget_AdSpace'); }
More info here: https://wordpress.org/support/topic/function-create_function-is-deprecated-in-php-7-2-0/
Warning: Please note that if your plugin or theme is by a third-party who has updates, any updates will remove your fixes. Please notify the plugin author or theme author rather than making these changes yourself.
See also:
- Fix PHP error “Methods with same name as their class will not be constructors”
- Fix each() deprecated PHP function in WordPress
- Fix PHP error “called constructor method for WP_Widget… deprecated”
I’ve been enjoying these posts – thank you for sharing them.
In this example another option you could use is an anonymous function with something like
add_action( 'widgets_init', function () {
return register_widget('Woo_Widget_AdSpace');
}, 1 );
Thanks again for posting these.
Thank you, Sal!
Hi Sal and Sarah,
thanks for these solution tipps.
But in my case (current WP version with PHP 8) they only produce another error.
I’ve used:
add_action(‘widgets_init’, function () {
return register_widget(‘SimpleSectionNav’);
}, 1 );
And in result I get that error message (sorry for spamming):
Fatal error: Uncaught ArgumentCountError: Too few arguments to function WP_Widget::__construct(), 0 passed in /var/www/sites/wordpress-2017/wp-includes/class-wp-widget-factory.php on line 61 and at least 2 expected in /var/www/sites/wordpress-2017/wp-includes/class-wp-widget.php:162 Stack trace: #0 /var/www/sites/wordpress-2017/wp-includes/class-wp-widget-factory.php(61): WP_Widget->__construct() #1 /var/www/sites/wordpress-2017/wp-includes/widgets.php(115): WP_Widget_Factory->register(‘SimpleSectionNa…’) #2 /var/www/sites/wordpress-2017/wp-content/plugins/simple-section-navigation/simple_section_nav.php(155): register_widget(‘SimpleSectionNa…’) #3 /var/www/sites/wordpress-2017/wp-includes/class-wp-hook.php(303): {closure}(”) #4 /var/www/sites/wordpress-2017/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(”, Array) #5 /var/www/sites/wordpress-2017/wp-includes/plugin.php(470): WP_Hook->do_action(Array) #6 /var/www/sites/wordpress-2017/wp-includes/widgets.php(1809): do_action(‘widgets_init’) #7 /var/www/sites/wordpress-2017/wp-includes/class-wp-hook.php(303): wp_widgets_init(”) #8 /var/www/sites/wordpress-2017/wp-includes/class-wp-hook.php(327): WP_Hook->apply_filters(NULL, Array) #9 /var/www/sites/wordpress-2017/wp-includes/plugin.php(470): WP_Hook->do_action(Array) #10 /var/www/sites/wordpress-2017/wp-settings.php(578): do_action(‘init’) #11 /var/www/sites/wordpress-2017/wp-config.php(86): require_once(‘/is/htdocs/wp10…’) #12 /var/www/sites/wordpress-2017/wp-load.php(50): require_once(‘/is/htdocs/wp10…’) #13 /var/www/sites/wordpress-2017/wp-blog-header.php(13): require_once(‘/is/htdocs/wp10…’) #14 /var/www/sites/wordpress-2017/index.php(17): require(‘/is/htdocs/wp10…’) #15 {main} thrown in /var/www/sites/wordpress-2017/wp-includes/class-wp-widget.php on line 162
When removing the add_action(…), the WP works.
Do you have any hints for me please?
Thanks and best regards
Jan
I created this post awhile ago, so it could be an outdated solution. I hope you are able to figure it out!
Thank you thank you thank you!!!
You really saved my day, week and month with your helpful examples.
take care,
Thomas.
You are SO welcome! It saved my day to figure out the solution! So happy to help others 🙂
Blessings,
Sarah
Thank you so much for this – I’m not an expert coder but I can follow instruction with an example and this was perfect. My debug log is empty!
Proof that 65 year old grannies can still amaze themselves – with a little help from some generous souls x 🙂
That’s wonderful, Pat! Glad to hear that my work paid off for someone else. I love helping your age bracket 🙂
Some would call me a 65-year-old as well, but I prefer to think of myself as 50 (plus shipping and handling)
You make me smile!
This comment made me smile! Stay blessed! 🙂
Thank you! I have fixed my theme problem.
wonderful!
This line shows Function create_function() is deprecated erron and I don’t know how to fix it –add_filter( ‘pre_transient_update_core’, create_function( ‘$a’, “return null;” ) );
Help, anyone? I don’t know.
I have an issue with a PHP function for a now-discontinued theme, Headway, that puts up an error in PHP 7.4.x, and breaks the site in PHP 8.x.
Deprecated: Function create_function() is deprecated in /var/www/vhosts/ourstrangeplanet.com/public_html/wp-content/themes/headway/library/api/api-admin-meta-box.php on line 29
Can someone help me fix it?
Gene Steinberg
I would like to thank you so much ! My Hosting provider did an update of PHP without me to understand the consequences on my WordPress site.
Because of your post, it took only 10 minutes for me to correct the php of the old WordPress theme I was using. You are a life saver !
Wonderful! Glad to help!
Deprecated: Function create_function() is deprecated in /home/portklm/public_html/wp-includes/plugin.php on line 437
how i can solve this issues