Are you getting this error notice on your WordPress site after updating WordPress to 4.3? Let me show you how to fix this error. It can be fixed with one line of code in your WordPress config file.
Notice: The called constructor method for WP_Widget is deprecated since version 4.3.0! Use __construct() instead.
I’ve had a few of our customers at churchthemes.com report this error without any idea of how to solve it, so this is a quick guide for WordPress site owners to make the error go away. Because more than 2,000 plugins are affected, I am sure that thousands of WordPress users are seeing this error notice about the deprecated style of constructor.
What Causes It?
New releases of WordPress periodically “deprecate” outdated ways of doing things. Deprecation means theme and plugin authors need to modify their code and release and update of their product to use more modern code. A change in WordPress 4.3 is the reason for the “Notice” you see. Normally, hosts have the display of errors like this turned off (because they are for developers), but sometimes they do not. That’s why you see it.
It’s important for plugin developers to resolve these issues in their products because after deprecation comes removal. At point, the message will no longer be a “Notice” but instead the code will stop working altogether, breaking your website entirely. But let’s let plugin authors worry about that. Let me show you as a user how to get rid of the annoying, “The called constructor method for WP_Widget is deprecated” notice.
Fix Step 1: Check Plugins and Theme
Since the “The called constructor method for WP_Widget is deprecated” is almost certainly caused by a WordPress plugin or, the first step is to deactivate your theme and see if the notice goes away. You can temporarily activate the default Twenty Fifteen theme to check this. If you find the error does go away, contact your theme author and ask them to fix this, then skip to Step 2 to hide the error.
If the issue is not your theme, deactivate all plugins temporarily and check your site to see if the error is gone. If it is gone, the error notice is caused by one or more plugins. To determine which plugin(s) are causing the notice, either check this list or activate them one at at time, looking for the error as you go. If the deprecation error resurfaces after activating a specific plugin then that plugin is causing it. Contact the plugin author and ask them to resolve the error.
You can choose to use a different theme or deactivate the plugin that is causing the WP_Widget constructor deprecation notice. Most likely though you will just want to hide the error, and fast. The notice does not actually indicate something is not working. The theme and plugin will work fine (probably for the next year or more) so it is safe to disable notices while you wait for the plugin maker to fix the issue on their end. Notices should actually be hidden on a live site anyway.
Fix Step 2: Hide the Notice Error Message
Use FTP or your hosting control panel’s file manager to edit wp-config.php. Paste this line into your config file. If it already exists but is set to “true”, change it to “false”. This should prevent all error notices from showing and fix the problem with seeing “Notice: The called constructor method for WP_Widget is deprecated.”
define( 'WP_DEBUG', false );
It’s likely that you do not have a need to log errors (this is typically for developers), but if you do want to, use this code instead. Instead of displaying errors on the screen, errors will be logged in a file at /wp-content/debug.log (it will be created automatically upon the first error or notice).
define( 'WP_DEBUG', true ); define( 'WP_DEBUG_LOG', true ); define( 'WP_DEBUG_DISPLAY', false ); @ini_set( 'display_errors', 0 );
You should be all set now! That scary looking but relatively harmless notice is hidden and the plugin authors can deal with it in their next update.
- Deprecating PHP4 style constructors in WordPress 4.3 – Send this to your plugin author
- Debugging in WordPress – More on displaying and logging errors in WordPress